Skip to content
On this page

System Variables

CAD system variables are settings used in computer-aided design (CAD) software. CAD system variables can control the behavior, appearance, and functionality of CAD software. They can be global variables that control the behavior of the entire CAD system or local variables that affect specific CAD objects or operations.

CAD system variables can control various parameters, such as the units, precision, and colors of graphic display, default properties of drawing objects, layout of toolbars and menus, and the behavior of various commands. By modifying the values of system variables, users can customize the functionality and appearance of CAD software according to their needs.

Each CAD software has its own set of system variables, and new system variables can be added as needed. Users can modify the values of system variables by setting options in CAD software or using the corresponding commands.

MxCAD also provides methods for getting and setting CAD variables, based on the different variable types. There are four different methods for setting:

To get a floating-point variable: getSysVarDouble

To get a long integer variable: getSysVarLong

To get a point variable: getSysVarPoint

To get a string variable: getSysVarString

To set a variable, you just need to replace "get" with "set" in the method name and provide the variable name and the corresponding value of the appropriate type.

Let's illustrate the use of system variables with an example:

Sample project: https://demo.mxdraw3d.com:3000/mxcad/

In the bottom-right corner of the project, there are buttons that control various snap settings. These buttons are all long integer system variables:

Alt text

ts
export enum SysVarLongSketchSettings {
  /** Grid Mode */
  GRIDMODE = "Grid",
  /** Ortho Mode */
  ORTHOMODE = "Ortho",
  /** Polar Mode */
  AUTOSNAP = "Polar",
  /** Object Snap Mode */
  OSMODE = "Object Snap",
  /** Object Tracking Mode */
  DYNTRACE = "Object Tracking",
  /** Dynamic Input Mode */
  DYNINPUT = "Dynamic Input",
  /** Lineweight Display Mode */
  LWDISPLAY = "Lineweight Display"
}

Except for the OSMODE object snap variable, the values for the other variables are 0 to indicate they are turned off, and 1 to indicate they are turned on.

You can set these variables using the following code:

ts
import { MxCpp } from "mxcad"

const mxcad = MxCpp.getCurrentMxCAD()
// Turn on grid mode
mxcad.setSysVarLong("GRIDMODE", 1)
// Turn on ortho mode
mxcad.setSysVarLong("ORTHOMODE", 1)
// Turn off lineweight display
mxcad.setSysVarLong("LWDISPLAY", 0)

For dynamic snap, there are multiple snap options, and the value you get is a result of bitwise operations on these options to determine which snaps are enabled or disabled. Therefore, you need to set dynamic snap settings by adjusting various snap switches. Here is an example for dynamic object snap settings:

ts
import { MxCpp } from "mxcad"

const mxcad = MxCpp.getCurrentMxCAD()
const osModeVal = mxcad.setSysVarLong("OSMODE")

export enum SysVarLongSketchSettingsOsMode {
  /** Endpoint Snap */
  End = 1,
  /** Midpoint Snap */
  Mid = 2,
  /** Center Snap */
  Cen = 4,
  /** Node Snap */
  Node = 8,
  /** Quadrant Snap */
  Quad = 16,
  /** Intersection Snap */
  Int = 32,
  /** Insertion Snap */
  Ins = 64,
  /** Perpendicular Snap */
  Perp = 128,
  /** Tangent Snap */
  Tan = 256,
  /** Nearest Snap */
  Near = 512,
  /** Apparent Intersection Snap */
  App = 2048,
  /** Extension Snap */
  Ext = 4096,
  /** Parallel Snap */
  Par = 8192,
  /** Turn Off Snap */
  Off = 16384,
}

// Check if Object Snap is turned off (0 or 1)
const osModeOff = osModeVal & SysVarLongSketchSettingsOsMode.Off
// Check if Parallel Snap is turned on (0 or 8192)
const osModePar = osModeVal & SysVarLongSketchSettingsOsMode.Par

// Set whether Parallel Snap is turned on
const isOpenOsModePar = true
// Set the value accordingly
mxcad.setSysVarLong("OSMODE", 
    isOpenOsModePar 
    ?
    (osModeVal | SysVarLongSketchSettingsOsMode.Par) 
    :
    (osModeVal & ~SysVarLongSketchSettingsOsMode.Par)
)

// You can use similar code for other snap settings as well.
// ...

With the above code, you can customize various CAD system variables based on specific rules. CAD software offers a wide range of variables, and you can adjust them using the provided methods in MxCAD.