On this page

Docs / Commander+

Writing extensions

Add your own commands to Commander+ with macros, scripts, extension folders and packs.

You can add your own commands to the palette. A macro runs existing commands in order, a script turns one Python file into a command, and a folder holds several commands. With Pro Creator you can also turn your scripts into a protected pack to share or sell.

Where extensions go

Type extensions folder in the palette to open the folder:

<Cinema 4D preferences>/commander-plus/extensions/

Anything in it is loaded when Cinema 4D starts. After you add or edit an extension, type reload extensions. Settings › Extensions lists every extension; its details page switches it (or single commands) off and shows why one did not load.

Pick the simplest kind that does the job:

Kind What it is Good for
Pack A .c4dx made by create extension, installed by install extension Sharing or selling scripts, protected
Macro One .json file Running existing commands in order, no code
Script One .py file with a header One command, quick to write
Folder A folder with extension.json and Python Several commands, icons, sharing

Macro (.json)

{
  "command": "tidy and save",
  "description": "Delete empty nulls, then save",
  "steps": [
    {"run": "clean nulls"},
    12098
  ],
  "closes": true,
  "icon": 12098
}

Steps run in order:

  • A number: a Cinema 4D command id.
  • {"call": id, "subid": n}: a command with a sub-id.
  • {"run": "text"}: any palette command, as if you typed it ("sds on", or another extension's command).

Script (.py)

Any Script Manager script works as it is. Drop it in the folder and it becomes a command named after its file: Icon_Button.py becomes icon button.

To choose the keyword, add a description or take an argument, add header lines among the comments at the very top:

# @command drop to floor
# @description Move the selected objects down onto the floor
# @args choice y|x|z?
# @closes yes
# @icon 12345

import c4d

def main():
    for op in doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_TOPLEVEL):
        ...

if __name__ == "__main__":
    main()

All header lines are optional:

Header What it sets
@command The keyword you type.
@description The description in the palette.
@args The argument: its type, then the choice values.
@closes Ignored: a script always closes the palette (see Dialogs).
@icon An icon id, or an image file next to the script.
@name The display name of the extension and its command.
@author, @version Who made it, and its version.

As in the Script Manager, c4d, doc and op are there. So are args (the typed argument as a list of words) and ctx (see below). Instead of the __main__ block, you can define run(ctx).

The script is read again on every run: edit it and run it again, no reload needed. Only header changes need reload extensions.

Folder (extension.json and Python)

extensions/
  selection-tools/
    extension.json
    main.py
    icon.png        (optional)

extension.json:

{
  "name": "Selection Tools",
  "version": "1.0",
  "author": "You",
  "description": "Rename and group the selection",
  "api": 1,
  "main": "main.py",
  "commands": [
    {
      "keyword": "rename selection",
      "description": "Rename the selected objects, numbered",
      "args": {"type": "text"},
      "run": "rename"
    },
    {
      "keyword": "group selection",
      "description": "Put the selected objects under a new null",
      "icon": "icon.png",
      "closes": true
    }
  ]
}

Each command has:

Field What it is
keyword Required. What you type.
name The display name (optional).
description The description in the palette.
args The argument (see below).
run The function in main. By default, the keyword with _ for spaces: group_selection.
closes Ignored: a folder's commands always close the palette (see Dialogs).
icon An icon id, or an image in the folder.

A command can give "steps": [...] instead of run, like a macro.

main.py:

import c4d

def rename(ctx):
    for i, op in enumerate(ctx.selection, 1):
        ctx.doc.AddUndo(c4d.UNDOTYPE_CHANGE_SMALL, op)
        op.SetName("%s %d" % (ctx.text, i))

def group_selection(ctx):
    ...

api is the extension format the folder was written for (1 today). A Commander+ too old for it refuses it with a clear message instead of failing halfway.

Keywords and arguments

A command's keyword is what you type: lowercase letters, digits, spaces, ., _ and - (bake textures, lod-2). A keyword Commander+ already uses, or one another extension took first, is refused, and Settings says so.

A command can take one argument after its keyword. The palette checks it and suggests values before running:

Type Typed as Suggestions
none (default) tidy up None
choice bake high The listed values
number grow 2.5 None
text rename Hero Shot None (kept as typed)
material use Oak Floor The scene's materials
object find Cube The scene's objects

Any argument can be optional: add ? in the shorthand, or "optional": true.

A text or number argument can have a hint: what to type, shown after the keyword until something is typed. A number can have a min and a max: the palette does not run a number outside them.

The shorthand

A script's @args and a manifest's "args" as a string use this shorthand: type[?] [min..max] [values] ["hint"].

Shorthand Means
text Any text
text? "Object name" Optional text, hint "Object name"
number 1..64 "Segments" A number from 1 to 64, hint "Segments"
number ..10 / number 0.. At most 10 / at least 0
choice? low|high Optional, one of the values

The hint is everything after the first ". A closing " is optional, and a hint can't hold a ". The range is a number's first word with .. in it; either side may be empty.

In a manifest you can also write it as an object:

{"type": "number", "min": 1, "max": 64, "hint": "Segments", "optional": true}

Display name

Rows, the preview and Help › Commands show a command's name ("Drop to Floor") rather than its keyword. Search finds it by either. Give it:

  • in extension.json: "name" in each command, next to "keyword";
  • in a macro: its top-level "name";
  • in a script: # @name, which names the extension and its one command;
  • with the extension creator: the script's Name-US: header, when it reads like a name ("Boole Split", not "AR_BooleSplit").

Without one, the keyword in title case is shown (bake textures becomes "Bake Textures"). The keyword is still what you type.

What your code gets (ctx)

Name What it is
ctx.c4d The c4d module.
ctx.doc The active document.
ctx.op The active object, or None.
ctx.selection The selected objects (with children).
ctx.materials The selected materials.
ctx.args The typed argument as a list of words.
ctx.text The typed argument as one string.
ctx.path The extension's folder or file.
ctx.status(text) Shows text on Cinema 4D's status bar.
ctx.run_command(text) Runs another palette command, as if typed.

Each run of a script or folder command is one undo step. Call ctx.doc.AddUndo(...) before changing things, and Ctrl+Z undoes the whole command. Macros run Cinema 4D's own commands, which make their own undo steps.

c4d.EventAdd() is called for you afterwards.

Dialogs

Commands of scripts, folders and packs always close the palette, whatever closes says, and run only once it has closed. Cinema 4D has the focus again, so c4d.gui.MessageDialog, InputDialog, LoadDialog or a modal GeDialog work as they do from the Script Manager. Only a macro can keep the palette open ("closes": false).

A pinned palette (Ctrl+P) hides while such a command runs and opens again when it ends, so its dialogs and menus open in front.

Popup menus (c4d.gui.ShowPopupDialog) work too. A popup asked for at c4d.MOUSEPOS without a dialog opens at the pointer. A popup opened from a dialog's own Timer never responds: that is Cinema 4D's behaviour.

A non-modal dialog (DLG_TYPE_ASYNC) must be kept in a variable (a global in a script, a module variable in a folder), or it closes when the command ends. Running the script again keeps the dialog the last run left open.

Its buttons run after the command has finished, outside its undo step. Wrap their changes in doc.StartUndo() / doc.EndUndo() yourself, and get the document again (c4d.documents.GetActiveDocument()), since doc and op are the ones from when the command ran.

The extension creator

The extension creator turns your scripts into a protected .c4dx pack. It is part of the Pro Creator plan.

  1. 01
    Type create extension (or Settings › Extensions › Create).
  2. 02
    Pick a script, or a whole folder of scripts, with the Script / Folder buttons, or drop it on the palette. The palette shows what each script becomes, and a summary of the extension.
  3. 03
    Click "Edit details…" to set the name, author, description and version, each command's display name and keyword, and Selling it. Click "Done" (or press Esc) to go back.
  4. 04
    Click "Create .c4dx". A progress bar follows each script.
Screenshot: The extension creator
The extension creator

The result is one file, <id>-<version>.c4dx, next to your scripts ("Show file" opens its folder). That is what you share or sell. With "Also install it here" (on by default), it is installed for you too, so you can try it at once.

The creator makes one command per script:

  • Names come from Cinema 4D's script header (Name-US:, Description-US:, Author:), else the file name. A prefix every script in the pack shares (AR_, HB_) is dropped: AR_BooleSplit becomes boole split.
  • Icons are the images Cinema 4D already uses: the file with the script's name next to it (.tif, .png…).
  • Old code is fixed: Python 2 code (print x, xrange, except E, e…) and API calls Cinema 4D removed (GetLong becomes GetInt32, GetReal becomes GetFloat…). The window lists every fix, and anything it can't fix (scripts that react to Shift/Ctrl/Alt, fixed file paths, renderer plugins they need).
  • Data files a script reads next to itself are copied along.
  • The code is protected: each script is compiled and stored encrypted. It never lands on disk as source.
  • Compiled for one Python: create the pack in the Cinema 4D version your buyers use (2026 uses Python 3.11). Another version says so and asks for a new build.
  • Selling it (optional): the Gumroad product id (in the product's settings on Gumroad) and the Gumroad page (the "Buy it" link buyers see). Leave them empty for a free pack. A paid pack doesn't install, or run, without a valid licence key.

Your author key

Every pack you create is signed with your own author key, %USERPROFILE%\.commander-plus\author.key, made on your first Create. It proves that a new version comes from the same author as the one installed.

A new version

  1. 01
    In Settings › Extensions, open one of your packs. Its details show "Made here".
  2. 02
    Click "New version". The creator opens on the scripts it was made from, with the version raised (1.0 to 1.1) and what changed since the last one: new, changed and removed scripts. The summary shows what it was "Published as".
  3. 03
    Untick a command to leave it out.
  4. 04
    In "Edit details…", write a line or two under "What's new". Buyers see it when they install.
  5. 05
    Click "Create 1.1" (with your new version number).

If you change the Gumroad product id, buyers of the old version need a new licence. An empty one makes the new version free. The creator warns you in both cases.

Share the new .c4dx the same way as the first. Buyers install it over the old one, and a paid pack needs no key again.

Create every version on the computer with the same author.key. A new version signed with another key is refused as "Not from the author".

Your settings travel with the scripts

When you click Create, the creator saves what you changed (names, keywords, descriptions, icons, arguments, commands you left out) in commander-pack.json in the scripts folder. For a single script it is <script>.commander-pack.json beside it.

An Include switch is saved there the moment you flip it, so a script you switched off stays off. The next scan starts from this file, on this computer or any other, so keep it with your scripts. It only lists what differs from what the creator guesses. You can edit it by hand; a value that isn't valid is ignored, and the creator says so.

When something goes wrong

Every error, in a command or later in one of its dialogs, becomes an error report: the Commander+ and Cinema 4D versions, the extension and command, what the creator changed in the code, and the traceback. Your home folder shows as ~.

  • Type copy error report to copy the latest one.
  • Type error reports to open the folder that keeps the last 50 (commander-plus/logs in your Cinema 4D preferences folder).

The same folder has debug.log. If Cinema 4D stops responding for 15 seconds, the line it is stuck on is written there too.

Problem What to do
An extension fails to load Settings › Extensions lists it with the reason. The others load normally.
"Commander+: … failed: …" on the status bar The command raised an error. The full traceback is in the Python console.
A pack won't uninstall ("Cinema 4D is using one of its files") Restart Cinema 4D, then uninstall it before running any of its commands.
Your new version is refused as not from the author It was created with another author.key than the first one. Restore the backup of that key and create it again.