Introduction into the GUI of Cinema 4D¶
The layout of a Python dialog is specified in the CreateLayout()
method. This method, which always should be overloaded in derived dialog classes, is called by Cinema 4D whenever the dialog is opened. There are two ways to specify the layout.
Layout files¶
The recommended way is to use layout files, just as Cinema 4D does internally. Then the typical CreateLayout()
becomes as easy as:
def CreateLayout(self):
return self.LoadDialogResource(MY_DIALOG)
The key here is that MY_DIALOG corresponds to a MY_DIALOG.res file in the res/dialogs directory (see Directory Structure chapter in Plugin Structure). This file might look like this:
DIALOG MY_DIALOG
{
NAME DIALOG_TITLE;
GROUP
{
COLUMNS 1;
SPACE 4,4;
BORDERSIZE 4,4,4,4;
STATICTEXT { NAME HELLO_WORLD; }
}
}
Using a separate dialog resource like this has several advantages. Besides that it is easy to edit the dialog layout, it also facilitates international support greatly. The NAME fields above doesn’t specify their strings directly. Instead they point to the strings in the MY_DIALOG.str file in the strings_en-US/dialogs directory:
DIALOGSTRINGS MY_DIALOG
{
DIALOG_TITLE "My Dialog";
HELLO_WORLD "Hello World!";
}
If you would like to support German as well, just copy the strings_en-US directory to a new strings_de-DE directory, and change the above file to:
DIALOGSTRINGS MY_DIALOG
{
DIALOG_TITLE "Mein Dialog";
HELLO_WORLD "Hallo Welt!";
}
The string files are stored in Unicode UTF-8, which means that they handle almost every language there is. A good Windows editor for Unicode files is Unipad. However, as long as you are only going to make English resources any text editor will do. All the files with your identifier are automatically read after Cinema 4D loaded your plugins.
The GeDialog class¶
If you for some reason do not want to use dialog resources for your dialog, all the resource commands for adding groups and dialog components are there as
functions in the GeDialog
class. So then the above dialog’s CreateLayout()
function would look like this:
def CreateLayout(self):
self.SetTitle("My Dialog")
self.GroupBegin(id=100010, flags=0, cols=1, rows=1)
self.AddGroupSpace(4, 4)
self.AddGroupBorderSpace(4, 4, 4, 4)
self.AddStaticText(id=100011, flags=0, name="Hello World!")
self.GroupEnd()
Please note that you have now lost all the localization features, unless you manually code all strings using the GeLoadString()
function.