MAXScript Tools and Interaction with 3ds Max > Interacting with the 3ds Max User Interface > Viewports >

# snapMode Struct

The snapMode struct provides system globals and functions to access and control the snapping options through MAXScript.

System Globals:

    snapMode.active

A 3ds Max System Global which lets you get and set whether Snap is active.

A Boolean value.

    snapMode.type

Get/Set the current snap type as a name. Possible names are #2D , #2_5D , #3D .

The snapMode structure has been extended in 3ds Max 7 to provide access to all Snap settings and Snap results. Prior to 3ds Max 7, these properties were available in the third-party Avguard Extensions.

    snapMode.snapPreviewRadius

A System Global which lets you get and set the Snap Preview Radius value.

Default value is 30.

Available in 3ds Max 7 and higher.

    snapMode.snapRadius

A System Global which lets you get and set the Snap Radius value.

Default value is 20.

Available in 3ds Max 7 and higher.

    snapMode.hilite

A System Global which lets you get and set the color value of the Snap Marker.

Available in 3ds Max 7 and higher.

    snapMode.markSize

A System Global which lets you get and set the Snap Marker Size.

An integer value.

Available in 3ds Max 7 and higher.

    snapMode.toFrozen

A System Global which lets you get and set whether to snap to frozen objects.

A Boolean value.

Available in 3ds Max 7 and higher.

    snapMode.axisConstraint

A System Global which lets you get and set whether the snap should use axis constraints as Boolean value.

Corresponds to the checkbox in the "Grid and Snap Settings" dialog, Options tab.

Available in 3ds Max 7 and higher.

    snapMode.displayRubberBand

A System Global which lets you get and set whether to display rubber band as a Boolean value.

Corresponds to the checkbox in the "Grid and Snap Settings" dialog, Options tab.

Available in 3ds Max 7 and higher.

    snapMode.useAxisCenterAsStartSnapPoint

A System Global which lets you get and set the state of the "Use Axis Center As Start Snap Point" option as Boolean value.

Corresponds to the checkbox in the "Grid and Snap Settings" dialog, Options tab.

Available in 3ds Max 7 and higher up to 3ds Max 2010.

Deprecated in 3ds Max 2011.

Attempting to access this property will result in:

-- Runtime error: Cannot set this snap option. It has been deprecated as of 3ds Max 2011.

    snapMode.display

A System Global which lets you get and set whether the Snap Marker is displayed.

A Boolean value.

Available in 3ds Max 7 and higher.

    snapMode.strength

A System Global which lets you get and set the Snap Strength as an integer value.

Available in 3ds Max 7 and higher.

    snapMode.hit

A System Global which contains true if the Marker is currently snapped to something, false if not snapped.

Contains undefined if Snaps are not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.node

A System Global which contains the node currently being snapped to.

Contains undefined if not snapped to a node or if Snaps are not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.flags

A System Global which contains the Snap System Flags as an integer.

Contains undefined if Snaps not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.hitPoint

A System Global which contains the last Snap Point as Point3 coordinate in local coordinates of the node snapped to.

Contains undefined if Snaps are not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.worldHitpoint

A System Global which contains the last Snap Point as Point3 world coordinate.

Contains undefined if Snaps are not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.screenHitPoint

A System Global which contains the last Snap Point as a Point3 screen coordinate.

Contains undefined if Snaps are not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.OKForRelativeSnap

A System Global which contains true if at least one Snap Point has been recorded.

Contains undefined if Snaps are not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.refPoint

A System Global which contains the last Snap Point as point3 world coordinate.

Contains undefined if Snaps are not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.topRefPoint

A System Global which contains the first snap point as point3 world coordinate.

Contains undefined if Snaps are not active.

Read only.

Available in 3ds Max 7 and higher.

    snapMode.numOSnaps

A System Global which contains the number of OSnaps as an integer.

Read only.

Currently there are 6 sets of OSnaps - see below of details.

Available in 3ds Max 7 and higher.

Methods:

    snapMode.getOSnapName <int osnap_index>

Returns the name of the indexed OSnap as string.

Currently, the results are:

1 - "Body" - Available in 3ds Max 2011 and higher.

2 - "NURBS"

3 - "Standard"

4 - "Standard"

5 - "Standard"

6 - "Standard"

All others available in 3ds Max 7 and higher.

Note

The Standard Snaps are exposed in 4 groups with indices 3 to 6.

See the table below for details on which snap items are in which groups.

Also see example output further on this page.

    snapMode.getOSnapNumItems <int osnap_index>

Returns the number of OSnap items in the indexed OSnap as <integer>.

Available in 3ds Max 7 and higher.

Possible osnap_index values are:

Index | Type | Count | Snap Names
1 | Body | 5 | Vertex, End Edge, Edge, Edge Midpoint, Face
2 | NURBS | 10 | CV, Point, Curve Center, Curve Normal, Curve Tangent, Curve Edge, Curve End, Surf Center, Surf Normal, Surf Edge
3 | Standard | 2 | Grid Points, Grid Lines
4 | Standard | 2 | Pivot, Bounding Box
5 | Standard | 2 | Perpendicular, Tangent
6 | Standard | 6 | Vertex, Endpoint, Edge/Segment, Midpoint, Face, Center Face

    snapMode.getOSnapItemName <int osnap_index> <int osnap_item_index>

Returns the name of the indexed OSnap item in the indexed OSnap as string.

See table above for currently implemented names.

Available in 3ds Max 7 and higher.

    snapMode.getOSnapItemToolTip <int osnap_index> <int osnap_item_index>

Returns the tooltip of the indexed OSnap item in the indexed OSnap as string.

Available in 3ds Max 7 and higher.

    snapMode.getOSnapItemActive <int osnap_index> <int osnap_item_index>

Returns true if the indexed OSnap item in the indexed OSnap is active, false otherwise.

Available in 3ds Max 7 and higher.

    snapMode.setOSnapItemActive <int osnap_index> <int osnap_item_index> <boolean>

Sets whether the indexed OSnap item in the indexed OSnap is active.

Available in 3ds Max 7 and higher.

## Exploring the Snap Options

SCRIPT:
     --The following example prints information about the state of --all Snap options to the Listener:
    for i = 1 to snapmode.numOSnaps do
    (
    format "%: name: \"%\"\n" i (snapmode.getOSnapName i)
    for j = 1 to (snapmode.getOSnapNumItems i) do
    format " %: name: \"%\"; tooltip: \"%\"; state: %\n" j \
    (snapmode.getOSnapItemName i j) \
    (snapmode.getOSnapItemToolTip i j) \
    (snapmode.getOSnapItemActive i j)
    )
OUTPUT:
    1: name: "Body Snaps"
    1: name: "Vertex"; tooltip: ""; state: true
    2: name: "End Edge"; tooltip: ""; state: false
    3: name: "Edge"; tooltip: ""; state: false
    4: name: "Edge Midpoint"; tooltip: ""; state: false
    5: name: "Face"; tooltip: ""; state: false
    2: name: "NURBS"
    1: name: "CV"; tooltip: ""; state: false
    2: name: "Point"; tooltip: ""; state: false
    3: name: "Curve Center"; tooltip: ""; state: false
    4: name: "Curve Normal"; tooltip: ""; state: false
    5: name: "Curve Tangent"; tooltip: ""; state: false
    6: name: "Curve Edge"; tooltip: ""; state: false
    7: name: "Curve End"; tooltip: ""; state: false
    8: name: "Surf Center"; tooltip: ""; state: false
    9: name: "Surf Normal"; tooltip: ""; state: false
    10: name: "Surf Edge"; tooltip: ""; state: false
    3: name: "Standard"
    1: name: "Grid Points"; tooltip: ""; state: true
    2: name: "Grid Lines"; tooltip: ""; state: false
    4: name: "Standard"
    1: name: "Pivot"; tooltip: ""; state: false
    2: name: "Bounding Box"; tooltip: ""; state: false
    5: name: "Standard"
    1: name: "Perpendicular"; tooltip: ""; state: false
    2: name: "Tangent"; tooltip: ""; state: false
    6: name: "Standard"
    1: name: "Vertex"; tooltip: ""; state: false
    2: name: "Endpoint"; tooltip: ""; state: false
    3: name: "Edge/Segment"; tooltip: ""; state: false
    4: name: "Midpoint"; tooltip: ""; state: false
    5: name: "Face"; tooltip: ""; state: false
    6: name: "Center Face"; tooltip: ""; state: false
    OK

## Changing the Snap Options

The following example shows how to access and change since snap options:

EXAMPLE
     --The Snaps dialog must not necessarily be open, --but in this example we will toggle it on to be able to see --what is happening to the checkboxes:
    max drawingaids --toggle on the Snaps dialog
    OK --if it was closed, it should be open now
    snapmode.getOSnapItemActive 5 1 --print the state of the Object>Vertex snap
    false --it is off --now toggle the vertex snap:
    snapmode.setOSnapItemActive 5 1 (not(snapmode.getOSnapItemActive 5 1))
    OK
    max drawingaids; max drawingaids --toggle the Snaps dialog twice to refresh
    OK
    OK --the Vertex checkbox should be checked now
    snapmode.getOSnapItemActive 5 1 --get the current Vertex snap state
    true --it is now on

## Exploring the Snap Marker Settings

The following example prints information about the snap marker's settings:

EXAMPLE
    format "type: %; hilite: %; marksize: %; toFrozen: %\n" snapmode.type snapmode.hilite \
    snapmode.markSize snapmode.toFrozen
    format "axisConstraint: %; active: %; strength: %\n" snapmode.axisConstraint snapmode.active \
    snapmode.strength

## Exploring the Snap Results

The following example shows how to access and print dynamically the results of the snap operations in the viewports:

EXAMPLE
     --This function can be registered as a RedrawViews Callback --It will print information about the current snap state to the Listener
    fn snapinfo =
    (
    local snapinfo
    if snapmode.active do
    (
    struct snapinfo (hit, flags, hitpoint, worldhitpoint, screenHitPoint, OKForRelativeSnap, topRefPoint, refPoint, node)
    local out = snapinfo snapmode.hit (bit.intAsHex snapmode.flags) snapmode.hitPoint \
    snapmode.worldHitpoint snapmode.screenHitPoint snapmode.OKForRelativeSnap \
    snapmode.refPoint snapmode.topRefPoint snapmode.node
    print out
    )
    ok
    )
    unregisterRedrawViewsCallback snapinfo
    registerRedrawViewsCallback snapinfo

#### See Also

- 3ds Max System Globals