Using a Classic API UI in the Node Editor

Describes how to reuse custom user interface created with the classic API in the Node Editor. User interfaces allow the user to define or change the value of attributes. Cinema 4D can display descriptions that use data types created with the Classic API while the node core deals with Maxon API data types. To use those data types and descriptions in the node editor, those data types must be converted from the type GeData to the type Data and vice-versa. That means the data types must exist in both the Maxon API and the Classic API. For both API to communicate, a conversion must be implemented. This is done by implementing an interface that inherits from UiConversionInterface with just a couple of functions. Those functions define what are the data types supported and how the conversion is done in both directions. An example can be found in the sdk.zip provided with Cinema 4D. This example shows how to use the "Dots Data" custom UI example in the node editor.

Defining What DataType Is Compatible With the UI

The function QuerySupportedDataTypes must be overridden to define what data types the implementation can handle. To do that, the BaseArray passed to this function must be filled with the data types that are supported. This array will also be used to define the list of UI that can be used to handle an attribute of this kind of data type.

Converting Data From Core to Classic

While the Maxon API uses the type Data to store any kind of data types, the Classic API uses the type GeData. Nodes are functions that take data as inputs, process them and provide the result of this processing.

To create a user interface that can be used in the node editor:

  • data must be converted from the type GeData to the type Data,
  • the micro node will process the data and make the result available, and
  • this result will be converted back to the type GeData that can be displayed as the result of the node.

The interface has two functions that must be overridden, ConvertToCore and ConvertToC4D. Both functions must be fully functional otherwise some data will be lost. For example, the data can be stored inside a BaseContainer in the Classic API while it is stored as a BaseArray in the Maxon API. In case of complex data, the data can be copied or reconstructed. Keep in mind, to increase speed, that data can be moved to avoid copying.

In the function ConvertToCore, data is converted from the type GeData to the type Data. In the function ConvertToC4D, data must be converted from the type Data to the type GeData.

Create the Description for the Attribute

To display the value of an attribute, a description must be created. This description will display Classic API gadgets inside the Node editor that use the Maxon API description system. Just like in the Classic API, some parameters must be defined using a BaseContainer, for example, the name of the gadget or the custom UI that will be used. In conjunction with that, the description system used by the Maxon API must be used to define the place where the gadget must be inserted in the UI. This is done inside the function CreateC4DDescription. The function has many parameters to retrieve the information about the description for both systems, DescID, InternID, DescTranslation.

Create the User Node

Now that the conversion interface has been defined, the Resource Editor must be used to create the User Node that will be instantiated in the Node Editor.

Once the Resource Editor is opened inside Cinema 4D:

  • In the database for the plugin, invoke Data Type -> Add Data Type to add a new data type and define its name as: net.maxonexample.handbook.customgui.dotdata.
  • Add a new attribute and include net.maxon.object.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.
  • On the attribute list, select net.maxon.object.base.name that should have an icon with an exclamation mark and define the string to Dot Data Example.
  • Deselect any attribute on the attribute list and define the classification of the Data Type as node.
  • Add a new attribute and define its DataType by clicking the button v on the right of the DataType field and start typing the DataType used to register the Classic datatype as a Maxon Data and set the classification to "Input."
  • Once defined, in the UI tab, the field Gui Type ID will display the different UI compatible with that type. The ID used to register the UiConversionInterface should be listed there. Once selected, the Classic gadget should be displayed inside the Resource Editor.