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.NodeData – a superclass for instancable plugins

The super class for instancable plugins. Just subclasses can be registered. To get more information, you should download the official C++ Documentation of CINEMA 4D and open the page “Resource files”.

class c4d.plugins.NodeData

SuperClass

BaseData

Methods

NodeData.InitAttr(host, type, desc)

If you use a resource file (.res) to add custom editable attributes to your object you have to initialize them with this method, otherwise you cant access this elements properly, even they are already defined in your resource file. Just call them in the init(self, op) method of your NodeData:

import c4d
from c4d import symbols as sy

def Init(self, op):
    #please note, the desc element has to be a constant (id of your container element)
    self.InitAttr(host=op, type=float, desc=[sy.TUBEOBJECT_RAD]) #init element TUBEOBJECT_RAD
    self.InitAttr(host=op, type=float, desc=[sy.TUBEOBJECT_IRADX])

    op[TUBEOBJECT_RAD]= 200.0 #assign value
    op[TUBEOBJECT_IRADX] = 50.0 #assign value
Parameters:
  • host (BaseObject) – The host object.
  • type (type) – Just pass the type like float, int, PriorityData...
  • desc (list) – The element container id you want to initialize. Normally you just have to copy the op[...] stuff. Check out the example above.

NodeData Management

Note

The following text contain two different class names: BaseTag and TagData. These classes can easily be mixed up, but they are not derived from each other. So we are talking about two different classes. So please pay attention when you read the following chapter.

In this chapter we are going to understand the internal management of CINEMA 4D and registered plugins. Imagine you wrote a simple Tag Plugin. So you create your own class, derived from the class TagData and register it on startup with the corresponding register method:

import c4d
from c4d import plugins

PLUGIN_ID = 1234567890

class TestTag(plugins.TagData):

    def Execute(self, tag, doc, op, bt, priority, flags):
        #do your stuff here
        return plugins.EXECUTION_OK

if __name__ == "__main__":
    print plugins.RegisterTagPlugin(id=PLUGIN_ID, str="TestTag", g=Calva,
                                    description="testtag", icon=None,
                                    info=plugins.TAG_MULTIPLE|plugins.TAG_EXPRESSION|plugins.TAG_VISIBLE)

In the following example the user selects your tag plugin in the context menu of an object in the Object Manager where he wants to attach a new tag on. The user gets a tag which is attached to the according object in the object manager. But here is something which might make be confused. The tag which is attached to the object is of type BaseTag and not as expected of your type TestTag (see example above).

Where is the instance of your class? Your object is not visible in the document. The BaseTag is a controller(handles input and output) and internally established with an instance of your class TestTag. Established means, that the BaseTag has an internal reference to TestTag and just redirects all messages and notifications to this instance. It also contains the description attributes which are visible in the Attribute-Manager in CINEMA 4D.

When the user changes something, the BaseTag instance will be cloned, and the new instance get the new values. The old BaseTag will be pushed onto the Undo stack.

../../../../_images/association.png

Just remember that the BaseTag instance is the corresponding tag in the document. It will be passed to the overwritten methods so you can read the current settings which will be required by your calculation your plugin is made for.

See also

Pattern Presentation-Abstraction-Control:
Similar Design Pattern.

Table Of Contents

This Page