This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.plugins.ObjectData

An object plugin class. Register this class with RegisterObjectData.

Note

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

Optimize Cache

On each call of a method of your class (Python), Py4D has to manage a lot of stuff so that the method can be called. The method get_virtual_object() is called on each frame and if you don’t 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 don’t 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 Py4D 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"""

    _optimize_cache = True # the optional cache flag

    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)
class c4d.plugins.ObjectData

// Methods to override

// Generator

// Modifier

// Spline

// Helper routines

SuperClass

NodeData

Methods

ObjectData.Init(self, op)

Override - Called when a new instance of the node plugin has been allocated.

Note

If your class has a constructor it is called as usual before this function, but at that time there’s no object link established.

Parameter:op (BaseObject) –

The object which is established with this instance.

Warning

Please note, if you return False, the object will not be created.

Return type:bool
Returns:True on success, otherwise False.
ObjectData.Message(self, op, type, data)

Override - Called each time the user chooses another tool.

Parameters:
  • op (BaseObject) – The object which is established with this instance.
  • type (int) – The message ID.
  • data (any) – The message data.
Return type:

bool

Returns:

True on success, otherwise False.

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

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

Parameters:
  • op – The object which is established with this instance.
  • op (BaseObject) –

    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
  • bd (BaseDraw) – The editor’s view.
  • bh (dict) – Private - hierarchy helper
Return type:

bool

Returns:

Success of drawing into the editor view.

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

Override - Return the boundaries of your object.:

def GetDimension(self, op, mp, rad):
    """ 'mp' and 'rad' are no real references to the original
    Vectors, but if the method works fine and no exception is thrown
    the changes will be transfered after the method is done."""

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

    mp = c4d.Vector(x_size, y_size, z_size)    #!!! wrong !!! do not overwrite the original reference
    #this assign applies for 'rad' as well
    return
Parameters:
  • op (BaseObject) – The established BaseObject.
  • 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.Free(self, op)

Override - If your class has a destructor it is called as usual after this function.

Parameter:op (BaseObject) – The object which is established with this instance.
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

Important: 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. This function is called in a thread context. Please see the important information about threading.

Note

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

Parameter:op (BaseObject) – The established BaseObject.
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

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

Parameters:
  • op (BaseObject) – The established BaseObject.
  • 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)

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

Note

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

Parameters:
  • mod – The established BaseObject.
  • doc (BaseDocument) – The document containing the plugin object.
  • mod (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.
ObjectData.CheckDirty(self, op, doc)

You can override this function to check for a change in a deformer object manually.

Note

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

Parameters:
  • mod (BaseObject) – The established BaseObject.
  • doc (BaseDocument) – The document containing the plugin object.
ObjectData.MoveHandle(self, op, undo, tm, hitid, qualifier)

Override - Move a handle manually.

Parameters:
  • op (BaseObject) – The established BaseObject.
  • undo (BaseObject) – This is a copy of the object that must not be modified during the move handle.
  • tm (Matrix) – The amount the handle has been moved by the user.
  • hitid (int) – The handle ID returned from detect_handle
  • 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:

bool

Returns:

Success of modifying the handle.

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

Override - Move a handle manually.

Parameters:
  • op (BaseObject) – The established BaseObject.
  • 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 move_handle

Table Of Contents

This Page