c4d.modules.snap

Follow me to the Inheritance diagramm.

New in version R14.034.

This is the snap module to access the snap settings, quantizing options, workplane etc.

(You can find the following script in the examples folder)

"""
Snapping Module Example

Example:
c4d.modules.snap

This example shows how to use the snap module functions.
"""

import c4d
from c4d.modules import snap


def main():
    
    # Check snap state
    res = snap.IsSnapEnabled(doc)
    if not res:
        # Enable snap if not activated
        snap.EnableSnap(True, doc)
        print "Snap Enabled:", snap.IsSnapEnabled(doc)
    
    # Get snap settings
    bc = snap.GetSnapSettings(doc)

    # Change snap settings
    
    # Set 3D snapping mode
    bc[c4d.SNAP_SETTINGS_MODE] = c4d.SNAP_SETTINGS_MODE_3D
    snap.SetSnapSettings(doc, bc)
    
    # Check quantizing state
    if not bc[c4d.QUANTIZE_ENABLED]:
        # Enable quantizing if not activated
        c4d.CallCommand(c4d.QUANTIZE_ENABLED)
        c4d.EventAdd()
        print "Quantize Enabled:", snap.IsQuantizeEnabled(doc)
    
    # Set quantize scale step
    snap.SetQuantizeStep(doc, None, c4d.QUANTIZE_SCALE, 0.5)
    print "Quantize Scale Step:",  snap.GetQuantizeStep(doc, None, c4d.QUANTIZE_SCALE)

    # Print workplane object and matrix
    print "Workplane Object:", snap.GetWorkplaneObject(doc)
    print "Workplane Matrix:", snap.GetWorkplaneMatrix(doc, None)
    
    # Check if workplane is locked
    if not snap.IsWorkplaneLock(doc):
        # Lock workplane
        snap.SetWorkplaneLock(doc.GetActiveBaseDraw(), True)
        print "Workplane Locked:", snap.IsWorkplaneLock(doc)


if __name__=='__main__':
    main()

Functions

c4d.modules.snap.IsSnapEnabled(doc[, snapmode])

Check if snap is enabled for the document doc or for a specific snapmode.

Parameters:
  • doc (BaseDocument) – The document to test for.
  • snapmode (int) –

    Optionnally set a snap mode instead of checking snap for the document. One of the following:

    SNAPMODE_GUIDE Snap to guide objects.
    SNAPMODE_INTERSECTION Snap to the intersections of objects and guides.
    SNAPMODE_POINT Snap to a vertex on a mesh.
    SNAPMODE_SPLINE Snap to any point along a spline.
    SNAPMODE_DYNAMICGUIDE Snap using dynamic or “inferred” guides.
    SNAPMODE_SPLINEMID Snap to the middle of a spline segment.
    SNAPMODE_EDGE Snap to any point along an edge.
    SNAPMODE_EDGEMID Snap to the middle of an edge.
    SNAPMODE_POLYGON Snap to the surface of a polygon.
    SNAPMODE_POLYGONCENTER Snap to the center of individual polygons.
    SNAPMODE_WORKPLANE Snap to the surface of the workplane.
    SNAPMODE_AXIS Snap to the axis of an object.
    SNAPMODE_ORTHO Snap perpendicular to guides edges and splines.
    SNAPMODE_GRIDPOINT Snap to the intersection points of the grid on the workplane.
    SNAPMODE_GRIDLINE Snap to the grid lines on the workplane.
    SNAPMODE_MIDPOINT Snap for mid points. Allow subsnap for each parent mode that have it.
    SNAPMODE_GUIDEMID Snap the middle point in between of static guides interesections.
Return type:

bool

Returns:

True if snap is enabled, otherwise False.

c4d.modules.snap.EnableSnap(state, doc[, snapmode])

Set the snap enabled status for the document doc or a particular snapmode.

Parameters:
  • state (bool) – The state to set: True to enable, False to disable.
  • doc (BaseDocument) – The document to set the snap mode state for.
  • snapmode (int) –

    Optionnally set a snap mode instead of enabling snap for the document. One of the following:

    SNAPMODE_GUIDE Snap to guide objects.
    SNAPMODE_INTERSECTION Snap to the intersections of objects and guides.
    SNAPMODE_POINT Snap to a vertex on a mesh.
    SNAPMODE_SPLINE Snap to any point along a spline.
    SNAPMODE_DYNAMICGUIDE Snap using dynamic or “inferred” guides.
    SNAPMODE_SPLINEMID Snap to the middle of a spline segment.
    SNAPMODE_EDGE Snap to any point along an edge.
    SNAPMODE_EDGEMID Snap to the middle of an edge.
    SNAPMODE_POLYGON Snap to the surface of a polygon.
    SNAPMODE_POLYGONCENTER Snap to the center of individual polygons.
    SNAPMODE_WORKPLANE Snap to the surface of the workplane.
    SNAPMODE_AXIS Snap to the axis of an object.
    SNAPMODE_ORTHO Snap perpendicular to guides edges and splines.
    SNAPMODE_GRIDPOINT Snap to the intersection points of the grid on the workplane.
    SNAPMODE_GRIDLINE Snap to the grid lines on the workplane.
    SNAPMODE_MIDPOINT Snap for mid points. Allow subsnap for each parent mode that have it.
    SNAPMODE_GUIDEMID Snap the middle point in between of static guides interesections.
c4d.modules.snap.GetSnapSettings(doc[, snapmode])

Get the snap settings for the document doc or a specific snapmode.

Parameters:
  • doc (BaseDocument) – The document related snap settings to retrieve.
  • snapmode (int) –

    Specify a snap mode to get or modify its specific settings instead of the global settings (pass NOTOK). One of the following:

    SNAPMODE_GUIDE Snap to guide objects.
    SNAPMODE_INTERSECTION Snap to the intersections of objects and guides.
    SNAPMODE_POINT Snap to a vertex on a mesh.
    SNAPMODE_SPLINE Snap to any point along a spline.
    SNAPMODE_DYNAMICGUIDE Snap using dynamic or “inferred” guides.
    SNAPMODE_SPLINEMID Snap to the middle of a spline segment.
    SNAPMODE_EDGE Snap to any point along an edge.
    SNAPMODE_EDGEMID Snap to the middle of an edge.
    SNAPMODE_POLYGON Snap to the surface of a polygon.
    SNAPMODE_POLYGONCENTER Snap to the center of individual polygons.
    SNAPMODE_WORKPLANE Snap to the surface of the workplane.
    SNAPMODE_AXIS Snap to the axis of an object.
    SNAPMODE_ORTHO Snap perpendicular to guides edges and splines.
    SNAPMODE_GRIDPOINT Snap to the intersection points of the grid on the workplane.
    SNAPMODE_GRIDLINE Snap to the grid lines on the workplane.
    SNAPMODE_MIDPOINT Snap for mid points. Allow subsnap for each parent mode that have it.
    SNAPMODE_GUIDEMID Snap the middle point in between of static guides interesections.
Return type:

BaseContainer

Returns:

A copy of the settings in a BaseContainer form. See dmodeling.h for more information on the returned container.

c4d.modules.snap.SetSnapSettings(doc, bc[, snapmode])

Set the snap settings for the document doc or a specific snapmode.

Parameters:
  • doc (BaseDocument) – The document to set the snap settings for.
  • bc (BaseContainer) – The BaseContainer with the settings for the document doc and/or snapmode. See dmodeling.h for more information on the container.
  • snapmode (int) –

    Optionally specify the snap mode to set the settings for instead of the global settings. One of the following:

    SNAPMODE_GUIDE Snap to guide objects.
    SNAPMODE_INTERSECTION Snap to the intersections of objects and guides.
    SNAPMODE_POINT Snap to a vertex on a mesh.
    SNAPMODE_SPLINE Snap to any point along a spline.
    SNAPMODE_DYNAMICGUIDE Snap using dynamic or “inferred” guides.
    SNAPMODE_SPLINEMID Snap to the middle of a spline segment.
    SNAPMODE_EDGE Snap to any point along an edge.
    SNAPMODE_EDGEMID Snap to the middle of an edge.
    SNAPMODE_POLYGON Snap to the surface of a polygon.
    SNAPMODE_POLYGONCENTER Snap to the center of individual polygons.
    SNAPMODE_WORKPLANE Snap to the surface of the workplane.
    SNAPMODE_AXIS Snap to the axis of an object.
    SNAPMODE_ORTHO Snap perpendicular to guides edges and splines.
    SNAPMODE_GRIDPOINT Snap to the intersection points of the grid on the workplane.
    SNAPMODE_GRIDLINE Snap to the grid lines on the workplane.
    SNAPMODE_MIDPOINT Snap for mid points. Allow subsnap for each parent mode that have it.
    SNAPMODE_GUIDEMID Snap the middle point in between of static guides interesections.
c4d.modules.snap.IsQuantizeEnabled(doc)

Check if quantizing is enabled for the document doc.

Parameters:doc (BaseDocument) – The document to test for.
Return type:bool
Returns:True if quantizing is enabled, otherwise False.
c4d.modules.snap.GetQuantizeStep(doc, bd, quantize_mode)

Get the quantize step values from QUANTIZE_MOVE, QUANTIZE_SCALE etc.

Parameters:
  • doc (BaseDocument) – The document to get the values.
  • bd (BaseDraw) – The view that you want to retrieve the correct QUANTIZE_MOVE value for. Not relevant for other quantize modes (pass None).
  • quantize_mode (int) – The mode you want to retrieve the value for, e.g. QUANTIZE_ROTATE, QUANTIZE_MOVE, QUANTIZE_SCALE or QUANTIZE_TEXTURE.
c4d.modules.snap.SetQuantizeStep(doc, bd, quantize_mode, val)

Set the quantize step values for QUANTIZE_MOVE, QUANTIZE_SCALE etc.

Parameters:
  • doc (BaseDocument) – The document to set the values.
  • bd (BaseDraw) – The view that you want to set the correct QUANTIZE_MOVE value for. Not relevant for other quantize modes (pass None).
  • quantize_mode (int) – The mode you want to set the value for, e.g. QUANTIZE_ROTATE, QUANTIZE_MOVE, QUANTIZE_SCALE or QUANTIZE_TEXTURE.
  • val (float) – The new quantizing step value.
c4d.modules.snap.GetWorkplaneObject(doc)

Retrieve the workplane object for document doc.

Parameters:doc (BaseDocument) – The document.
Return type:BaseObject
Returns:The workplane object.
c4d.modules.snap.IsWorkplaneLock(doc)

Get the workplane locked status for document doc.

Parameters:doc (BaseDocument) – The document.
Return type:bool
Returns:True if the workplane is locked.
c4d.modules.snap.SetWorkplaneLock(bd, locked)

Set the workplane locked status.

Parameters:
  • bd (BaseDraw) – The viewport to lock the workplane.
  • locked (bool) – True to lock the workplane.
c4d.modules.snap.GetWorkplaneMatrix(doc, bd)

Get the workplane matrix.

Parameters:
  • doc (BaseDocument) – The document.
  • bd (BaseDraw) – The viewport you want to get the workplane’s matrix from. If None the locked matrix is returned independently from view.
Return type:

Matrix

Returns:

The workplane matrix.

Table Of Contents