The script works for anything that is a
c4d.PointObject, i.e., editable polygon and spline objects. But not for generators, e.g., the Cube object or the Circle spline, as you cannot edit their points and therefore have no control over the placement of their "axis" in relation to their vertices.
When you want to set the transform of any
BaseObject, e.g., a
PointObject, a generator, or a null object, you must simply set either its local or global matrix. But this will not keep vertices 'in place' as generators and a null object have no vertices one could edit, and the vertices of
PointObject instances must be corrected manually to achieve the 'move the axis idea'.
But you can of course just set the global or local matrix (a.k.a. transform) of a
BaseObject. Find an example below. For more detailled information, I would recommend having a look at the Matrix Manual.
The result, the two cubes are not at the same location because combining two transforms is not commutative, i.e., the order matters. A * B is not always the same as B * A for matrices:
"""Demonstrates the basic concept of transformations as realized by Cinema 4D.
def main() -> None:
"""Constructs two transforms and applies them in the global coordinate system to two cube
# Construct a transform that translates by 500 units on the y-axis and one that rotates by
# 45° on the x-axis.
move: c4d.Matrix = c4d.utils.MatrixMove(c4d.Vector(0, 500, 0))
rotate: c4d.Matrix = c4d.utils.MatrixRotX(c4d.utils.DegToRad(45))
# Combine both transforms into a singular one by multiplying them. Note that matrix
# multiplication, combining transforms, is not commutative. I.e., the order matters opposed
# to numbers; move * rotate is not the same as rotate * move.
tMoveRotate: c4d.Matrix = move * rotate
tRotateMove: c4d.Matrix = rotate * move
# Allocate two cube objects.
cubeMoveRotate: c4d.BaseObject = c4d.BaseObject(c4d.Ocube)
cubeRotateMove: c4d.BaseObject = c4d.BaseObject(c4d.Ocube)
if None in (cubeMoveRotate, cubeRotateMove):
raise MemoryError("Could not allocate cube object.")
# And set their global matrix, i.e., the absolute transform in the global coordinate system.
# Name both null objects, set their display color, insert them into the active document, and
# push an update event.
cubeMoveRotate.SetName("Cube: Move -> Rotate")
cubeRotateMove.SetName("Cube: Rotate -> Move")
cubeMoveRotate[c4d.ID_BASEOBJECT_USECOLOR] = c4d.ID_BASEOBJECT_USECOLOR_ALWAYS
cubeRotateMove[c4d.ID_BASEOBJECT_USECOLOR] = c4d.ID_BASEOBJECT_USECOLOR_ALWAYS
cubeMoveRotate[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(1, 0, 0)
cubeRotateMove[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(0, 0, 1)
if __name__ == '__main__':