Solved 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.
    c5dbdd05-cb75-42f3-a0ab-5ee1a99c5de0-image.png
    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.
    9d2f3d55-fca0-43ef-9b6b-ef17caeb3605-image.png

Cheers,
Ferdinand

The result:
palette.gif

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().
    c4d.documents.LoadFile(paletteFile)

if __name__ == '__main__':
    main()

MAXON SDK Specialist
developers.maxon.net

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.
    c5dbdd05-cb75-42f3-a0ab-5ee1a99c5de0-image.png
    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.
    9d2f3d55-fca0-43ef-9b6b-ef17caeb3605-image.png

Cheers,
Ferdinand

The result:
palette.gif

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().
    c4d.documents.LoadFile(paletteFile)

if __name__ == '__main__':
    main()

MAXON SDK Specialist
developers.maxon.net