Main Index :

Plugin files


Plugins are stored in the plugins folder within the C4D folder. Each plugin should have a file named anything.cof. This file should contain a main() function with no arguments. When C4D starts it finds all files in this folder that end with .cof and executes this main() function. The simplest plugin possible thus looks like this:

main()
{
  println("Hello World!");
}

Such a plugin isn't very interesting, as it is only run when the program starts. Therefore we have the ability to register plugin hooks in various parts of the program. Each plugin type is represented by a class, for example MenuPlugin. (The different kinds of plugins are described more in detail elsewhere.) When you create a new menu plugin, you create a class that is derived from the MenuPlugin class. All plugin classes are in turn derived from the BasePlugin class: (This is not really true, but at least all plugin classes share BasePlugin's functions.)

class BasePlugin
{
public:
  BasePlugin();
  
  [int] GetID() = 0;
}
As those who are familiar with C++ will know, the =0 part means that the GetID() function must be declared in derived classes. As the name tells, this function is used to return the id of the plugin:
const var MyMenuPluginId = 123141241;

class MyMenuPlugin : MenuPlugin
{
public:
  MyMenuPlugin();
  
  GetID();
  [...]
}
MyMenuPlugin ::GetID() { return MyMenuPluginId; }

Important: Every plugin must have a unique id! Plugin ids can be registered at http://www.plugincafe.com for free.

The MenuPlugin class, as well as all the other plugin classes, also has other functions for your plugin class to overload. Among these are for example the function Execute() that is called whenever someone selects the menu item of the plugin.

When all the necessary virtual functions of the base class are overloaded it's time to register the plugin class with C4D. This is done in the main() function with the Register() function:

main()
{
  Register(MyMenuPlugin);
}

A .cof file can contain many different plugins, in which case there will be several Register() calls in the main() function. This is especially true of animation plugins, where a track, sequence and key plugin must be registered separately for each animation plugin.

Include files

The plugin code can be distributed into several files. Just create a separate .coh file (any suffix could be used as long as it's not .cof) in the same directory as the main .cof file, and include it at the top of the .cof file like this:

include "myInclude.coh"

Directory structure

While .cof files can be placed directly in the plugin directory, it is often better to group them into hierarchies. The standard layout for a plugin folder is like this:

myPlugin/
  myPlugin.cof
  myInclude.coh
  ...
  res/
    c4d_symbols.h
    dialogs/
      myDialog.res
      ...
  strings_us/
    c4d_strings.str
    dialogs/
      myDialog.str
      ...
  strings_de/
  strings_jp/
  ...
  myIcon.tif
  myWhatever.any
  ...

The main file is myPlugin.cof, which contains the main() function and will include the files named .coh. The res directory contains plugin resources, which currently means dialogs. Each dialog is contained in its own .res file. The c4d_symbols.h file should contain enums for the constants used in the .res files and should be included into the main .cof file.

Then there should be a directory named strings_xx for each language that the plugin supports, where xx is a two-letter language or country code according to the ISO 639 standard or the ISO 3361-1 standard. Currently there are C4D versions available for the following codes:

us - American English
de - German
fr - French
it - Italian
jp - Japanese

Each of the language directories should contain a .str file for every dialog and a c4d_strings.str for other resource strings. It is recommended that you first develop the plugin in one language, and then just copy the strings directory before translating.

Finally you can of course have any other files you like in your folder, for example plugin icons or logos. These can be conveniently accessed using the GeGetRootFilename() function.

Compiled plugins

Plain text .cof files can be compiled with the C4D C.O.F.F.E.E. compiler to binary .cob files. The advantage of compiled files is that nobody can see and/or change the code. The directory structure remains the same, except that all include files are included in the .cob file.

The C.O.F.F.E.E. compiler is included among the example plugins (Compiler.cof).