c4d.utils

Follow me to the Inheritance diagramm.

Members

c4d.utils.SendModelingCommand(command, list[, mode=MODIFY_ALL[, bc[, doc[, flags]]]])

With this function one can apply nearly all modeling commands. The function is applied to the objects in list. With the parameter mode you can decide if the current selection should be used to control what points/polygons are affected.

Note

Current State to Object(CSTO) has to be executed on a duplicate of an object because CSTO modifies the existing caches. In some cases you have to use a temporary document as well ObjectData.GetVirtualObjects().

This is a small example how you can use this function:

import c4d
from c4d import utils

settings = c4d.BaseContainer()                 # Settings
settings[c4d.MDATA_EXTRUDE_OFFSET] = 50.0      # Length of the extrusion

res = utils.SendModelingCommand(command = c4d.ID_MODELING_EXTRUDE_TOOL,
                                list = [op],
                                mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                                bc = settings,
                                doc = doc)
c4d.EventAdd()

if res is False:
    print "Something went wrong."
elif res is True:
    print "Command successfull."
elif isinstance(res, list):
    print "Here you get the newly created object(s)."
Parameters:
  • command (int) –
    • There are several groups of IDs to use. First there are the internal modeling commands: (Indented IDs MDATA_* are for the passed container bc.)
    MCOMMAND_SPLINE_HARDINTERPOLATION Hard interpolation.      
    MCOMMAND_SPLINE_SOFTINTERPOLATION Soft interpolation.      
    MCOMMAND_SPLINE_REORDER Set first point.      
    MCOMMAND_SPLINE_REVERSE Reverse sequence.      
    MCOMMAND_SPLINE_MOVEDOWN Move down sequence.      
    MCOMMAND_SPLINE_MOVEUP Move up sequence.      
    MCOMMAND_SPLINE_JOINSEGMENT Join segment.      
    MCOMMAND_SPLINE_BREAKSEGMENT Break segment.      
    MCOMMAND_SPLINE_EQUALLENGTH Equal tangent length.      
    MCOMMAND_SPLINE_EQUALDIRECTION Equal tangent direction.      
    MCOMMAND_SPLINE_LINEUP Line up.      
    MCOMMAND_SPLINE_CREATEOUTLINE Create outline:      
      MDATA_SPLINE_OUTLINE float Distance.  
      MDATA_SPLINE_PROJECTMODE int Projection. (See dialog.)  
      MDATA_SPLINE_ADDPOINTSEGMENT int Segment.  
      MDATA_SPLINE_ADDPOINTPOSITION float Position.  
      MDATA_SPLINE_ADDPOINTSELECT bool Select added point.  
      MDATA_SPLINE_OUTLINESEPARATE bool Create new object.  
    MCOMMAND_SPLINE_PROJECT Project:      
      MDATA_SPLINE_PROJECTMODE int Projection. (See dialog.)  
    MCOMMAND_SPLINE_ADDPOINT Add point:      
      MDATA_SPLINE_ADDPOINTSEGMENT int Segment.  
      MDATA_SPLINE_ADDPOINTPOSITION float Position.  
    MCOMMAND_SELECTALL Select all.      
    MCOMMAND_DESELECTALL Deselect all.      
    MCOMMAND_SELECTINVERSE Invert selection.      
    MCOMMAND_SELECTCONNECTED Select connected.      
    MCOMMAND_SELECTGROW Grow selection.      
    MCOMMAND_SELECTSHRINK Shrink selection.      
    MCOMMAND_SELECTPOINTTOPOLY Polygon selection from points.      
    MCOMMAND_SELECTPOLYTOPOINT Point selection from polygons.      
    MCOMMAND_SELECTADJACENT Select adjacent.      
    MCOMMAND_GENERATESELECTION Set selection.      
    MCOMMAND_HIDESELECTED Hide selected.      
    MCOMMAND_HIDEUNSELECTED Hide unselected.      
    MCOMMAND_HIDEINVERT Invert visibility.      
    MCOMMAND_UNHIDE Unhide all.      
    MCOMMAND_REVERSENORMALS Reverse normals.      
    MCOMMAND_ALIGNNORMALS Align normals.      
    MCOMMAND_SPLIT Split.      
    MCOMMAND_TRIANGULATE Triangulate.      
    MCOMMAND_UNTRIANGULATE Untriangulate:      
      MDATA_UNTRIANGULATE_NGONS bool Create N-gons.  
      MDATA_UNTRIANGULATE_ANGLE_RAD float Untriangulate angle radius.  
      MDATA_CONVERTSELECTION_LEFT int Left selection. (See dialog.)  
      MDATA_CONVERTSELECTION_RIGHT int Right selection. (See dialog.)  
      MDATA_CONVERTSELECTION_TOLERANT bool Tolerant conversion.  
      MDATA_CURRENTSTATETOOBJECT_INHERITANCE bool Use inheritance.  
      MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION bool Keep animation.  
      MDATA_CURRENTSTATETOOBJECT_NOGENERATE bool No generate.  
      MDATA_ROTATECAMERA bool Tools/Camera Rotation.  
      MDATA_RING_EDGE int Ring edge.  
      MDATA_RING_SELECTION int Ring selection:  
          SELECTION_NEW Starts a new selection.
          SELECTION_ADD Adds to the current selection.
          SELECTION_SUB Subtracts from the current selection.
      MDATA_RING_SKIP int Ring skip.  
      MDATA_FILLSEL_START_POLY int Fill selection start polygon.  
      MDATA_FILLSEL_SELECTION int Fill selection:  
          SELECTION_NEW Starts a new selection.
          SELECTION_ADD Adds to the current selection.
          SELECTION_SUB Subtracts from the current selection.
      MDATA_OUTLINESEL_START_POLY int Outline selection start polygon.  
      MDATA_OUTLINESEL_SELECTION int Outline selection:  
          SELECTION_NEW Starts a new selection.
          SELECTION_ADD Adds to the current selection.
          SELECTION_SUB Subtracts from the current selection.
      MDATA_RESETSYSTEM_COMPENSATE bool Offsets.  
      MDATA_RESETSYSTEM_RECURSIVE bool Reset sub-objects.  
      MDATA_JOIN_MERGE_SELTAGS bool Merge selection tags.  
      MDATA_SETVERTEX_VALUE float Value.  
      MDATA_SETVERTEX_MODE int Mode. (See dialog.)  
    MCOMMAND_DELETE Delete.      
    MCOMMAND_OPTIMIZE Optimize:      
      MDATA_OPTIMIZE_TOLERANCE float Tolerance.  
      MDATA_OPTIMIZE_POINTS bool Points.  
      MDATA_OPTIMIZE_POLYGONS bool Polygons.  
      MDATA_OPTIMIZE_UNUSEDPOINTS bool Unused points.  
    MCOMMAND_DISCONNECT Disconnect:      
      MDATA_DISCONNECT_PRESERVEGROUPS bool Preserve groups.  
    MCOMMAND_MAKEEDITABLE Make editable. (Returns object.)      
    MCOMMAND_MIRROR Mirror:      
      MDATA_MIRROR_SNAPPOINTS bool Snap to points.  
      MDATA_MIRROR_DUPLICATE bool Duplicate points.  
      MDATA_MIRROR_WELD bool Weld points.  
      MDATA_MIRROR_TOLERANCE float Weld tolerance.  
      MDATA_MIRROR_SYSTEM int Coordinate system. (See dialog.)  
      MDATA_MIRROR_PLANE int Mirror plane. (See dialog.)  
      MDATA_MIRROR_VALUE float Value.  
      MDATA_MIRROR_POINT Vector Mirror point.  
      MDATA_MIRROR_VECTOR Vector Mirror vector.  
      MDATA_MIRROR_SELECTIONS bool Duplicate tag selections.  
      MDATA_MIRROR_ONPLANE bool Symmetric.  
    MCOMMAND_SUBDIVIDE Subdivide:      
      MDATA_SUBDIVIDE_HYPER bool Hyper NURBS subdivide.  
      MDATA_SUBDIVIDE_ANGLE float Maximum angle.  
      MDATA_SUBDIVIDE_SPLINESUB int Subdivisions. (Spline.)  
      MDATA_SUBDIVIDE_SUB int Subdivisions. (Polygon.)  
    MCOMMAND_EXPLODESEGMENTS Explode segments.      
    MCOMMAND_KNIFE Knife. See toolknife.h.      
    MCOMMAND_CURRENTSTATETOOBJECT Current state to object: (Returns object.)      
      MDATA_CURRENTSTATETOOBJECT_INHERITANCE bool Use inheritance.  
      MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION bool Keep animation.  
      MDATA_CURRENTSTATETOOBJECT_NOGENERATE bool No generate.  
    MCOMMAND_JOIN Join: (Returns object.)      
      MDATA_JOIN_MERGE_SELTAGS bool Merge selection tags.  
    MCOMMAND_CONVERTSELECTION Convert selection.      
      MDATA_CONVERTSELECTION_LEFT int Left selection. (See dialog.)  
      MDATA_CONVERTSELECTION_RIGHT int Right selection. (See dialog.)  
      MDATA_CONVERTSELECTION_TOLERANT bool Tolerant conversion.  
      MDATA_CURRENTSTATETOOBJECT_INHERITANCE bool Use inheritance.  
      MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION bool Keep animation.  
      MDATA_CURRENTSTATETOOBJECT_NOGENERATE bool No generate.  
      MDATA_ROTATECAMERA bool Tools/Camera Rotation.  
      MDATA_RING_EDGE int Ring edge.  
      MDATA_RING_SELECTION int Ring selection:  
          SELECTION_NEW Starts a new selection.
          SELECTION_ADD Adds to the current selection.
          SELECTION_SUB Subtracts from the current selection.
      MDATA_RING_SKIP int Ring skip.  
      MDATA_FILLSEL_START_POLY int Fill selection start polygon.  
      MDATA_FILLSEL_SELECTION int Fill selection:  
          SELECTION_NEW Starts a new selection.
          SELECTION_ADD Adds to the current selection.
          SELECTION_SUB Subtracts from the current selection.
      MDATA_OUTLINESEL_START_POLY int Outline selection start polygon.  
      MDATA_OUTLINESEL_SELECTION int Outline selection:  
          SELECTION_NEW Starts a new selection.
          SELECTION_ADD Adds to the current selection.
          SELECTION_SUB Subtracts from the current selection.
      MDATA_RESETSYSTEM_COMPENSATE bool Offsets.  
      MDATA_RESETSYSTEM_RECURSIVE bool Reset sub-objects.  
      MDATA_JOIN_MERGE_SELTAGS bool Merge selection tags.  
      MDATA_SETVERTEX_VALUE float Value.  
      MDATA_SETVERTEX_MODE int Mode. (See dialog.)  
    MCOMMAND_EDGE_TO_SPLINE Edge to spline      
    MCOMMAND_BREAKPHONG Break phong.      
    MCOMMAND_UNBREAKPHONG Unbreak phong.      
    MCOMMAND_PHONGTOSELECTION Phong to selection.      
    MCOMMAND_MELT Melt.      
    MCOMMAND_RESETSYSTEM Reset System:      
      MDATA_RESETSYSTEM_COMPENSATE bool Offsets.  
      MDATA_RESETSYSTEM_RECURSIVE bool Reset sub-objects.  
    • Then there are the modeling library tool IDs, where you have to look up the parameters in the resource files:
    ID_MODELING_EDGECUT_TOOL Edge cut tool. See tooledgecut.h.
    ID_MODELING_FILL_SELECTION_TOOL Fill selection tool.
    ID_MODELING_OUTLINE_SELECTION_TOOL Private.
    ID_MODELING_LOOP_TOOL Loop selection tool. See toolloopselection.h.
    ID_MODELING_RING_TOOL Ring selection tool.
    ID_MODELING_EXTRUDE_TOOL Extrude tool. See toolextrude.h.
    ID_MODELING_MATRIX_EXTRUDE_TOOL Matrix extrude tool. See toolmatrixextrude.h.
    ID_MODELING_NORMALMOVE_TOOL Normal move tool. See toolnormalmove.h.
    ID_MODELING_NORMALSCALE_TOOL Normal scale tool. See toolnormalscale.h.
    ID_MODELING_NORMALROTATE_TOOL Normal rotate tool. See toolnormalrotate.h.
    ID_MODELING_SMOOTH_SHIFT_TOOL Smooth shift tool. See toolsmoothshift.h.
    ID_MODELING_EXTRUDE_INNER_TOOL Extrude inner tool. See toolextrudeinner.h.
    ID_MODELING_BEVEL_TOOL Bevel tool. See toolbevel.h.
    ID_MODELING_POLYGON_CREATE_TOOL Create polygon tool. See toolcreatepolygon.h.
    ID_MODELING_POINT_ADD_TOOL Add point tool. See tooladdpoint.h.
    ID_MODELING_BRIDGE_TOOL Bridge tool. See toolbridge.h.
    ID_MODELING_WELD_TOOL Weld tool. See toolpointweld.h.
    ID_MODELING_CLOSEHOLE_TOOL Close polygon hole tool. See toolclosehold.h.
    ID_MODELING_STITCHANDSEW_TOOL Stich and sew tool. See toolstitchandsew.h.
    ID_MODELING_SLIDE_TOOL Slide tool. See toolslide.h.
    ID_MODELING_IRON_TOOL Iron tool. See tooliron.h.
    ID_MODELING_SETVALUE_TOOL Set value tool. See toolsetvalue.h.
    ID_MODELING_DUPLICATE_TOOL Duplicate tool. See toolduplicate.h.
    ID_MODELING_ARRANGE_TOOL Arrange tool. See toolarrange.h.
    ID_MODELING_TRANSFER_TOOL Transfer tool. See tooltransfer.h.
    ID_MODELING_RANDOMIZE_TOOL Randomize tool. See toolrandomize.h.
    ID_MODELING_CENTER_TOOL Center tool. See toolcenter.h.
    ID_MODELING_KNIFE_TOOL Knife tool. See toolknife.h.
    ID_MODELING_LIVESELECTION Live selection tool. See toolliveselection.h.
    ID_MODELING_RECTSELECTION Rectangle selection tool. See toolrectselection.h.
    ID_MODELING_FREESELECTION Free selection tool. See toolfreeselection.h.
    ID_MODELING_POLYSELECTION Polygon selection tool. See toolpolyselection.h.
    ID_MODELING_MODIFY_TOOL Modify tool. See toolmodify.h.
    ID_MEASURE_TOOL Measure tool. See toolmeasure.h.
    ID_MODELING_MAGNET_TOOL Magnet tool. See toolmagnet.h.
    ID_MODELING_BRUSH_TOOL Brush tool. See toolbrush.h.
    ID_MODELING_SPLINE_ROUND_TOOL Spline round tool. See toolsplineround.h.
    ID_MODELING_CLONE_TOOL Clone tool. See toolclone.h.
    ID_MODELING_SPLINE_CHAMFER_TOOL Spline chamfer tool. See toolsplinechamfer.h.
    ID_MODELING_ARRAY_TOOL Array tool. See toolarray.h.
    ID_MODELING_SPLINE_PROJECT_TOOL Spline project tool. See toolsplineproject.h.
    • Finally there are the modeling library menu commands. These have no parameters:
    ID_MODELING_MELT_COMMAND Melt.
    ID_MODELING_EDGE_SPLINE_COMMAND Edge to spline.
    ID_MODELING_COLLAPSE_COMMAND Collapse.
    ID_NGON_RETRI_MENU Retriangulate N-gons.
    ID_NGON_REMOVE_MENU Remove N-gons.
    ID_NGON_FORCERETRI_MENU Force N-gon triangulation.
    ID_OBJECTHANDLES_ONOFF_MENU Object handles toggle.
    ID_SDS_INC_MENU Increment SDS.
    ID_SDS_DEC_MENU Decrement SDS.
    ID_SDS_ONFFF_MENU Toggle SDS.
    ID_MODELING_OM_SELECT_INVERT Invert object manager selection.
    ID_MODELING_OM_SELECT_HIDE Hide selected objects.
    ID_MODELING_OM_SELECT_SHOW Show selected objects.
    ID_MODELING_SHORTCUT_SELECTVISIBLE Toggle select visible.
    ID_CAMERA_SET_PIVOT Set the camera pivot.
    ID_CAMERA_LOCK_PIVOT Locks/unlocks the camera’s Point of Interest (POI) to the last used POI location.
    ID_LASTTOOL_START The first of the last used tools. The next last used tools can be accessed with ID_LASTTOOL_START + (1...6)
    ID_LASTTOOL_END The last of the last used tools.
  • list (list of BaseObjects) – A list with objects which you want to apply the modeling command.
  • bc (BaseContainer) – This is a settings container which contains all the values of the tool you want to apply.
  • mode (int) –

    Modeling mode:

    MODELINGCOMMANDMODE_ALL All points/polygons.
    MODELINGCOMMANDMODE_POINTSELECTION Only the current point selection.
    MODELINGCOMMANDMODE_POLYGONSELECTION Only the polygon point selection.
    MODELINGCOMMANDMODE_EDGESELECTION Only the edge point selection.
  • doc (BaseDocument) –
    The document for the operation. Should be set if possible. Must be set for MCOMMAND_MAKEEDITABLE, MCOMMAND_CURRENTSTATETOOBJECT and MCOMMAND_SPLINE_PROJECT.
    If you set the document, the objects which you pass to this function have to be in the same document. So pay attention that you use one send_modeling_command per document for objects.
  • flags (int) –

    The flags:

    MODELINGCOMMANDFLAGS_0 No flags.
    MODELINGCOMMANDFLAGS_CREATEUNDO Creates undo and inserts newly created objects into doc.
Return type:

False, True or list of BaseObject

Returns:

True if the command succeeded, otherwise False if something went wrong. Some commands don’t apply their task to the passed objects, they return a cloned object so just check it.

c4d.utils.GetAngle(v1, v2)

Calculates the angle of two vectors.

Parameters:
  • v1 (Vector) – Input value in degrees.
  • v2 (Vector) – Input value in degrees.
Return type:

float

Returns:

The angle.

c4d.utils.RangeMap(value, mininput, maxinput, minoutput, maxoutput, clampval[, curve])

Map the value of a range to another. Similiar to the RangeMapper Node. Here is a small example:

print RangeMap(value=0.5, mininput=0, maxinput=1, minoutput=5, maxoutput=10, clampval=False)
#Output: 7.5
Parameters:
  • value (float) – The value
  • mininput (float) – The minimum Input
  • maxinput (float) – The maximum Input
  • minoutput (float) – The minimum Output
  • maxoutput (float) – The maximum Output
  • clampval (bool) – Currently not implemented. Please use False here.
  • curve (SplineData) – The curve.
c4d.utils.Rad(d)

Convert a degrees value into radians.

Parameters: r (number) – Input value in degrees.
Return type: number
Returns: Converted value in radians.
c4d.utils.Deg(r)

Convert a radians value into degrees.

Parameters: r (number) – Input value in radians.
Return type: number
Returns: Converted value in degrees.
c4d.utils.MixVec(v1, v2, t)

Mixes the two vectors together, such as mixing two colours.

Parameters:
  • v1 (Vector) – Vector to mix.
  • v2 (Vector) – Vector to mix.
  • t (number) – Mix amount
Math :

0 < t < 1.0

Return type:

Vector

Returns:

The mixed vector.

c4d.utils.MixNum(v1, v2, t)

Returns a mixed value of v1 and v2 using the parameter t, as calculated by v1+(v2-v1)*t.

Parameters:
  • v1 (float) – Value to mix.
  • v2 (float) – Value to mix.
  • t (number) – Mix amount.
Math :

0 < t < 1.0

Return type:

float

Returns:

Mix amount, with 0 <= t <= 1.0.

c4d.utils.Pulse(a, b, x)

Returns 1.0 if x is between or equal to either of a and b, else 0.0.

Parameters:
  • a (number) – The float value.
  • b (number) – The float value.
  • x (number) – The float value.
Return type:

float

Returns:

The pulse value.

c4d.utils.Clamp(a, b, x)

Returns a if x is less than a and b if x is greater than b, else returns x.

Note :

The order of parameters different to Peachey’s definition.

Parameters:
  • a (number) – The float value.
  • b (number) – The float value.
  • x (number) – The float value.
Return type:

float

Returns:

The clamped value.

c4d.utils.Step(a, b)

Returns 1.0 if x is greater than or equal to a, else 0.0.

Parameters:
  • a (number) – The float value.
  • b (number) – The float value.
Return type:

float

Returns:

The step value (1.0 or 0.0).

c4d.utils.Smoothstep(a, b, x)

Returns 0.0 if x is less than a and 1.0 if x is greater than b, else returns x mapped on the range [a,b] (a number between 0.0 and 1.0). The mapping is smoothed using an ease-in/ease-out curve.

Parameters:
  • a (float) – The float value.
  • b (float) – The float value.
  • x (float) – The float value.
Return type:

float

Returns:

The smoothed value.

c4d.utils.Boxstep(a, b, x)

Returns 0.0 if x is less than a and 1.0 if x is greater than b, else returns x mapped on the range [a,b] (a number between 0.0 and 1.0).

Parameters:
  • a (number) – The float value.
  • b (number) – The float value.
  • x (number) – The float value.
Return type:

float

Returns:

The stepped value.

c4d.utils.MatrixRotX(w)

Creates a rotation matrix about the X axis.

Parameters: w (float) – The angle around X.
Return type: Matrix
Returns: The rotation matrix.
c4d.utils.MatrixRotY(w)

Creates a rotation matrix about the Y axis.

Parameters: w (float) – The angle around Y.
Return type: Matrix
Returns: The rotation matrix.
c4d.utils.MatrixRotZ(w)

Creates a rotation matrix about the Z axis.

Parameters: w (float) – The angle around Z.
Return type: Matrix
Returns: The rotation matrix.
c4d.utils.MatrixToRotAxis(m)

Calculates rotation axis and angle from matrix m:

v, w = MatrixToRotAxis(m)
#v is the rotation axis, c4d.Vector
#w is the rotation angle, float
Parameters: m (Matrix) – Rotation matrix.
Return type: list
Returns: The rotation axis, and the angle.
c4d.utils.RotAxisToMatrix(v, w)

Calculate matrix from rotation axis v and angle w:

:type v: :class:`Vector `
:param v: The axis
:type w: float
:param w: The angle of rotation
:rtype: :class:`Matrix `
:return: Rotation matrix.
c4d.utils.GetOptimalAngle(hpb_old, hpb_new, rotation_order)

Modify hpb_new so that the “distance” to the last angle hpb_old is at minimum. This helps to avoid HPB singularity effects.

Parameters:
  • hpb_old (Vector) – The old HPB.
  • hpb_new (Vector) – The new HPB.
  • rotation_order (int) –

    New in version R13.016.

    The order of rotation:

    ROTATIONORDER_YXZGLOBAL Global YXZ order.
    ROTATIONORDER_YZXGLOBAL Global YZX order.
    ROTATIONORDER_ZYXGLOBAL Global ZYX order.
    ROTATIONORDER_ZXYGLOBAL Global ZXY order.
    ROTATIONORDER_XZYGLOBAL Global XZY order.
    ROTATIONORDER_XYZGLOBAL Global XYZ order.
    ROTATIONORDER_YXZLOCAL Local YXZ order.
    ROTATIONORDER_YZXLOCAL Local YZX order.
    ROTATIONORDER_ZYXLOCAL Local ZYX order.
    ROTATIONORDER_ZXYLOCAL Local ZXY order.
    ROTATIONORDER_XZYLOCAL Local XZY order.
    ROTATIONORDER_XYZLOCAL Local XYZ order.
    ROTATIONORDER_HPB HPB order.
    ROTATIONORDER_DEFAULT ROTATIONORDER_HPB
Return type:

Vector

Returns:

The optimal angle.

c4d.utils.PointLineDistance(p0, v, p)

Calculates the distance from a point to a line.

Parameters:
  • p0 (Vector) – The starting point of the line.
  • v (Vector) – The line vector.
  • p (Vector) – The point.
Return type:

Vector

Returns:

Point-line vector.

c4d.utils.ReflectRay(v, n)

Find the ray vector after a reflection about a surface normal.

Parameters:
  • v (Vector) – The incoming ray.
  • n (Vector) – The surface normal.
  • p (Vector) – The reflected ray.
c4d.utils.CalcSpline(x, knots)

Calculates the value of a spline at a point.

Parameters:
  • x (float) – The position on the spline.
  • knots (list of float) – The knots list.
Return type:

float

Returns:

The spline value.

c4d.utils.CalcSplineV(x, knots)

Calculates the value of a spline at a point.

Parameters:
  • x (float) – The position on the spline.
  • knots (list of Vector) – The knots list.
Return type:

Vector

Returns:

The spline value.

c4d.utils.RGBToHSV(col)

Converts RGB into the HSV color space and returns the converted value.

Parameters: col (Vector) – RGB color.
Return type: Vector
Returns: HSV color.
c4d.utils.HSVToRGB(col)

Converts HSV into the RGB color space and returns the converted value.

Parameters: col (Vector) – HSV color.
Return type: Vector
Returns: RGB color.
c4d.utils.VectorEqual(v1, v2[, epsilon=0.01])

Check if vector v1 and v2 are within epsilon of each other.

Parameters:
  • v1 (Vector) – The first vector.
  • v2 (Vector) – The second vector.
  • epsilon (float) – The epsilon value.
Return type:

bool

Returns:

True if the vectors are equal.

c4d.utils.Bias(b, x)

Returns the bias as the defined in the book “Texturing and Modeling” by Ebert.

The internal code:

import math

def Bias(b, x):
    return math.pow(x, -math.log(b) / 0.693147180559945)
Parameters:
  • b (number) – Bias value.
  • x (number) – The real value.
Return type:

float

Returns:

The bias.

c4d.utils.FCut(a, b, c)

Limit the value of a to between b and c.

Parameters:
  • a (float) – Value
  • b (float) – Lower bound
  • c (float) – Upper bound
c4d.utils.CutColor(vec)

Limit a color vector between 0.0 and 1.0.

Parameters: vec (Vector) – Bias value.
Return type: Vector
Returns: The limited color vector.
c4d.utils.Truncate(x)

Limit a color vector between 0.0 and 1.0.

The internal code:

import math

def Truncate(x):
    if x >= 0.0:
        return math.floor(x)
    else:
        return math.fceil(x)
Parameters: x (number) – The value to truncate.
Return type: float
Returns: The truncated value.
c4d.utils.VectorSum(vec)

Sum the vector components.

Parameters: x (Vector) – A color
Return type: float
Returns: The sum of the components.
c4d.utils.VectorGray(vec)

Sum the vector components and multiply by 1/3.

Parameters: vec (Vector) – A color
Return type: float
Returns: The gray value.
c4d.utils.VectorAngle(vec1, vec2)

Calculates the angle between two vectors in radians.

Parameters:
  • vec1 (Vector) – The first vector.
  • vec2 (Vector) – The second vector.
Return type:

float

Returns:

The angle in radians.

c4d.utils.VectorMin(vec)

Find the minimum component of the vector.

Parameters: vec (Vector) – The vector to find the minimum component of.
Return type: float
Returns: The minimum component of the vector.
c4d.utils.VectorMax(vec)

Find the maximum component of the vector.

Parameters: vec (Vector) – The vector to find the maximum component of.
Return type: float
Returns: The maximum component of the vector.
c4d.utils.MatrixMove(vec)

Create a translation matrix.

Parameters: vec (Vector) – The translation vector.
Return type: Matrix
Returns: The translation matrix.
c4d.utils.MatrixScale(s)

Create a scaling matrix.

Parameters: s (Vector) – The scaling vector for the axes.
Return type: Matrix
Returns: The scaling matrix.
c4d.utils.VectorToHPB(p)

Calculate euler angles from the vector p. The bank is always set to 0.0.

Parameters: p (Vector) – The vector to find the HPB for.
Return type: Vector
Returns: The rotation HPB.
c4d.utils.MatrixToHPB(m[, order=ROTATIONORDER_DEFAULT])

Calculate euler angles from the matrix m.

Parameters:
  • m (Matrix) – The rotation matrix.
  • order (int) –

    New in version R13.016.

    The order of rotation:

    ROTATIONORDER_YXZGLOBAL Global YXZ order.
    ROTATIONORDER_YZXGLOBAL Global YZX order.
    ROTATIONORDER_ZYXGLOBAL Global ZYX order.
    ROTATIONORDER_ZXYGLOBAL Global ZXY order.
    ROTATIONORDER_XZYGLOBAL Global XZY order.
    ROTATIONORDER_XYZGLOBAL Global XYZ order.
    ROTATIONORDER_YXZLOCAL Local YXZ order.
    ROTATIONORDER_YZXLOCAL Local YZX order.
    ROTATIONORDER_ZYXLOCAL Local ZYX order.
    ROTATIONORDER_ZXYLOCAL Local ZXY order.
    ROTATIONORDER_XZYLOCAL Local XZY order.
    ROTATIONORDER_XYZLOCAL Local XYZ order.
    ROTATIONORDER_HPB HPB order.
    ROTATIONORDER_DEFAULT ROTATIONORDER_HPB
Return type:

Vector

Returns:

The HPB.

c4d.utils.HPBToMatrix(hpb[, order=ROTATIONORDER_DEFAULT])

Construct matrix from the euler angles hpb.

Parameters:
  • hpb (Vector) – The input HPB.
  • order (int) –

    The order of rotation:

    ROTATIONORDER_YXZGLOBAL Global YXZ order.
    ROTATIONORDER_YZXGLOBAL Global YZX order.
    ROTATIONORDER_ZYXGLOBAL Global ZYX order.
    ROTATIONORDER_ZXYGLOBAL Global ZXY order.
    ROTATIONORDER_XZYGLOBAL Global XZY order.
    ROTATIONORDER_XYZGLOBAL Global XYZ order.
    ROTATIONORDER_YXZLOCAL Local YXZ order.
    ROTATIONORDER_YZXLOCAL Local YZX order.
    ROTATIONORDER_ZYXLOCAL Local ZYX order.
    ROTATIONORDER_ZXYLOCAL Local ZXY order.
    ROTATIONORDER_XZYLOCAL Local XZY order.
    ROTATIONORDER_XYZLOCAL Local XYZ order.
    ROTATIONORDER_HPB HPB order.
    ROTATIONORDER_DEFAULT ROTATIONORDER_HPB
Return type:

Matrix

Returns:

The rotation matrix.

c4d.utils.CalcLOD(val, lod, min, max)

This is a helper function to modify a user chosen subdivision value. For example:

sub = utils.CalcLOD(op[TUBEOBJECT_SUB, 1], hh["lod"], 1, 1000)
Parameters:
  • val (int) – The user chosen lod value.
  • lod (float) – The LOD value.
  • min (int) – The minimum lod.
  • max (int) – The maximum lod.
c4d.utils.CompareFloatTolerant(a, b)

Compares if two floats are close to each other on a bit basis (rather than a fixed epsilon).

Parameters:
  • a (float) – The first parameter.
  • b (float) – The second parameter.
Return type:

bool

Returns:

True if a and b are sufficiently close to each other, otherwise False.

c4d.utils.SinCos(w)

Get sine and cosine of w:

sn, cs = SinCos(80)
Parameters: w (float) – Value.
Return type: list
Returns: Sine and Cosine.
c4d.utils.TransformColor(input, colortransformation)

New in version R13.016.

Transforms a color from one color profile to another.

Parameters:
  • input (Vector) – The color to transform.
  • colortransformation (int) –

    Transformation mode:

    COLORSPACETRANSFORMATION_NONE None.
    COLORSPACETRANSFORMATION_LINEAR_TO_SRGB Linear to sRGB color space transformation.
    COLORSPACETRANSFORMATION_SRGB_TO_LINEAR sRGB to linear color space transformation.
    COLORSPACETRANSFORMATION_LINEAR_TO_VIEW Linear to display color space transformation.
    COLORSPACETRANSFORMATION_SRGB_TO_VIEW sRGB to display color space transformation.
Return type:

Vector

Returns:

The transformed color.

c4d.utils.CalculateTranslationScale(src, dst)

New in version R13.016.

Calculates the scale between src and dst.

Parameters:
Return type:

float

Returns:

The scale.

Commands for SendModelingCommand():

  • There are several groups of IDs to use. First there are the internal modeling commands: (Indented IDs MDATA_* are for the passed container bc.)
MCOMMAND_SPLINE_HARDINTERPOLATION Hard interpolation.      
MCOMMAND_SPLINE_SOFTINTERPOLATION Soft interpolation.      
MCOMMAND_SPLINE_REORDER Set first point.      
MCOMMAND_SPLINE_REVERSE Reverse sequence.      
MCOMMAND_SPLINE_MOVEDOWN Move down sequence.      
MCOMMAND_SPLINE_MOVEUP Move up sequence.      
MCOMMAND_SPLINE_JOINSEGMENT Join segment.      
MCOMMAND_SPLINE_BREAKSEGMENT Break segment.      
MCOMMAND_SPLINE_EQUALLENGTH Equal tangent length.      
MCOMMAND_SPLINE_EQUALDIRECTION Equal tangent direction.      
MCOMMAND_SPLINE_LINEUP Line up.      
MCOMMAND_SPLINE_CREATEOUTLINE Create outline:      
  MDATA_SPLINE_OUTLINE float Distance.  
  MDATA_SPLINE_PROJECTMODE int Projection. (See dialog.)  
  MDATA_SPLINE_ADDPOINTSEGMENT int Segment.  
  MDATA_SPLINE_ADDPOINTPOSITION float Position.  
  MDATA_SPLINE_ADDPOINTSELECT bool Select added point.  
  MDATA_SPLINE_OUTLINESEPARATE bool Create new object.  
MCOMMAND_SPLINE_PROJECT Project:      
  MDATA_SPLINE_PROJECTMODE int Projection. (See dialog.)  
MCOMMAND_SPLINE_ADDPOINT Add point:      
  MDATA_SPLINE_ADDPOINTSEGMENT int Segment.  
  MDATA_SPLINE_ADDPOINTPOSITION float Position.  
MCOMMAND_SELECTALL Select all.      
MCOMMAND_DESELECTALL Deselect all.      
MCOMMAND_SELECTINVERSE Invert selection.      
MCOMMAND_SELECTCONNECTED Select connected.      
MCOMMAND_SELECTGROW Grow selection.      
MCOMMAND_SELECTSHRINK Shrink selection.      
MCOMMAND_SELECTPOINTTOPOLY Polygon selection from points.      
MCOMMAND_SELECTPOLYTOPOINT Point selection from polygons.      
MCOMMAND_SELECTADJACENT Select adjacent.      
MCOMMAND_GENERATESELECTION Set selection.      
MCOMMAND_HIDESELECTED Hide selected.      
MCOMMAND_HIDEUNSELECTED Hide unselected.      
MCOMMAND_HIDEINVERT Invert visibility.      
MCOMMAND_UNHIDE Unhide all.      
MCOMMAND_REVERSENORMALS Reverse normals.      
MCOMMAND_ALIGNNORMALS Align normals.      
MCOMMAND_SPLIT Split.      
MCOMMAND_TRIANGULATE Triangulate.      
MCOMMAND_UNTRIANGULATE Untriangulate:      
  MDATA_UNTRIANGULATE_NGONS bool Create N-gons.  
  MDATA_UNTRIANGULATE_ANGLE_RAD float Untriangulate angle radius.  
  MDATA_CONVERTSELECTION_LEFT int Left selection. (See dialog.)  
  MDATA_CONVERTSELECTION_RIGHT int Right selection. (See dialog.)  
  MDATA_CONVERTSELECTION_TOLERANT bool Tolerant conversion.  
  MDATA_CURRENTSTATETOOBJECT_INHERITANCE bool Use inheritance.  
  MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION bool Keep animation.  
  MDATA_CURRENTSTATETOOBJECT_NOGENERATE bool No generate.  
  MDATA_ROTATECAMERA bool Tools/Camera Rotation.  
  MDATA_RING_EDGE int Ring edge.  
  MDATA_RING_SELECTION int Ring selection:  
      SELECTION_NEW Starts a new selection.
      SELECTION_ADD Adds to the current selection.
      SELECTION_SUB Subtracts from the current selection.
  MDATA_RING_SKIP int Ring skip.  
  MDATA_FILLSEL_START_POLY int Fill selection start polygon.  
  MDATA_FILLSEL_SELECTION int Fill selection:  
      SELECTION_NEW Starts a new selection.
      SELECTION_ADD Adds to the current selection.
      SELECTION_SUB Subtracts from the current selection.
  MDATA_OUTLINESEL_START_POLY int Outline selection start polygon.  
  MDATA_OUTLINESEL_SELECTION int Outline selection:  
      SELECTION_NEW Starts a new selection.
      SELECTION_ADD Adds to the current selection.
      SELECTION_SUB Subtracts from the current selection.
  MDATA_RESETSYSTEM_COMPENSATE bool Offsets.  
  MDATA_RESETSYSTEM_RECURSIVE bool Reset sub-objects.  
  MDATA_JOIN_MERGE_SELTAGS bool Merge selection tags.  
  MDATA_SETVERTEX_VALUE float Value.  
  MDATA_SETVERTEX_MODE int Mode. (See dialog.)  
MCOMMAND_DELETE Delete.      
MCOMMAND_OPTIMIZE Optimize:      
  MDATA_OPTIMIZE_TOLERANCE float Tolerance.  
  MDATA_OPTIMIZE_POINTS bool Points.  
  MDATA_OPTIMIZE_POLYGONS bool Polygons.  
  MDATA_OPTIMIZE_UNUSEDPOINTS bool Unused points.  
MCOMMAND_DISCONNECT Disconnect:      
  MDATA_DISCONNECT_PRESERVEGROUPS bool Preserve groups.  
MCOMMAND_MAKEEDITABLE Make editable. (Returns object.)      
MCOMMAND_MIRROR Mirror:      
  MDATA_MIRROR_SNAPPOINTS bool Snap to points.  
  MDATA_MIRROR_DUPLICATE bool Duplicate points.  
  MDATA_MIRROR_WELD bool Weld points.  
  MDATA_MIRROR_TOLERANCE float Weld tolerance.  
  MDATA_MIRROR_SYSTEM int Coordinate system. (See dialog.)  
  MDATA_MIRROR_PLANE int Mirror plane. (See dialog.)  
  MDATA_MIRROR_VALUE float Value.  
  MDATA_MIRROR_POINT Vector Mirror point.  
  MDATA_MIRROR_VECTOR Vector Mirror vector.  
  MDATA_MIRROR_SELECTIONS bool Duplicate tag selections.  
  MDATA_MIRROR_ONPLANE bool Symmetric.  
MCOMMAND_SUBDIVIDE Subdivide:      
  MDATA_SUBDIVIDE_HYPER bool Hyper NURBS subdivide.  
  MDATA_SUBDIVIDE_ANGLE float Maximum angle.  
  MDATA_SUBDIVIDE_SPLINESUB int Subdivisions. (Spline.)  
  MDATA_SUBDIVIDE_SUB int Subdivisions. (Polygon.)  
MCOMMAND_EXPLODESEGMENTS Explode segments.      
MCOMMAND_KNIFE Knife. See toolknife.h.      
MCOMMAND_CURRENTSTATETOOBJECT Current state to object: (Returns object.)      
  MDATA_CURRENTSTATETOOBJECT_INHERITANCE bool Use inheritance.  
  MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION bool Keep animation.  
  MDATA_CURRENTSTATETOOBJECT_NOGENERATE bool No generate.  
MCOMMAND_JOIN Join: (Returns object.)      
  MDATA_JOIN_MERGE_SELTAGS bool Merge selection tags.  
MCOMMAND_CONVERTSELECTION Convert selection.      
  MDATA_CONVERTSELECTION_LEFT int Left selection. (See dialog.)  
  MDATA_CONVERTSELECTION_RIGHT int Right selection. (See dialog.)  
  MDATA_CONVERTSELECTION_TOLERANT bool Tolerant conversion.  
  MDATA_CURRENTSTATETOOBJECT_INHERITANCE bool Use inheritance.  
  MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION bool Keep animation.  
  MDATA_CURRENTSTATETOOBJECT_NOGENERATE bool No generate.  
  MDATA_ROTATECAMERA bool Tools/Camera Rotation.  
  MDATA_RING_EDGE int Ring edge.  
  MDATA_RING_SELECTION int Ring selection:  
      SELECTION_NEW Starts a new selection.
      SELECTION_ADD Adds to the current selection.
      SELECTION_SUB Subtracts from the current selection.
  MDATA_RING_SKIP int Ring skip.  
  MDATA_FILLSEL_START_POLY int Fill selection start polygon.  
  MDATA_FILLSEL_SELECTION int Fill selection:  
      SELECTION_NEW Starts a new selection.
      SELECTION_ADD Adds to the current selection.
      SELECTION_SUB Subtracts from the current selection.
  MDATA_OUTLINESEL_START_POLY int Outline selection start polygon.  
  MDATA_OUTLINESEL_SELECTION int Outline selection:  
      SELECTION_NEW Starts a new selection.
      SELECTION_ADD Adds to the current selection.
      SELECTION_SUB Subtracts from the current selection.
  MDATA_RESETSYSTEM_COMPENSATE bool Offsets.  
  MDATA_RESETSYSTEM_RECURSIVE bool Reset sub-objects.  
  MDATA_JOIN_MERGE_SELTAGS bool Merge selection tags.  
  MDATA_SETVERTEX_VALUE float Value.  
  MDATA_SETVERTEX_MODE int Mode. (See dialog.)  
MCOMMAND_EDGE_TO_SPLINE Edge to spline      
MCOMMAND_BREAKPHONG Break phong.      
MCOMMAND_UNBREAKPHONG Unbreak phong.      
MCOMMAND_PHONGTOSELECTION Phong to selection.      
MCOMMAND_MELT Melt.      
MCOMMAND_RESETSYSTEM Reset System:      
  MDATA_RESETSYSTEM_COMPENSATE bool Offsets.  
  MDATA_RESETSYSTEM_RECURSIVE bool Reset sub-objects.  
  • Then there are the modeling library tool IDs, where you have to look up the parameters in the resource files:
ID_MODELING_EDGECUT_TOOL Edge cut tool. See tooledgecut.h.
ID_MODELING_FILL_SELECTION_TOOL Fill selection tool.
ID_MODELING_OUTLINE_SELECTION_TOOL Private.
ID_MODELING_LOOP_TOOL Loop selection tool. See toolloopselection.h.
ID_MODELING_RING_TOOL Ring selection tool.
ID_MODELING_EXTRUDE_TOOL Extrude tool. See toolextrude.h.
ID_MODELING_MATRIX_EXTRUDE_TOOL Matrix extrude tool. See toolmatrixextrude.h.
ID_MODELING_NORMALMOVE_TOOL Normal move tool. See toolnormalmove.h.
ID_MODELING_NORMALSCALE_TOOL Normal scale tool. See toolnormalscale.h.
ID_MODELING_NORMALROTATE_TOOL Normal rotate tool. See toolnormalrotate.h.
ID_MODELING_SMOOTH_SHIFT_TOOL Smooth shift tool. See toolsmoothshift.h.
ID_MODELING_EXTRUDE_INNER_TOOL Extrude inner tool. See toolextrudeinner.h.
ID_MODELING_BEVEL_TOOL Bevel tool. See toolbevel.h.
ID_MODELING_POLYGON_CREATE_TOOL Create polygon tool. See toolcreatepolygon.h.
ID_MODELING_POINT_ADD_TOOL Add point tool. See tooladdpoint.h.
ID_MODELING_BRIDGE_TOOL Bridge tool. See toolbridge.h.
ID_MODELING_WELD_TOOL Weld tool. See toolpointweld.h.
ID_MODELING_CLOSEHOLE_TOOL Close polygon hole tool. See toolclosehold.h.
ID_MODELING_STITCHANDSEW_TOOL Stich and sew tool. See toolstitchandsew.h.
ID_MODELING_SLIDE_TOOL Slide tool. See toolslide.h.
ID_MODELING_IRON_TOOL Iron tool. See tooliron.h.
ID_MODELING_SETVALUE_TOOL Set value tool. See toolsetvalue.h.
ID_MODELING_DUPLICATE_TOOL Duplicate tool. See toolduplicate.h.
ID_MODELING_ARRANGE_TOOL Arrange tool. See toolarrange.h.
ID_MODELING_TRANSFER_TOOL Transfer tool. See tooltransfer.h.
ID_MODELING_RANDOMIZE_TOOL Randomize tool. See toolrandomize.h.
ID_MODELING_CENTER_TOOL Center tool. See toolcenter.h.
ID_MODELING_KNIFE_TOOL Knife tool. See toolknife.h.
ID_MODELING_LIVESELECTION Live selection tool. See toolliveselection.h.
ID_MODELING_RECTSELECTION Rectangle selection tool. See toolrectselection.h.
ID_MODELING_FREESELECTION Free selection tool. See toolfreeselection.h.
ID_MODELING_POLYSELECTION Polygon selection tool. See toolpolyselection.h.
ID_MODELING_MODIFY_TOOL Modify tool. See toolmodify.h.
ID_MEASURE_TOOL Measure tool. See toolmeasure.h.
ID_MODELING_MAGNET_TOOL Magnet tool. See toolmagnet.h.
ID_MODELING_BRUSH_TOOL Brush tool. See toolbrush.h.
ID_MODELING_SPLINE_ROUND_TOOL Spline round tool. See toolsplineround.h.
ID_MODELING_CLONE_TOOL Clone tool. See toolclone.h.
ID_MODELING_SPLINE_CHAMFER_TOOL Spline chamfer tool. See toolsplinechamfer.h.
ID_MODELING_ARRAY_TOOL Array tool. See toolarray.h.
ID_MODELING_SPLINE_PROJECT_TOOL Spline project tool. See toolsplineproject.h.
  • Finally there are the modeling library menu commands. These have no parameters:
ID_MODELING_MELT_COMMAND Melt.
ID_MODELING_EDGE_SPLINE_COMMAND Edge to spline.
ID_MODELING_COLLAPSE_COMMAND Collapse.
ID_NGON_RETRI_MENU Retriangulate N-gons.
ID_NGON_REMOVE_MENU Remove N-gons.
ID_NGON_FORCERETRI_MENU Force N-gon triangulation.
ID_OBJECTHANDLES_ONOFF_MENU Object handles toggle.
ID_SDS_INC_MENU Increment SDS.
ID_SDS_DEC_MENU Decrement SDS.
ID_SDS_ONFFF_MENU Toggle SDS.
ID_MODELING_OM_SELECT_INVERT Invert object manager selection.
ID_MODELING_OM_SELECT_HIDE Hide selected objects.
ID_MODELING_OM_SELECT_SHOW Show selected objects.
ID_MODELING_SHORTCUT_SELECTVISIBLE Toggle select visible.
ID_CAMERA_SET_PIVOT Set the camera pivot.
ID_CAMERA_LOCK_PIVOT Locks/unlocks the camera’s Point of Interest (POI) to the last used POI location.
ID_LASTTOOL_START The first of the last used tools. The next last used tools can be accessed with ID_LASTTOOL_START + (1...6)
ID_LASTTOOL_END The last of the last used tools.

Table Of Contents