volume_command_sphere

Creates a sphere volume with the corresponding command.

volume_command_sphere.py

"""Creates a sphere volume with the corresponding command.

Topics:
    * c4d.modules.volume.SendVolumeCommand()
    * c4d.VOLUMECOMMANDTYPE_CREATESPHEREVOLUME
"""
__author__ = "Maxime Adam"
__copyright__ = "Copyright (C) 2026 MAXON Computer GmbH"
__license__ = "Apache-2.0 License"
__version__ = "R20"

import c4d


def main():
    # Configures settings for sphere volume command
    settings = c4d.BaseContainer()
    settings[c4d.CREATESPHEREVOLUMESETTINGS_RADIUS] = 100.0
    settings[c4d.CREATESPHEREVOLUMESETTINGS_POSITION] = c4d.Vector(0, 100, 0)
    settings[c4d.CREATESPHEREVOLUMESETTINGS_BANDWIDTH] = 2
    settings[c4d.CREATESPHEREVOLUMESETTINGS_GRIDSIZE] = 1.0

    # Creates sphere volume
    result = c4d.modules.volume.SendVolumeCommand(c4d.VOLUMECOMMANDTYPE_CREATESPHEREVOLUME, [], settings, doc)
    if not result:
        raise MemoryError("Failed to create a sphere volume.")

    # Gets the sphere volume result
    volumeObject = result[0]

    # Inserts the object into the active document
    doc.InsertObject(volumeObject)
    doc.SetActiveObject(volumeObject)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()


# Execute main()
if __name__ == '__main__':
    main()