c4d.CKey

class c4d.CKey
Represents a key in the curve of a track which represent the animation of a parameter.

Tangents are only guaranteed to be available for tracks of category CTRACK_CATEGORY_VALUE. Tracks of the categories CTRACK_CATEGORY_DATA and CTRACK_CATEGORY_PLUGIN may contain tangent data or not. E.g., a BaseTime track will provide tangents for its keys, while a PLA track will not. Such tracks which do not provide tangent data will however not raise an error on attempting to retrieve a tangent for a key, but instead return the null-vector (0, 0, 0).

Methods Signatures

CKey.GetTime(self)

Gets the time of the key.

CKey.GetTimeLeft(self)

Gets the time component of the left tangent of the key.

CKey.GetTimeRight(self)

Gets the time component of the right tangent of the key.

CKey.GetValue(self)

Gets the value of the key.

CKey.GetValueLeft(self)

Gets the value component of the left tangent of the key.

CKey.GetValueRight(self)

Gets the value component of the right tangent of the key.

CKey.SetValue(self, seq, v)

Sets the value of the key.

CKey.SetValueLeft(self, seq, v)

Sets the value component of the left tangent of the key.

CKey.SetValueRight(self, seq, v)

Sets the value component of the right tangent of the key.

CKey.SetTime(self, seq, t)

Sets the time of the key.

CKey.SetTimeLeft(self, seq, t)

Sets the time component of the left tangent of the key.

CKey.SetTimeRight(self, seq, t)

Sets the time component of the right tangent of the key.

CKey.SetInterpolation(self, seq, inter)

Sets the interpolation type of the key.

CKey.GetInterpolation(self)

Returns the interpolation type of the key.

CKey.SetQuatInterpolation(self, seq, inter[, bUndo])

Sets the quaternion interpolation type of the key.

CKey.GetQuatInterpolation(self)

Gets the quaternion interpolation type of the key.

CKey.GetTrack(self)

Gets the track of the key.

CKey.GetCurve(self)

Gets the curve of the key.

CKey.FlushData(self)

Flushes the data of the key.

CKey.SetGeData(self, seq, d)

Sets the data of the key.

CKey.GetGeData(self)

Gets the data of the key.

CKey.GetClone(self[, trans])

Gets a clone of the key.

CKey.GetAutomaticTangentMode(self)

Gets the AutoTangent mode of the key.

CKey.SetAutomaticTangentMode(self, seq, autoMode)

Sets the AutoTangent mode of the key.

CKey.SetTimeLeftAdjustValue(self, seq, t)

Sets Time Left and adjusts Value so the angle stays the same.

CKey.SetTimeRightAdjustValue(self, seq, t)

Sets Time Right and adjusts Value so the angle stays the same.

Inheritance

Parent Class:

Methods Documentation

CKey.GetTime(self)

Gets the time of the key.

Return type

c4d.BaseTime

Returns

The time.

CKey.GetTimeLeft(self)
Gets the time component of the left tangent of the key.

See class description for details on the availability of tangents.
Return type

c4d.BaseTime

Returns

The left time.

CKey.GetTimeRight(self)
Gets the time component of the right tangent of the key.

See class description for details on the availability of tangents.
Return type

c4d.BaseTime

Returns

The right time.

CKey.GetValue(self)
Gets the value of the key.

Used to read keys of tracks that are of category CTRACK_CATEGORY_VALUE. This usually only does apply to DTYPE_REAL and DTYPE_LONG tracks, other data types must be read with CKey.GetGeData(). An exception to that rule are tracks for data types that are composed out of float values, like for example c4d.Vector or c4d.Matrix. Here the type is being decomposed into multiple tracks of floating point values. E.g., for a vector into its three or four components and for a matrix first into its vectors and then each vector into its components. Call CTrack.GetTrackCategory() to determine the category of a track and therefore the method which has to be used to read data from its keys.

See also

To read keys of tracks of the category CTRACK_CATEGORY_DATA, including of type DTYPE_BOOL, use CKey.GetGeData().

Return type

float

Returns

The value.

CKey.GetValueLeft(self)
Gets the value component of the left tangent of the key.

See class description for details on the availability of tangents.
Return type

float

Returns

The value.

CKey.GetValueRight(self)
Gets the value component of the right tangent of the key.

See class description for details on the availability of tangents.
Return type

float

Returns

The value.

CKey.SetValue(self, seq, v)
Sets the value of the key.

Used to write keys of tracks that are of category CTRACK_CATEGORY_VALUE. This usually only does apply to DTYPE_REAL and DTYPE_LONG tracks, other data types must be written with CKey.SetGeData(). An exception to that rule are tracks for data types that are composed out of float values, like for example c4d.Vector or c4d.Matrix. Here the type is being decomposed into multiple tracks of floating point values. E.g., for a vector into its three or four components and for a matrix first into its vectors and then each vector into its components. Call CTrack.GetTrackCategory() to determine the category of a track and therefore the method which has to be used to write data into its keys.

See also

To write keys of tracks of the category CTRACK_CATEGORY_DATA, including of type DTYPE_BOOL, use CKey.SetGeData().

Parameters
  • seq (c4d.CCurve) – The curve.

  • v (float) – The new value.

CKey.SetValueLeft(self, seq, v)
Sets the value component of the left tangent of the key.

See class description for details on the availability of tangents.
Parameters
  • seq (c4d.CCurve) – The curve.

  • v (float) – The new value.

CKey.SetValueRight(self, seq, v)
Sets the value component of the right tangent of the key.

See class description for details on the availability of tangents.
Parameters
  • seq (c4d.CCurve) – The curve.

  • v (float) – The new value.

CKey.SetTime(self, seq, t)

Sets the time of the key.

Parameters
CKey.SetTimeLeft(self, seq, t)
Sets the time component of the left tangent of the key.

See class description for details on the availability of tangents.
Parameters
CKey.SetTimeRight(self, seq, t)
Sets the time component of the right tangent of the key.

See class description for details on the availability of tangents.
Parameters
CKey.SetInterpolation(self, seq, inter)

Sets the interpolation type of the key.

Parameters
  • seq (c4d.CCurve) – The curve.

  • int

    The new interpolation type:

    CINTERPOLATION_SPLINE

    Spline.

    CINTERPOLATION_LINEAR

    Linear

    CINTERPOLATION_STEP

    Step.

CKey.GetInterpolation(self)

Returns the interpolation type of the key.

Return type

int

Returns

The interpolation type:

CINTERPOLATION_SPLINE

Spline.

CINTERPOLATION_LINEAR

Linear

CINTERPOLATION_STEP

Step.

CKey.SetQuatInterpolation(self, seq, inter, bUndo=True)

Sets the quaternion interpolation type of the key.

New in version R18.020.

Note

Keys at the same time on other component curve will be modified.

Parameters
  • seq (c4d.CCurve) – The curve the key belongs to.

  • inter (int) –

    The quaternion interpolation type to set:

    ROTATIONINTERPOLATION_QUATERNION_SLERP

    Quaternion Spherical LERP Interpolation (Linear).

    ROTATIONINTERPOLATION_QUATERNION_CUBIC

    Quaternion Smooth Cubic Interpolation (Formerly known as Losch).

  • bUndo (bool) –

    True to add the 3 rotation keys in the undo system.
    The caller has to to manage start/end of undo actions with BaseDocument.StartUndo()/EndUndo().

CKey.GetQuatInterpolation(self)

Gets the quaternion interpolation type of the key.

New in version R18.020.

Return type

int

Returns

The quaternion interpolation type:

ROTATIONINTERPOLATION_QUATERNION_SLERP

Quaternion Spherical LERP Interpolation (Linear).

ROTATIONINTERPOLATION_QUATERNION_CUBIC

Quaternion Smooth Cubic Interpolation (Formerly known as Losch).

CKey.GetTrack(self)

Gets the track of the key.

Return type

c4d.CTrack

Returns

The track.

CKey.GetCurve(self)

Gets the curve of the key.

Return type

c4d.CCurve

Returns

The curve.

CKey.FlushData(self)

Flushes the data of the key.

CKey.SetGeData(self, seq, d)
Sets the data of the key.

Used to write keys of tracks that are of category CTRACK_CATEGORY_DATA. This usually does apply to tracks that neither store DTYPE_REAL and DTYPE_LONG data, and those data types must be written with CKey.SetValue(). An exception to that rule are tracks for data types that are composed out of float values, like for example c4d.Vector or c4d.Matrix. Here the type is being decomposed into multiple tracks of floating point values. E.g., for a vector into its three or four components and for a matrix first into its vectors and then each vector into its components. Call CTrack.GetTrackCategory() to determine the category of a track and therefore the method which has to be used to write data into its keys. See the example below for how to write a boolean key value with this method.
# Get the first material of the document and its first track.
mat = doc.GetFirstMaterial()
if mat is None:
    raise RuntimeError("No material found.")
track = mat.GetFirstCTrack()
if track is None:
    raise RuntimeError("Material has no tracks.")

# Bail when this first track is not for the boolean "use color" parameter 
# of the material.
if track.GetDescriptionID()[0].id != c4d.MATERIAL_USE_COLOR:
    raise RuntimeError("'Use-Color' track not found")

# Get the curve of the track and its first key. 
curve = track.GetCurve(c4d.CCURVE_CURVE)
if curve.GetKeyCount() < 1:
    raise RuntimeError("Curve has no keys.")
key = curve.GetKey(0)

# Print the current value of the boolean key and then set it to `True`.
print (key.GetGeData())
key.SetGeData(curve, True)

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

See also

To write keys of tracks of the category CTRACK_CATEGORY_VALUE, use CKey.SetValue().

Parameters
  • seq (c4d.CCurve) – The curve.

  • d (any) – The data.

CKey.GetGeData(self)
Gets the data of the key.

Used to read keys of tracks that are of category CTRACK_CATEGORY_DATA. This usually does apply to tracks that neither store DTYPE_REAL and DTYPE_LONG data, those data types must be read with CKey.GetValue(). An exception to that rule are tracks for data types that are composed out of float values, like for example c4d.Vector or c4d.Matrix. Here the type is being decomposed into multiple tracks of floating point values. E.g., for a vector into its three or four components and for a matrix first into its vectors and then each vector into its components. Call CTrack.GetTrackCategory() to determine the category of a track and therefore the method which has to be used to read data from its keys. See the example below for how to read complex data out of a key. The compilation of the returned c4d.BaseContainer depends on the described data type. See c4d.CustomDataType for an overview of the custom data types exposed to Python.
# This is a PLA track, we get its curve and iterate over all keys.
if ctrack.CheckType(c4d.CTpla):
    curve =  ctrack.GetCurve(c4d.CCURVE_CURVE)

    for i in range(curve.GetKeyCount()):
        ckey = curve.GetKey(i)
        # We retrieve the key data with GetGeData which usually returns
        # a BaseContainer().
        data = ckey.GetGeData()
        if not isinstance(data, c4d.BaseContainer):
            RuntimeError("Failed to retrieve PLA data.")

        print (data[c4d.CK_PLA_DATA])

See also

To read keys of tracks of the category CTRACK_CATEGORY_VALUE, use CKey.GetValue().

Return type

Any

Returns

The data, depends on the key.

CKey.GetClone(self, trans=None)

Gets a clone of the key.

Parameters

trans (Optional[c4d.AliasTrans]) –

New in version R17.032: An optional alias translator for the operation.

Return type

c4d.CKey

Returns

The cloned key.

CKey.GetAutomaticTangentMode(self)

Gets the AutoTangent mode of the key.

New in version R17.048.

Return type

int

Returns

The AutoTangent mode:

CAUTOMODE_CLASSIC

AutoTangent first implementation.

CAUTOMODE_FIXEDSLOPE

AutoTangent with fixed slope for given time.

CKey.SetAutomaticTangentMode(self, seq, autoMode)

Sets the AutoTangent mode of the key.

New in version R17.048.

Parameters
  • seq (c4d.CCurve) – The curve the key belongs to.

  • autoMode (int) –

    The AutoTangent mode to set:

    CAUTOMODE_CLASSIC

    AutoTangent first implementation.

    CAUTOMODE_FIXEDSLOPE

    AutoTangent with fixed slope for given time.

CKey.SetTimeLeftAdjustValue(self, seq, t)

Sets Time Left and adjusts Value so the angle stays the same.

New in version R17.048.

Parameters
Return type

bool

Returns

True if successful. False if current Time Left is smaller than FLT_MIN and Value is not Zero (angle cannot stay the same).

CKey.SetTimeRightAdjustValue(self, seq, t)

Sets Time Right and adjusts Value so the angle stays the same.

New in version R17.048.

Parameters
Return type

bool

Returns

True if successful. False if current Time Right is smaller than FLT_MIN and Value is not Zero (angle cannot stay the same).