Skip to content
On this page

System variables

CAD system variables are data storage units used to store operating environment Settings, graphic information and command Settings. They can control certain functions of CAD and the design environment, the way commands work. CAD system variables typically have a length of 6 to 10 characters and can be integers, real numbers, dot switches, or text strings. Some system variables have read-only properties, users can only view but not modify; System variables that do not have read-only properties can be viewed and set by calling commands. The following are some of the most common system variables we use in CAD drawings.

mxcad provides the method of obtaining and setting corresponding CAD variables according to the above definition of CAD system variables. According to different variable types, we have four different ways to set:

  1. Get the floating point variable getSysVarDouble,

  2. Get the long integer variable getSysVarLong

  3. Get the point variable getSysVarPoint

  4. Get the string variable getSysVarString

Tip

Setting is to change the method 'get' to 'set', passing the variable name and the corresponding type value.

orthogonal

We can control whether the orthogonal plotting mode is enabled by setting the long integer variable 'ORTHOMODE'. When the orthogonal drawing mode is turned on, you can limit the cursor to move only on the horizontal or vertical axis to achieve the purpose of drawing in the right Angle or orthogonal mode. But when the user enters coordinate values from the command line or uses entity capture, the orthogonal drawing is ignored.

variable nameVariable valuedescription
ORTHOMODE1Opens the orthogonal plotting mode
ORTHOMODE0Turns off the orthogonal plotting mode
ts
import { MxCpp } from "mxcad"

const mxcad = MxCpp.getCurrentMxCAD()
// Open orthogonal drawing mode
mxcad.setSysVarLong("ORTHOMODE", 1)

Object capture

In the process of CAD drawing, we often encounter points that need some special positions, such as endpoints, midpoints, intersection points, etc. Capturing these points by eye alone is not accurate, so mxcad provides some physical capture methods to improve accuracy.

We can set different capture modes by setting the dynamic capture value of the long integer variable 'OSMODE', 1 where the dynamic capture value we get is the total value of the operation based on whether these switches are turned on or not. The following uses setting the parallel capture mode as an example (other capture modes can be directly referred to the following example) :

methodoperation valuedescription
nearest point capture512Captures the point closest to the specified point. These objects include lines, circles, arcs, compound lines, ellipses, and splines that are the closest points to the cursor.
endpoint capture1Captures the closest endpoint of the arc, straight line, compound line, ray, and plane equidistant cursor
midpoint capture2Capture the midpoint of arc, straight line, compound line, solid filling line, spline curve and other entities
center capture4Capture the center of an arc, circle, ellipse, or ellipse.
foot capture128to capture the point of the arc, circle, structure line, ellipse, ellipse arc, straight line, compound line, ray, solid or spline curve orthogonal, can also capture the object's appearance extension of the point of intersection.
Tangent capture256Captures a point on a circle or arc connected to a previous point. The two points form a line that is tangent to the circle or arc.
quadrant capture16Captures the nearest quadrant of an arc, circle, or ellipse.
insertion point capture64captures the insertion point of a block, text, property, or property definition.
intersection capture32Capture the intersection points between objects such as arc, circle, ellipse, ellipse arc, straight line, compound line, ray, spline curve or construction line.
Extended capture4096The extended capture mode is used to capture the extension of a line or arc.
Parallel capture8192Parallel capture mode is used to draw a line parallel to another object.
Intersections capture2048captures the intersections of two objects such as arcs, circles, ellipses, lines, compound lines, rays, splines, or reference lines that do not intersect in three-dimensional space but appear to intersect in a graphical display.
Disable the physical capture16384disables the physical capture.
ts
import { MxCpp, McGePoint3d } from "mxcad"
const mxcad = mxcad.MxCpp.getCurrentMxCAD()
const osModeVal = mxcad.setSysVarLong("OSMODE")
export enum SysVarLongSketchSettingsOsMode {
    /** Endpoint capture */
    End = 1,
    /** Midpoint capture */
    Mid = 2,
    /** Center point capture */
    Cen = 4,
    /** Node capture */
    Node = 8,
    /** Quadrant point capture */
    Quad = 16,
    /** Intersection capture */
    Int = 32,
    /** Insert point capture */
    Ins = 64,
    /** Foot point capture */
    Perp = 128,
    /** Cut point capture */
    Tan = 256,
    /** Nearest point capture */
    Near = 512,
    /** Appearance intersection capture */
    App = 2048,
    /** Extension point capture */
    Ext = 4096,
    /** Parallel point capture */
    Par = 8192,
    /** Capture off */
    Off = 16384,
}
// Close capture 0 or 1
const osModeOff = osModeVal & SysVarLongSketchSettingsOsMode.Off
// Parallel points capture 0 or 1
const osModePar = osModeVal & SysVarLongSketchSettingsOsMode.Par

// Whether to enable parallel point capture
const isOpenOsModePar = true
// Settings
mxcad.setSysVarLong("OSMODE", 
    isOpenOsModePar 
    ?
    (osModeVal | SysVarLongSketchSettingsOsMode.Par) 
    :
    (osModeVal & ~SysVarLongSketchSettingsOsMode.Par)
)

Dynamic input

We can control whether dynamic input mode is enabled by setting the long integer variable 'DYNINPUT'. When dynamic input mode is enabled, users can view and edit the length, Angle, and radius of the current operation in real time.

variable nameVariable valuedescription
DYNINPUT1Enables the dynamic input mode
DYNINPUT0Disable the dynamic input mode
ts
import { MxCpp } from "mxcad"

const mxcad = MxCpp.getCurrentMxCAD()
// Enable dynamic input mode
mxcad.setSysVarLong("DYNINPUT", 1)

Polar axis and object tracking

Polar axis tracking allows users to trace points along specific angular increments, helping to create accurate lines, angles, and other graphical objects. For example, if the user sets an Angle increment of 30 degrees, when using polar axis tracking, a dotted line will appear at the cursor every 30 degrees to help the user track and position to a specific Angle.

We can start the pole axis by setting the long integer variable AUTOSNAP and the long integer variable DYNTRACE to start the object trace. The increment of the polar axis can be done by setting the floating-point variable POLARANG, to which the Angle is converted to radians when assigned.

ts
import { MxCpp } from "mxcad"

const mxcad = MxCpp.getCurrentMxCAD()

// Enable object tracking
mxcad.setSysVarLong("DYNTRACE",1)

// Open the pole axis
const autoSnapVal = mxcad.getSysVarLong("AUTOSNAP")
// Specify the pole axis Angle
mxcad.setSysVarDouble("POLARANG", 30/180 *Math.PI)
// Whether to open the pole axis
const isOpenOsModePar = true
// Settings
mxcad.setSysVarLong("AUTOSNAP", isOpenOsModePar ? (autoSnapVal | 8) :(autoSnapVal & ~8) )

Grid

A raster pattern in CAD can be seen as a series of regular points set in two-dimensional space that form a matrix covering the entire plane of the user's coordinate system. With raster mode turned on, users can accurately position and draw objects through the raster points, similar to placing a graph paper under a drawing. The raster mode also helps to show the distance and Angle between objects, serving as a frame of reference for positioning and display.

We can control whether the grid mode is enabled by setting the long integer variable GRIDMODE.

variable nameVariable valuedescription
GRIDMODE1Enables the grid mode
GRIDMODE0Turns off the grid mode
ts
import { MxCpp } from "mxcad"

const mxcad = MxCpp.getCurrentMxCAD()
// Turn on grid mode
mxcad.setSysVarLong("GRIDMODE",1)