Skip to main content

get_all_objects_crawl_objects

import c4d

def crawl_and_collect_objects(obj, object_list, depth=0):
# Add the current object to the list
object_list.append(obj)

# Recursively process the children
child = obj.GetDown()
while child:
crawl_and_collect_objects(child, object_list, depth + 1)
child = child.GetNext()

def main_2():
# Get the active document
doc = c4d.documents.GetActiveDocument()

if doc is None:
return

# Get the active object (root of the hierarchy)
active_object = doc.GetActiveObject()

if active_object is None:
return

# Initialize an empty list to store objects
object_list = []

# Collect objects in the hierarchy
crawl_and_collect_objects(active_object, object_list)

# Print the collected object names
print("Collected Objects:")
for obj in object_list:
print(obj.GetName())

cube = c4d.BaseObject(c4d.Ocube)
cube.InsertUnder(obj)

doc.InsertObject(cube)

c4d.EventAdd()


def main():

obj_list = doc.GetActiveObjects(1)

for obj in obj_list:
cube = c4d.BaseObject(c4d.Ocube)
cube.InsertUnder(obj)

doc.InsertObject(cube)

c4d.EventAdd()

if __name__=='__main__':
main()