c4d.plugins.ObjectData

An object plugin class. Register this class with RegisterObjectData().

Note

Before you start writing your own ObjectData plugin, you should read NodeData Management before.

Optimize Cache

On each call of a method of your class (Python), Python has to manage a lot of stuff so that the method can be called. The method GetVirtualObjects() is called on each frame and if you do not want to calculate the object on each frame again and again you can still return the cache object with the following code:

def GetVirtualObjects(self, op, hierarchyhelp):

    dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
    if dirty is False: return op.GetCache(hierarchyhelp)

This is the common way how to return the cache object so Python do not has to built the whole object on each frame. That saves a lot of time. But how you can read some lines before, just calling the method needs some time, because Python has to register this call to the internal management system.

So there is a new second way how to return the cache of your already-built object on a level which is much closer to the internal system than Python. You can set a flag in your class which is checked after the constructor of your object was read. The code you see above is called and if there is a cache available the Python method is not called anymore because the cache is already taken. That saves a lot of time. To use this code you should take a look at the following class:

class CacheTest(plugins.ObjectData):
    """CacheTest Generator"""

    def __init__(self):
        self.SetOptimizeCache(True)

    def GetVirtualObjects(self, op, hierarchyhelp):

        #disabled the following lines because cache flag was set
        #so the cache build is done before this method is called
        #dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
        #if dirty is False: return op.GetCache(hierarchyhelp)

        #create cube
        return c4d.BaseObject(c4d.Ocube)

Inheritance

Members

ObjectData.GetDimension(self, op, mp, rad)

Override - Return the boundaries of your object.:

def GetDimension(self, op, mp, rad):
    """
    (i) When the method runs without a raised exception
    mp and rad will be internally copied, otherwise they
    are ignored.
    """

    mp.x = self.x_size   # correct
    mp.y = self.y_size   # correct
    mp.z = self.z_size   # correct

    mp = c4d.Vector(x_size, y_size, z_size)    #!!! wrong !!! do not rebind mp!
    #this assign applies for 'rad' as well
    return
Parameters:
  • op (BaseObject) – The established base object.
  • mp (Vector) – Assign the center point of the bounding box to this vector.
  • rad (Vector) – Assign the XYZ bounding box radius to this vector.
ObjectData.Draw(self, op, drawpass, bd, bh)

Override - Called when the display is updated for you to display some visual element of your op in the 3D view.

Note

This function is called in a thread context. Please see the important information about threading.

Parameters:
  • op (BaseObject) – The established base object.
  • drawpass (int) –

    One of the following flags:

    DRAWPASS_OBJECT Object pass.
    DRAWPASS_BOX Box pass.
    DRAWPASS_HANDLES Handle pass.
    DRAWPASS_HIGHLIGHTS Highlights pass.
    DRAWPASS_XRAY X-Ray pass.

    Warning

    Only draw in DRAWPASS_HIGHLIGHTS if you really know what you are doing. Otherwise always check the drawpass and then do not draw if it is DRAWPASS_HIGHLIGHTS.

    Here is an example:

    def Draw(self, data, drawpass, bd, bh):
    
        if drawpass==c4d.DRAWPASS_HIGHLIGHTS:
            return c4d.DRAWRESULT_SKIP
    
        # Put here your drawing operations
    
        return c4d.DRAWRESULT_OK
    

    Warning

    Only draw the object in one pass : DRAWPASS_OBJECT. The object‘s appearance may change if you draw the same object in multiple passes.

  • bd (BaseDraw) – The editor’s view.
  • bh (BaseDrawHelp) – The BaseDrawHelp editor’s view.
Return type:

int

Returns:

Success of drawing into the editor view:

DRAWRESULT_OK

You have drawn anything.

DRAWRESULT_ERROR

There was an error while drawing.

DRAWRESULT_SKIP

There was nothing to draw in this pass.

ObjectData.DrawShadow(self, op, bd, bh)

New in version R14.014.

Called during the shadow pass instead of the Draw() method.

Parameters:
Return type:

int

Returns:

Success of drawing into the editor view:

DRAWRESULT_OK

You have drawn anything.

DRAWRESULT_ERROR

There was an error while drawing.

DRAWRESULT_SKIP

There was nothing to draw in this pass.

ObjectData.GetVirtualObjects(self, op, hh)

Override - Return an object chain of a generator object (in your case e.g. a polygonal object). Must not be overridden for non-generator objects.

Note

The building, adding, comparing and touching must be always done - even if there has been no change! The reason is that CINEMA 4D must always know which objects are affected by the generator.

Note

This function is called in a thread context. Please see the important information about threading.

Note

Please read the introduction at the top of this page to get in touch with the new caching options.

Parameters:op (BaseObject) – The established base object.
Return type:BaseObject or None
Returns:The newly allocated object or None if an error occured.
ObjectData.GetContour(self, op, doc, lod, bt)

Override - Return a spline contour. For spline objects only.

Note

This function is called in a thread context. Please see the important information about threading.

Note

Splines created through GetContour() are cached. To make this frame dependent, CheckDirty() can be overloaded to set the object dirty if a certain condition has changed.

Parameters:
  • op (BaseObject) – The established base object.
  • doc (BaseDocument) – The document containing the plugin object.
  • lod (int) – The level of detail.
  • bt (None:) – Currently not used.
Return type:

SplineObject or None

Returns:

The newly allocated spline or None

ObjectData.ModifyObject(self, mod, doc, op, op_mg, mod_mg, lod, flags, thread)

Override - Only necessary for deformation objects. This is called when your plugin should modify the passed object.

Note

This function is called in a thread context. Please see the important information about threading.

Parameters:
  • mod (BaseObject) – The modifier object’s.
  • doc (BaseDocument) – The document containing the plugin object.
  • op (BaseObject) – The object to modify.
  • op_mg (Matrix) – The object’s world matrix.
  • mod_mg (Matrix) – The modifier object’s world matrix.
  • lod (float) – The level of detail.
  • flags (int) – Currently unused, this is for future expansion.
  • thread (None:) – Currently unused, this is for future expansion.
Return type:

bool

Returns:

Success of modifying the object.

ObjectData.CheckDirty(self, op, doc)

Override - You can override this function to check for a change in the object manually. This example will make your object update every frame:

def CheckDirty(self, op, doc):

    frame = doc.GetTime().GetFrame(doc.GetFps())
    if frame != lastFrame:
        lastFrame = frame
        op.SetDirty(c4d.DIRTYFLAGS_DATA)

This method is useful to override in deformer and spline plugins.

Note

This function is called in a thread context. Please see the important information about threading.

Parameters:
  • op (BaseObject) – The established base object.
  • doc (BaseDocument) – The document containing the plugin object.
ObjectData.MoveHandle(self, op, undo, mouse_pos, hit_id, qualifier, bd)

Override - Move a handle manually.

Parameters:
  • op (BaseObject) – The established base object.
  • undo (BaseObject) – This is a copy of the object that must not be modified during the move handle.
  • mouse_pos (Vector) – The current mouse position.
  • hit_id (int) – The handle ID returned from DetectHandle()
  • qualifier (int) –

    Any qualifier keys that were pressed. These are defined in c4d.gui:

    QUALIFIER_SHIFT Shift
    QUALIFIER_CTRL Ctrl
    QUALIFIER_MOUSEHIT Indication in DetectHandle() that the user pressed the mouse (DetectHandle() is also called for cursor information, when hovering over a handle). E.g. if mousehit and ctrl is set, DetectHandle() could create a new element.
  • bd (BaseDraw) – The editor’s view.
Return type:

bool

Returns:

Success of modifying the handle.

ObjectData.DetectHandle(self, op, bd, x, y, qualifier)

Override - Manually detect a click on a handle.

Parameters:
  • op (BaseObject) – The established base object.
  • bd (BaseDraw) – The editor’s view.
  • x (int) – The mouse X coordinate.
  • y (int) – The mouse Y coordinate.
  • qualifier (int) –

    Any qualifier keys that were pressed. These are defined in c4d.gui:

    QUALIFIER_SHIFT Shift
    QUALIFIER_CTRL Ctrl
    QUALIFIER_MOUSEHIT Indication in DetectHandle() that the user pressed the mouse (DetectHandle() is also called for cursor information, when hovering over a handle). E.g. if mousehit and ctrl is set, DetectHandle() could create a new element.
Return type:

int

Returns:

The handle ID that is to be passed to MoveHandle()

ObjectData.AddToExecution(self, op, list)

Override - By default this function returns False. Then C4D will call Execute() at the priority specified by the user in the EXPRESSION_PRIORITY parameter of the container.

If you override this function and return True, then you can insert your own points of execution in the list by calling for example:

list.Add(op, c4d.EXECUTIONPRIORITY_ANIMATION, 0)
list.Add(op, c4d.EXECUTIONPRIORITY_GENERATOR, 0)
Parameters:
  • op (BaseObject) – The established base object.
  • list (PriorityList) – The priority list to add your object’s execution points to.
Return type:

bool

Returns:

True if you override this function and has added stuff to list.

ObjectData.Execute(self, op, doc, bt, priority, flags)

Override - Called at the point in the priority pipeline specified by AddToExecution(), or the lack thereof.

Note

This function is called in a thread context. Please see the important information about threading.

Parameters:
  • op (BaseObject) – The established base object.
  • doc (BaseDocument) – The host document of the object.
  • bt – Currently not used.
  • priority (int) –

    The priority of this call to Execute() in the pipeline. Standard values are:

    EXECUTIONPRIORITY_INITIAL Initial.
    EXECUTIONPRIORITY_ANIMATION Animation.
    EXECUTIONPRIORITY_ANIMATION_NLA NLA.
    EXECUTIONPRIORITY_EXPRESSION Expression.
    EXECUTIONPRIORITY_DYNAMICS Dynamics (R11.5).
    EXECUTIONPRIORITY_GENERATOR Generators.
  • flags (int) –

    A combination of the following flags:

    EXECUTIONFLAGS_0 None.
    EXECUTIONFLAGS_ANIMATION Animation is calculated.
    EXECUTIONFLAGS_EXPRESSION Expressions are calculated.
    EXECUTIONFLAGS_CACHEBUILDING Cache building is done.
    EXECUTIONFLAGS_CAMERAONLY Only camera dependent expressions shall be executed.
    EXECUTIONFLAGS_INDRAG Pipeline is done within scrubbing.
    EXECUTIONFLAGS_INMOVE Pipeline is done within moving.
    EXECUTIONFLAGS_RENDER The external renderer (picture viewer) is running.
Return type:

int

Returns:

The result:

EXECUTIONRESULT_OK

OK.

EXECUTIONRESULT_USERBREAK

User break.

EXECUTIONRESULT_MEMORYERROR

Memory error.

ObjectData.ModifyParticles(self, op, pp, ss, pcnt, diff)

Override - Called for modifying particles. This is for particle modifiers only.

Note

This function is called in a thread context. Please see the important information about threading.

Parameters:
  • op (BaseObject) – The established base object.
  • pp (list of Particle) –

    The initial element of the Particle list.

    Note

    This list is used to read the particles information only, the particles should not be modified.

  • ss (list of BaseParticle) – The initial element of the BaseParticle list. Modify the elements in this list to change the velocity of the particle.
  • pcnt (int) – The number of particles in the Particle and BaseParticle list.
  • diff (float) – The time delta for the particles movement in seconds. Usually the difference in time between two frames, but this can be different for such functions as motion blur.

Table Of Contents