Skip to main content

Copy Objects

There's really robust procedural workflow in C4D especially that involves manual animation. Here is the script that copies the object hierarchy. It's not procedural copy and paste. But its a bit workaround.

One work case is if you want to have multiple extrude animation but have different letters. Just animatme one extrude letter and copy and paste it to another different letters through the script rather than doing it manually.


import c4d


def main():
# obj = doc.GetActiveObject()
# obj_a = doc.SearchObject('B_extrude')
# obj_b = doc.SearchObject('U_extrude')


sel_obj = doc.GetActiveObjects(2)
driver_obj = sel_obj[0]
driven_obj = sel_obj[1:]


for driven in driven_obj:
dup_obj = driver_obj.GetClone()
x_pos = driven[c4d.ID_BASEOBJECT_ABS_POSITION,c4d.VECTOR_X]
y_pos = driven[c4d.ID_BASEOBJECT_ABS_POSITION,c4d.VECTOR_Y]
z_pos = driven[c4d.ID_BASEOBJECT_ABS_POSITION,c4d.VECTOR_Z]
name = driven.GetName()

dup_obj.SetName(name)
dup_obj[c4d.ID_BASEOBJECT_ABS_POSITION,c4d.VECTOR_X] = x_pos
dup_obj[c4d.ID_BASEOBJECT_ABS_POSITION,c4d.VECTOR_Y] = y_pos
dup_obj[c4d.ID_BASEOBJECT_ABS_POSITION,c4d.VECTOR_Z] = z_pos

dup_obj_children = dup_obj.GetChildren()

for child in dup_obj_children:
child.Remove()

driven_children = driven.GetChildren()

for child in driven_children:
child_dup = child.GetClone()
child_dup.InsertUnder(dup_obj)

doc.InsertObject(dup_obj)
c4d.EventAdd()


if __name__ == '__main__':
main()