Cinema 4D Python API Examples

repository·master·Indexed 41 days ago

https://github.com/maxon-computer/cinema-4d-python-api-examples

A collection of Python API examples for Cinema 4D, covering GUI plugin development with GeDialog, dynamic layouts, resource organization, and localization. Includes implementations for persistent dialogs using BFM_LAYOUT_GETDATA and BFM_LAYOUT_SETDATA, tool finalization workflows for snapshot-based editing, and licensing patterns for plugin activation and validation.

Tokens
20.6K
Snippets
21
Records
168
Agent score
51%

What's inside Cinema 4D Python API

  1. Overview of Cinema 4D Python API script categories

    master

    The repository organizes Python examples into several functional categories to help you learn different aspects of the Cinema 4D API:

    • Foundations: Fundamental concepts and classes used throughout Cinema 4D.
    • Data and algorithms: Core data types and mathematical algorithms such as Vector, Matrix, and BaseContainer.
    • Application Development: General software development tasks including GUI creation (GeDialog, Description), File I/O, Threading, and Logging.
    • 3D concepts: High-level workflows and scene manipulation, including modeling operations, keyframe animation, materials, shading, document management, and render settings.
    • Modules: Examples extending Cinema 4D's functionality through specific modules like Xpresso, Mograph, Fields, Colorswatch, and Volume.
  2. Overview of the Asset API

    master

    The Asset API is a collection of interfaces designed for the Cinema 4D Asset Browser (replacing the legacy Content Browser). It primarily exposes the underlying data structures used by the Asset Browser rather than providing extensive GUI control.

    Assets can include scenes, objects, materials, media files, presets, and other types, which are organized via categories and keywords. These assets are stored in Asset Databases, which also manage Asset Metadata (such as annotations) visible in the Asset Browser's Info Area.

  3. Overview of the Color Chooser libraries

    master

    The Color Chooser libraries provide a system for managing color swatches and color utility functions.

    Color Swatches allow you to handle individual colors or groups of colors. These groups can be persisted within Cinema 4D, a BaseDocument, or as a preset.

    Core API Components:

    • c4d.modules.colorchooser: Provides static methods for color manipulation and utility.
    • c4d.modules.colorchooser.ColorSwatchData: A container used to store multiple ColorSwatchGroup objects.
    • c4d.modules.colorchooser.ColorSwatchGroup: A container that stores multiple colors represented as maxon::ColorA objects.
  4. Overview of Cinema 4D Python API Examples

    master

    This repository contains official code examples for the Cinema 4D Python API. These examples are identical to those shipped with the Cinema 4D Python SDK.

    To effectively use these examples, developers should refer to the Cinema 4D Python API Documentation for manuals and the API index, and follow the Getting Started guide.

    It is recommended to register at developers.maxon.net to generate plugin identifiers and access the developer forum.

  5. Overview of Cinema 4D Python API Modules

    master

    Cinema 4D's core functionality can be extended and accessed via several specialized Python API modules. These modules provide programmatic access to specific toolsets, ranging from rendering and animation to texturing and simulation. Use these modules to automate workflows or create custom tools within the following domains:

    • Rendering & Batching: batch_render for managing render queues and team_render (implied) for network rendering.
    • Animation & Motion: mograph for cloners, effectors, and fields; motion_tracker for accessing 2D track data and footage properties; and xpresso for node-based custom expressions.
    • Texturing & Materials: bodypaint for accessing edited bitmap textures on polygons; node for manipulating material and scene nodes; substance for interacting with Allegorithmic Substance procedural assets; and colorchooser for managing color swatches and groups.
    • Geometry & Simulation: lod_object for level-of-detail generators; thinking_particles for advanced particle systems; and volume for importing and editing OpenVDB data.
    • Workflow & Environment: assets for managing reusable assets in the Asset Browser; snap for accessing snap settings and workplanes; and token_system for handling expression tokens in file names.
  6. Overview of the Volume module

    master

    The Volume module provides tools to import, create, and edit OpenVDB data within Cinema 4D. It is split between the Classic API and the newer Maxon API.

    Classic API

    • c4d.VolumeObject: Represents a volume instance within a scene.
    • c4d.VolumeBuilder: A generator object used to construct volumes from scene geometry.

    Maxon API

    • maxon.frameworks.volume: The primary module for direct manipulation of c4d.VolumeObject.
    • maxon.VolumeToolsInterface: A helper interface for volume management.
    • maxon.GridAccessorInterface: An interface used to iterate through and access voxel data within volumes.
  7. Implement licensing checks in Cinema 4D Python plugins

    master

    This project provides examples for implementing licensing workflows in Cinema 4D using Python. Because Python source code is inherently insecure and can be decrypted or obfuscated, licensing should be implemented as a deterrent ('keep honest users honest') rather than a foolproof security measure.

    Available Examples

    • py-licensing.pyp: A comprehensive example demonstrating multiple licensing workflows, including internalized and file-based storage, both restart-based and no-restart-based activation workflows, and a GUI-based license manager dialog.
    • py-licensing_simple.pyp: A simplified version focusing on a single concept, such as simple file-based license storage in the user's preferences folder, a restart-based activation workflow, and a simple hashing scheme for license keys.
  8. Understand Cinema 4D 3D API concepts

    master

    The Cinema 4D Python API is organized into several core functional areas for managing 3D scenes and performing operations. Developers can interact with these concepts to manipulate geometry, manage scene data, or control rendering:

    • modeling: Accesses base classes for modeling within Cinema 4D. For advanced modeling tools, the MAXON API is required.
    • rendering: Provides tools to render a specific BaseDocument.
    • scene_elements: Manages the components of a scene, including:
      • animation: Controls keyframe animation via tracks, curves, and keys.
      • materials_shading: Manages materials, shaders, and texture paths.
      • scene_elements (objects/tags): Handles objects (e.g., Camera Object, Instance Object) and tags.
      • scene_management: Handles scene-level operations like layers, markers, and undo functionality.
      • take_system: Utilizes the Take System to manage different scene variations within a single BaseDocument.
    • simulation: Provides interfaces for Cinema 4D simulation tools, such as the particle system.
  9. Available File and Media manipulation examples

    master

    The following example scripts are available in this directory to demonstrate specific file and media tasks:

    • copy_32bits_image: Copies internal data of a 32-bit per-channel image to a new one.
    • export_alembic: Exports Alembic files with custom settings.
    • export_obj: Exports OBJ files with custom settings.
    • geclipmap_fill_color_bitmap: Adds an overlay color to a Picture.
    • import_obj: Imports OBJ files with custom settings.
    • import_sketchup: Imports Sketchup files with custom settings.
    • import_step: Imports STP/STEP files with custom settings.
    • read_write_memory_file_bitmap: Demonstrates writing and reading a bitmap to/from memory.
    • read_write_memory_file_data: Demonstrates writing and reading simple data to/from memory.
    • set_get_globaltexturepaths: Sets and gets global texture paths (found in Preferences -> Files -> Paths).
  10. Understand Cinema 4D scene elements and management

    master

    The Cinema 4D Python API allows for the programmatic manipulation of complex 3D scenes through several specialized modules. Developers can interact with the following core scene components:

    • scene_elements: Used for handling objects (such as Camera Object, Instance Object, etc.) and tags.
    • material_shading: Used for managing materials, shaders, and texture paths.
    • animation: Used to manage keyframe animation of parameters via tracks, curves, and keys.
    • take_system: Used to manage scene variations within a single BaseDocument.
    • scene_management: Used for high-level scene operations including layers, markers, and undo functionality.