snapMode

snapMode const StructDef

 

snapMode.active

Get/Set whether snap is active as 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 to provide access to all Snap settings and Snap results. (Prior to 3ds Max 7, these properties were available in the 3rd party Avguard DLX extension)

The following properties are available in 3ds Max 7 and higher:

snapMode.snapPreviewRadius SystemGlobal:snapPreviewRadius 30

Get/Set the snap preview radius.

 

snapMode.snapRadius SystemGlobal:snapRadius 20

Get/Set the snap radius.

 

snapMode.displayRubberBand

Get/Set whether to display rubber band as a Boolean value.

 

snapMode.hilite

Get/Set the snap marker color as a color value.

 

snapMode.markSize

Get/Set the snap marker size as an integer

 

snapMode.toFrozen

Get/Set whether to snap to frozen objects as Boolean value.

 

snapMode.axisConstraint

Get/Set whether the snap should use axis constraints as Boolean value.

 

snapMode.display

Get/Set whether the snap marker is displayed as a Boolean value.

 

snapMode.strength

Get/Set the snap strength as an integer

The following snapMode variables/methods return undefined if snap not active.

snapMode.hit

Returns true if currently snapped to something - read only.

 

snapMode.node

Returns the node currently being snapped - read only.

 

snapMode.flags

Returns the snap system flags as an integer - read only.

 

snapMode.hitPoint

Returns the last snap point as point3 coordinate in local coordinates of node snapped to - read only.

 

snapMode.worldHitpoint

Returns the last snap point as point3 world coordinate - read only.

 

snapMode.screenHitPoint

Returns the last snap point as point3 screen coordinate - read only.

 

snapMode.OKForRelativeSnap

Returns true if at least one snap point has been recorded - read only.

 

snapMode.refPoint

Returns the last snap point as point3 world coordinate - read only.

 

snapMode.topRefPoint

Returns the first snap point as point3 world coordinate - read only.

 

snapMode.numOSnaps

Returns the number of OSnaps as an integer - read only. Currently there are 5 sets of OSnaps.

 

snapMode.getOSnapName <int osnap_index>

Returns the name of the indexed OSnap as string. Currently, the results are:

1 - "NURBS"

2 - "Standard"

3 - "Standard"

4 - "Standard"

5 - "Standard"

NOTE:

The Standard Snaps are exposed in 4 groups with indices 2 to 5. See 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>.

Possible osnap_index values are:

1 - NURBS

2 - Standard - Grid Points, Grid Lines

3 - Standard - Pivot, Bounding Box

4 - Standard - Perpendicular, Tangent

5 - Standard - 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.

 

snapMode.getOSnapItemToolTip <int osnap_index> <int osnap_item_index>

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

 

snapMode.getOSnapItemActive <int osnap_index> <int osnap_item_index>

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

 

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

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

Exploring the Snap Options

Example:

--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: "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

2: name: "Standard"

1: name: "Grid Points"; tooltip: ""; state: true

2: name: "Grid Lines"; tooltip: ""; state: false

3: name: "Standard"

1: name: "Pivot"; tooltip: ""; state: false

2: name: "Bounding Box"; tooltip: ""; state: false

4: name: "Standard"

1: name: "Perpendicular"; tooltip: ""; state: false

2: name: "Tangent"; tooltip: ""; state: false

5: name: "Standard"

1: name: "Vertex"; tooltip: ""; state: true

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