Describes implementing special port types and node commands for a user node.
A port bundle is a port composed of multiple child ports that realize a data structure. This parent port bundle can be connected to other bundles without having to connect every nested port one by one. But nested ports can still be used and connected individually. For example, a spline object is composed of one or several vertices, but the user will only connect the spline port to another spline port without having to connect each point one by one. A port bundle is created using the resource editor in two steps. The first is to create the port bundle itself. The second step is to create a user node and insert the port bundle. To create a port bundle with two ports, follow the steps as listed out below.
net.maxonexample.handbook.portbundle.colorandfloat
.net.maxon.object.base
with the check-boxes Data, UI and String checked. Update the information of the node using the buttons < or > to move to another element and come back.Color Bundle
.color
with the check-boxes Data, UI and String checked. Define the datatype as color and set the string to Color
. Define the Gui Type ID to net.maxon.ui.coloralpha.power
with the check-boxes Data, UI and String checked. Define the datatype as float and the string to Power
. Define the Gui Type ID to net.maxon.ui.number.Now the port bundle has been created, insert it into a user node.
net.maxsonexample.handbook.noderenderer.nodewithbundle
.net.maxon.node.base
. Update the information of the node using the button < or > to move to another element and come back.net.maxonexample.handbook.portbundle.colorandfloat
must be entered.Variadic ports are ports which can be added at runtime by the user. This can happen in the context of a port bundle, where then the number of ports attached to the bundle can change, and in the context of true nodes, where new ports can be attached to the true node at runtime. An example for variadic ports can be found in the ports for the Gradient datatype, where each gradient knot is exposed as a variadic port in the port bundle of the Gradient port. In the resource editor, a variadic port is a regular port that is declared as variadic. An additional field is created to store the number of ports that must be created. Also, two functions must be defined as an action to add or remove a sub-port. The usage of variadic ports in conjunction with micronodes is documented in the function AddVariadicPort.
Creating a variadic port is done with the resource editor. Be sure to start Cinema 4D with the correct option, see Implementing Custom Node Spaces.
net.maxonexample.handbook.noderenderer.nodewithvariadic
.net.maxon.node.base
with the check-boxes Data, UI and String checked. Update the information of the node using the button < or > to move to another element and come back.Node With Variadic Port
.handbook.variadic.color
and its data type to Color. Set the classification to Input. Because only input ports can be variadic. On the string tab, define the string of that attribute as Color
.addvariadicport
and in the second removevariadicport
.Add a Color
, select removevariadicport and define the string to Remove a Color
.The user node is now available with two buttons to add or remove a color port.
Nodes can have node commands associated with them. A node command provides a specific functionality for their associated node which can be executed on demand, as for example a button that must be pressed to initialize a node or to execute a custom function. Commands can be represented as buttons, but they can also be represented as menus. When the button is pressed, it will call a message to attempt to retrieve the delegate function which has been registered for that message, and execute that delegate. This message must be registered when Cinema 4D is being launched, by invoking the function RegisterMessage within the initialization macro MAXON_INITIALIZATION.
net.maxonexample.handbook.nodewithcommand
.net.maxon.node.base
. with the check-boxes Data, UI and String checked. Update the information of the node using the button < or > to move to another element and come back.buttoncommand
.Now that the user node is defined, the function that will be used as the delegate must be created. To register the message, two command must be defined. One will be used to check if the command is enabled or not, the other will be executed when the button is pressed.
The last thing to do is to register the message. A DescriptionMessageFunction must be created to store the function that will be called.
Parameters can be displayed or not based on a condition. This is convenient to hide some descriptions when the end user does not need to see them.
A boolean attribute can be created that has its identifier defined as showbutton
and Show the button
as string. Now a button attribute can be created, and its field show condition defined to the id of the parameter that will act as the condition. Once the id showbutton
is entered, it will be replaced by the string of the parameter with brackets like so {Show the button}. Now, the button will be hidden by default unless the checkbox is checked.