The base type for instantiable plugins. Use RegisterNodePlugin() to register the plugin.
If you use a resource file (.res) to add custom editable attributes to your object you can initialize them with this method. Just call this method in the Init() method of your node data class:
import c4d
def Init(self, node):
#please note, the desc element has to be a constant (id of your container element)
self.InitAttr(host=node, type=float, desc=[c4d.PY_TUBEOBJECT_RAD])
self.InitAttr(host=node, type=float, desc=[c4d.PY_TUBEOBJECT_IRADX])
node[c4d.PY_TUBEOBJECT_RAD]= 200.0
node[c4d.PY_TUBEOBJECT_IRADX] = 50.0
Parameters: |
|
---|
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 node link established.
Parameters: | node (GeListNode) – The list node connected with this instance. |
---|---|
Return type: | bool |
Returns: |
True on success, otherwise False.
Warning Please note, if you return False, the object will not be created. |
Override - If your class has a destructor it is called as usual after this function.
Parameters: | node (GeListNode) – The list node connected with this instance. |
---|
New in version R13.016.
Override - Called when a node is loaded from a file. Use this function to read any settings for your plugin that are not stored in the BaseContainer. You must read these settings from the HyperFile such as:
hf.ReadLong(offset)
hf.ReadBool(object_access)
For future extensions of your plugin you should check the level and only read the appropriate values:
if level >= 0:
hf.ReadLong(offset)
hf.ReadBool(object_access)
if level >= 1:
hf->ReadReal(a_new_feature)
Init() will have already been called before this function is called.
Note
It is recommended to store as much as possible in the BaseContainer as CINEMA 4D will handle the reading of those values automatically. Only use member variables when necessary.
Important
If you implement at least one of Read(), Write() and CopyTo(), you must usually implement all three. Otherwise data might be lost.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the data was read successfully, otherwise False. |
New in version R13.016.
Override - Called when a node is saved to a file. Use this function to write any settings for your plugin that are not stored in the BaseContainer. You must read these settings from the HyperFile such as:
hf.WriteLong(offset)
hf.WriteBool(object_access)
For future extensions of your plugin you should make sure to introduce a new level (See Read()) when writing new values:
// Level 0
hf.WriteLong(offset)
hf.WriteBool(object_access)
// Level 1
hf.WriteReal(a_new_feature)
Free() will be called after this function is called.
Note
It is recommended to store as much as possible in the BaseContainer as CINEMA 4D will handle the writing of those values automatically. Only use member variables when necessary.
Important
If you implement at least one of Read(), Write() and CopyTo(), you must usually implement all three. Otherwise data might be lost.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the data was written successfully, otherwise False. |
New in version R13.016.
Override - Called when a node is duplicated. Use this function to copy any settings for your plugin that are not stored in the BaseContainer. Simply transfer them from this to dest and/or snode to dnode:
dest.offset = offset
dest.object_access = object_access
Init() will have already been called for the destination node before this function is called.
Note
It is recommended to store as much as possible in the BaseContainer as CINEMA 4D will handle the copying of those values automatically. Only use member variables when necessary.
Important
If you implement at least one of Read(), Write() and CopyTo(), you must usually implement all three. Otherwise data might be lost.
Parameters: |
|
||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||||||||||||||
Returns: |
True if the data was copied successfully, otherwise False. |
New in version R13.016.
Parameters: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: |
Depends on the message type. |
New in version R13.029.
If you create your own BaseList elements this allows you to tell C4D how to retrieve the document. Any call to GeListNode.GetDocument() ends up here.
Note
Standard nodes like objects, tags etc. don’t need to override this function. Only if you create elements that are allocated with AllocListNode(), AllocSmallListNode() and AllocMultiNode() do need this function.
Parameters: | node (GeListNode) – The list node connected with this instance. |
---|---|
Return type: | BaseDocument |
Returns: | The document. |
New in version R13.029.
Called to know if the node is an instance of the given base type.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the node is an instance of the given type, otherwise False. |
New in version R13.029.
Called to let you decide which parameters should be enabled or disabled (ghosted). This can be used both for parameters that are stored in the node’s container and for custom parameters.
Just read the passed t_data if the right id was provided, and return True to enable the parameter or False to disable it depending on the value. Then make sure to include a call to the parent at the end:
return NodeData.GetDEnabling(node, id, t_data, flags, itemdesc)
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the parameter should be enabled, otherwise False. Note It is recommended that you include a call to the base class method as your last return. |
In the following chapter we are going to understand some internal things of CINEMA 4D. Normally you don’t need to care about this, but sometimes it’s very effective for debugging to dive into the deep to understand how things work.
Imagine you are writing your own tag plugin. To do this you write a class derived from TagData and register it with the corresponding function:
import c4d
from c4d import plugins
PLUGIN_ID = 1234567890
class LookAtCameraData(plugins.TagData):
def Execute(self, tag, doc, op, bt, priority, flags):
#...
return c4d.EXECUTIONRESULT_OK
if __name__ == "__main__":
plugins.RegisterTagPlugin(id=PLUGIN_ID, str="Look At Camera", g=LookAtCameraData,
description="pylookatcamera", icon=None,
info=c4d.TAG_MULTIPLE|c4d.TAG_EXPRESSION|c4d.TAG_VISIBLE)
Now you can create an instance of your tag in CINEMA 4D. What you now see is a little icon, which represents a new instance of type BaseTag. You might wonder why you get an object of this type, and not as expected of LookAtCameraData.
To clarify this, we need to understand the steps what CINEMA 4D does, when you create this tag.
First a new instance of BaseTag is created along with an instance of your type LookAtCameraData. The base tag is stored in the document and works like a controller with settings for the instance of LookAtCameraData. The instance of LookAtCameraData itself is invisible for the user.
When you take a look at the second argument of TagData.Execute() which is of type BaseTag. This object contains all the parameters which are set by the user in the document. When the user now changes a parameter, the current established BaseTag is put onto the undo stack and replaced by a new base tag which gets the new settings. The next time TagData.Execute() of this instance is executed, it gets the new parameter.
This concept works for all node data plugins (ObjectData, SceneSaverData, ...)
See also