c4d.plugins.NodeData
¶
The base type for instantiable plugins. Use
RegisterNodePlugin()
to register the plugin.
c4d.plugins.
NodeData
¶
NodeData.GetDocument()
NodeData.IsInstanceOf()
NodeData.IsDocumentRelated()
NodeData.GetBubbleHelp()
NodeData.GetDDescription()
NodeData.GetDParameter()
NodeData.SetDParameter()
NodeData.GetDEnabling()
NodeData.TranslateDescID()
NodeData.
InitAttr
(
host
,
type
,
id
)
¶
Initializes an object’s description parameter at id with its default value for the data type .
Just call this method in the
Init()
method of any node data class:
import c4d def Init(self, node): self.InitAttr(op, float, [c4d.PY_TUBEOBJECT_RAD]) self.InitAttr(op, float, [c4d.PY_TUBEOBJECT_IRADX]) node[c4d.PY_TUBEOBJECT_RAD]= 200.0 node[c4d.PY_TUBEOBJECT_IRADX] = 50.0
See also
The Py-RoundedTube example and its Init() method.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the parameter could be successfully initialized, otherwise False . |
NodeData.
Init
(
self
,
node
)
¶
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 ( c4d.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. |
NodeData.
Free
(
self
,
node
)
¶
Override - If your class has a destructor it is called as usual after this function.
Parameters: | node ( c4d.GeListNode ) – The list node connected with this instance. |
---|
NodeData.
Read
(
self
,
node
,
hf
,
level
)
¶
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.ReadInt32(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.ReadInt32(offset) hf.ReadBool(object_access) if level >= 1: hf->ReadFloat(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 . |
NodeData.
Write
(
self
,
node
,
hf
)
¶
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.WriteInt32(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.WriteInt32(offset) hf.WriteBool(object_access) // Level 1 hf.WriteFloat(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 . |
NodeData.
CopyTo
(
self
,
dest
,
snode
,
dnode
,
flags
,
trn
)
¶
Init()
is called for the destination node before this function.
Use this function to copy any settings for the plugin that are not stored in the
BaseContainer
. Simply transfer them from the current node data to
dest
and/or
snode
to
dnode
:
dest.offset = offset dest.object_access = object_access
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 at least one of
Read()
,
Write()
and
CopyTo()
is implemented, it is recommended to implement all three, otherwise data might be lost.
Parameters: |
|
||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||||||||||||||
Returns: |
True if the data was copied successfully, otherwise False . |
NodeData.
Message
(
self
,
node
,
type
,
data
)
¶
Override - Called when a node receives messages.
Parameters: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: |
Depends on the message type. |
NodeData.
GetDocument
(
self
,
node
)
¶
If you create your own BaseList elements this allows you to tell Cinema 4D how to retrieve the document. Any call to
GeListNode.GetDocument()
ends up here.
Note
Standard nodes like objects, tags etc. do not need to override this function. Only if you create elements that are allocated with AllocListNode(), AllocSmallListNode() and AllocMultiNode() do need this function.
Parameters: | node ( c4d.GeListNode ) – The list node connected with this instance. |
---|---|
Return type: | c4d.documents.BaseDocument |
Returns: | The document. |
NodeData.
IsInstanceOf
(
self
,
node
,
type
)
¶
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 . |
NodeData.
IsDocumentRelated
(
self
,
node
)
¶
New in version R18.011.
Called by the Attribute Manager for correct undo handling.
Warning
Should not be overloaded by regular plugins and should be used with extra care. If False is returned no undo is possible.
Parameters: | node ( c4d.GeListNode ) – The list node connected with this instance. |
---|---|
Return type: | bool |
Returns: | True if the node is part of the document, otherwise False . |
NodeData.
GetBubbleHelp
(
self
,
node
)
¶
New in version R18.011.
Called to create a contextual bubble help and status bar information for the node.
Note
When dealing with strings it is advised to use the string resources files and the
GeLoadString()
function. This keeps the plugin easy to localize for any language to support and makes full use of the language features of Cinema 4D.
Parameters: | node ( c4d.GeListNode ) – The list node connected with this instance. |
---|---|
Return type: | str |
Returns: | The bubble help string. |
NodeData.
GetDDescription
(
self
,
node
,
description
,
flags
)
¶
New in version R18.011.
Called to add parameters to the description for the node. Modify the passed description as needed and return the appropriate flags.
Note
If only a description resource is used it is not needed to overload
GetDDescription()
.
For instance, here is how
GetDDescription()
can be implemented:
def GetDDescription(self, node, description, flags): # Before adding dynamic parameters, load the parameters from the description resource if not description.LoadDescription(node.GetType()): return False # Get description single ID singleID = description.GetSingleDescID() # Check if dynamic parameter with ID paramID has to be added paramID = ... if singleID is None or paramID.IsPartOf(singleID)[0]: # Add dynamic parameter if not description.SetParameter(paramID, ...): return False ... # After parameters have been loaded and added successfully, return True and DESCFLAGS_DESC_LOADED with the input flags return (True, flags | c4d.DESCFLAGS_DESC_LOADED)
See also
c4d.Description
and
DescID.IsPartOf()
Parameters: |
|
||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool or tuple(bool, int) |
||||||||||||||
Returns: |
One of these options: bool: True if successful, otherwise False . Useful in error state to only return False . tuple(bool, int): The status ( True if successful, otherwise False ) and description flags ( DESCFLAGS_DESC ). |
NodeData.
GetDParameter
(
self
,
node
,
id
,
flags
)
¶
New in version R18.011.
Called to override the reading of description parameters. Necessary for parameters that are not simply stored in the node’s container e.g. class members. Return the parameter data and the appropriate flags if the right id is provided.Note
If only a description resource is used it is not needed to overload
GetDParameter()
.
Parameters: |
|
||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool or tuple(bool, any, int) |
||||||||||||||
Returns: |
One of these options: bool: True if successful, otherwise False . Useful in error state to only return False . tuple(bool, any, int): The status ( True if successful, otherwise False ), parameter data and description flags ( DESCFLAGS_DESC ). |
NodeData.
SetDParameter
(
self
,
node
,
id
,
t_data
,
flags
)
¶
New in version R18.011.
Called to override the writing of parameters. Read the passed t_data if the right id is provided, store the data and return the appropriate flags.
Note
If only a description resource is used it is not needed to overload
SetDParameter()
.
Parameters: |
|
||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool or tuple(bool, int) |
||||||||||||||
Returns: |
One of these options: bool: True if successful, otherwise False . Useful in error state to only return False . tuple(bool, int): The status ( True if successful, otherwise False ) and description flags ( DESCFLAGS_DESC ). |
NodeData.
GetDEnabling
(
self
,
node
,
id
,
t_data
,
flags
,
itemdesc
)
¶
Called to let 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.
And if the passed id element is not processed, include a call to the base class method as last return:
return NodeData.GetDEnabling(self, node, id, t_data, flags, itemdesc)
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the parameter should be enabled, otherwise False . Note It is recommended to include a call to the base class method as last return. |
NodeData.
TranslateDescID
(
self
,
node
,
id
)
¶
New in version R18.011.
Called by the Attribute Manager for every object and every description ID. Gives a NodeData plugin the opportunity to route a description ID in the description of a node to another one. For example used for tags that are embedded in an object description so that the keyframer for a tag property creates the track on the tag and not on the object.Parameters: |
|
---|---|
Return type: | |
Returns: |
One of these options: bool: True if successful, otherwise False . Useful in error state to only return False . tuple(bool,
DescID
,
C4DAtom
): The status (
True
if successful, otherwise
False
), target description ID and object.
|
In the following chapter we are going to understand some internal things of Cinema 4D. Normally you do not need to care about this, but sometimes it is 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
, …)