Reference Cinema 4D Cinema 4D Visualize, Broadcast, Studio Character Animation Character Component
Function available in CINEMA 4D Studio
Character Component

Basic Tag Insertion Mirroring Include Materials Layers Selection Bind Adjustments Hotspots Notes Animate Walk Python Advanced

Python

The Python tab gives you a great deal of flexibility to add custom functions and behaviors during the building and adjusting phases of the Character object.

Code

Use this field to enter your Python code.

Using Python you can override the following methods to change the behavior of the Character object when it performs certain actions. Make sure to import the .c4d module within this field in order to reference objects and methods it contains. Complete Python documentation can be found at http://developers.maxon.net.

def BuildTemplate()

This function is called within Character type Component tags each time a character template is saved using the Save Character Template command. Using this function, you can insert objects to dynamically build a template or modify the template document. Note that when adding components you also need to add the Component tag with appropriate settings.

Globals:

def GetComponents()

This function is called within Character type Component tags at every redraw and can be used to specify which component buttons are shown within the Character object. Return a list of available components as BaseLinks stored within a BaseContainer. The standard inclusion rules specified in the Component tags will apply when no BaseContainer is returned.

Globals:

Return:

c4d.BaseContainer

Example:

If this code is entered in the Python tab, the Character object will ensure an object with the name "Spine_null” is present. Until a Spine is added, no other components can be added, regardless of the Parent. Note that the FindObject methods search for the object name, not the component name. A BaseContainer is returned in this example only when no Spine exists, so once a Spine is added the inclusion rules in the Component Tags will be used.

def ModeChanged()

Called for everyComponent tag when the mode (Build, Adjust, Bind, Animate) is changed. This can be used to change the visibility of objects or enable/disable functions like expressions. Nothing is returned, simply modify the Character object directly.

Globals:

Constants:

def InsertComponent()

This function is called in two different ways. When it's used within the Component tag’s Python tab it can be used to override all insertion actions. You must insert all the objects into the document to create the component, and return the main component object that was inserted into the document.

You can also call this function within an Insertion rule on the Insertion tab of the Component tag. When used here, the function allows you to change where and how the object will be inserted. In this case, the global variable itype indicates the insertion type (like the Insert drop-down in the rule) and you should return a c4d.BaseObject that corresponds to the Object attribute in the rule.

Globals:

Return:

c4d.BaseObject: the main component object or the object the component should be inserted under

Example

Using InsertComponent within a Python Insertion rule, this code defines which object to insert the component under, depending on whether the Parent already has a child. In this case, it's used with a branching T-joint to insert each component under a different end of the joint.

def PostInsertComponent()

This function is called after a component has been inserted in the Character object and only when InsertComponent is not used. If nothing is returned you can make changes directly to the inserted objects within the function.

Globals:

def MirrorComponent()

This function is called when a mirrored component is added to the Character object. Mirrored components are generated automatically when multiple components of the same type are added with the same parent, based on the settings in the Component tag’s mirroring tab. MirrorComponent is called before PostInsertComponent and the mirrored component can be modified directly within this function.

Globals:

Return:

True / !=0 if mirroring was done by Python

def BoneInsert()

This function is called within a Component tag's Python tab when the user changes the bone count and completely overrides the bone insert.

Globals:

def IncludeObjects()

This function enables you to include additional objects with the component, similar to the Component tag’s Include tab. The incdata global is a BaseContainer in which the data of each entry is a BaseLink to the object and the index is an integer corresponding to the InExcludeData flags:

Flags:

Globals:

Return:

True / !=0: if the incdata was changed

def AdjustObject()

This function is called within a Python type Adjustment rule, which is created in the Adjustments tab by adding an object / rule to the Objects list and setting the Type to Python. This function is only evaluated when placed in the resulting Code field associated with each rule. The function is called continuously while the related handle is being adjusted. Within this function you can adjust the globals directly or return the matrix - the latter is preferable as the former could conflict with other rules. All matrices for this function are local to the Character object.

Globals:

Return:

The matrix to set for the object (c4d.Matrix)

def GetDependency()

This function is called prior to AdjustObject when placed in the Code field of a Python type Adjustment rule. Within this function you can return the objects upon which the rule depends. For instance, if an adjustment rule needs to set position based on 3 other objects (such as for a pole vector), you would return a c4d.BaseContainer with links to those 3 objects. This allows the Character object to create a dependency tree so that adjustments will be evaluated in the correct order, since one rule could change the object matrix used by another rule.

Globals:

Return:

c4d.BaseContainer containing BaseLinks (ID isn't evaluated)

def TransformComponent()

This function is called within a Python type Insertion rule, which is created in the Insertion tab by adding an object / rule to the Objects list and setting the Type to Python. Within this function you can transform the component and all its included objects during insert (overriding the transform settings specified in the tab).

Globals:

Return:

The new global matrix (c4d.Matrix) for the main component object

def AllowComponent()

This function is called within a Python type Insertion rule, which is created in the Insertion tab by adding an object / rule to the Objects list and setting the Type to Python. This function is only evaluated when placed in the resulting Code field associated with each rule. Return True to allow the component. This function is very similar to GetComponents, except it returns the state of a single component.

Globals:

Return:

c4d.modules.character.builder.CharacterObject

def FindObject(name)

Find an object by template name.

Parameters: name (string) - the object name to search for

Returns: The found object (c4d.BaseObject) or None

def GetFirst()

Returns the first character component.

Returns: The first component (builder.ComponentObject) or None

def GetObject()

Get the character BaseObject.

Returns: The Character's BaseObject (c4d.BaseObject)

c4d.modules.character.builder.Template

def FindComponent(name, ident)

Find component within template.

Parameters:

Returns: The found component (builder.Component) or None

def FindObject(name)

Find object within template.

Parameters: name (string) - the object name to search for

Returns: The found object (c4d.BaseObject) or None

def GetDocument()

Get the template BaseDocument.

Returns: The document (c4d.BaseDocument)

c4d.modules.character.builder.Component

def GetObject()

Gets the component's BaseObject.

Returns: The object (c4d.BaseObject)

def GetTemplate()

Get the component's Template.

Returns: The template (builder.Template)

c4d.modules.character.builder.ComponentObject

def CountComponent(name, ident, mirrored, down)

Count child components.

Parameters:

Returns: number of matches (int)

def FindComponent(name, ident, mirrored, down)

Find a specific child component by name.

Parameters:

Returns:first matched object (builder.ComponentObject)

def FindObject(name)

Find an object within the component by name.

Parameters: name (string) to match

Returns:first matched object (c4d.BaseObject)

def GetComponent()

Get the Component.

Returns: the related component (builder.Component)

def GetDown()

Get the main object of the first child component.

Returns: the main object of the first child component (c4d.BaseObject)

def GetName(ident)

Get the component's name.

Parameters: ident (boolean) if true, displays name and unique identifier

Returns: the name (string)

def GetNext()

Get the main object of the next component.

Returns: the main object of the next component (c4d.BaseObject)

def GetObject()

Get the component's main object.

Returns: the object (c4d.BaseObject)

def GetObjects(type=COMPONENT_OBJECT_GETOBJECTS_TYPE_):

Get a container with all the objects for this component.

Parameters:

Returns: container with object links (c4d.BaseContainer)

def GetPrev()

Get the previous component's main object.

Returns: the main object of the previous component (c4d.BaseObject)

def GetTag()

Get the component tag for this component.

Returns: the component tag (c4d.BaseTag)

def GetUp()

Get the Parent component's main object.

Returns: the main object of the Parent component (c4d.BaseObject)