Solved IsolateObjects question

I want to store an object and its children into a external file using following script.

import c4d
from c4d import gui

# Main function
def main():

    sel = doc.GetSelection()
    newDoc = c4d.documents.IsolateObjects(doc, sel)
    
    c4d.documents.SaveDocument(newDoc, "isolated_objects.c4d", 0, c4d.FORMAT_C4DEXPORT)
    c4d.EventAdd

# Execute main()
if __name__=='__main__':
    main()

However, if I try to export following object with its children (I selected all objects manually),
d16f92ec-ea20-47b7-aeba-3d7fb6e21207-image.png

the hierarchy is not correct and also the original objects are in the scene file?
903bdf6f-458e-42ae-bc06-38abe4468f5e-image.png

What am I doing incorrect?
Is it because the selection is incorrect, not taking into account the hierarchy.
If so, how can I select the objects and its children withthe correct hierarchy?

-Pim

Hi,

sel = doc.GetSelection()

BaseDocument.GetSelection() will return all selected materials, tags and objects. Unless this was an intentional choice, BaseDocument.GetActiveObjects() would be a more appropriate choice.

newDoc = c4d.documents.IsolateObjects(doc, sel)

You are passing here sel to IsolateObjects() as the argument of the objects to be isolated. Since you selected your whole scene graph this will result in this somewhat self-recursive output you have encountered. Copying Cube from your example also means copying all its descendants (Bend, Cylinder, Sphere and Cone). If you also pass all descendants it will result in the output shown above. So, if you just want to get a copy of Cube and all its children, you just need to select Cube and execute (op is predefined as the selected object) the following:

new_doc = c4d.documents.IsolateObjects(doc, op)

Cheers
zipit

MAXON SDK Specialist
developers.maxon.net

hello,

this is related to that thread i guess. (I also added element there)

As @zipit said, all the selected element are passed to the isolate function, so that's the result you have. All element and their children isolated one by one.

You have to only call isolate on the cube.

Cheers,
Manuel

MAXON SDK Specialist

MAXON Registered Developer

@zipit Thanks, just selecting the cube works.
One remark using op will give you an error "TypeError: 'c4d.BaseObject' object is not iterable".

So, just select the cube and

sel = doc.GetSelection()

will do the trick.

@m_magalhaes Yes, it is related to the other thread, but let's continue there.

@pim said in IsolateObjects question:

@zipit Thanks, just selecting the cube works.
One remark using op will give you an error "TypeError: 'c4d.BaseObject' object is not iterable".

So, just select the cube and

sel = doc.GetSelection()

will do the trick.

Hi,

sorry, my bad, that was a typo, IsolateObjects() expects a list of BaseObjects. So the the the correct call would be:

new_doc = c4d.documents.IsolateObjects(doc, [op])

Cheers
zipit

MAXON SDK Specialist
developers.maxon.net

Aha, thanks.