UNSOLVED Programmatically create a palette?

Is it possible to programmatically create a palette with commands that I specify? I would like to be able to create palettes on demand with certain commands so that a user can dock them.

Hello @kbar,

Thank you for reaching out to us. I am sure you are aware that this has been discussed before and nothing has changed here. It is not possible to programmatically instantiate, open, or populate palettes from the public C++ API. While we technically have the possibility to do it internally, our internal code does not really make use of this either. Which is why such a function does not exist although frequently requested.

There are two options you have:

  • Cinema 4D relies primarily on layouts these days. If you want to provide a specific working environment for users, you can simply provide layout files just as Cinema 4D does. Layout files can be provided for a full layout just as for single palette. Layout files for palettes can be saved from the context menu of a palette.
    A layout file can then be loaded back into Cinema 4D with the general-purpose file loading function LoadFile. Find a brief example in Python at the end of this posting.
  • You can provide and structure your product menu with CommandData plugins in such way that they form easy to separate palettes for the user.


The result:

The script:

"""Loads a palette file into Cinema 4D.

Showcases the ability of LoadFile() to handle almost all file formats Cinema 4D can deal with,
including layout files for palettes or the whole window.

import c4d
import os

def main() -> None:
    """Loads a palette into Cinema 4D.
    # Determine and assert the palette file path, the palette file in this 
    # example is meant to be located in the same directory as this script.
    directory = os.path.dirname(__file__)
    paletteFile = os.path.join(directory, "myPalette.l4d")
    if not os.path.exists(paletteFile ):
        raise OSError(f"The path {paletteFile } does not exist.")

    # Open the palette with LoadFile().

if __name__ == '__main__':