Looping through selection tags [SOLVED]

On 02/05/2016 at 01:34, xxxxxxxx wrote:

Hi everyone,

I am currently getting obj files of many objects. Sadly if I am importing them into cinema 4d, I am getting one polygon object with lots of selection tags. Each selection tag represents one piece of the model and I need them separated into single objects. So I thought I could write a python script and loop through all the selection tags and then separate them.

I found this thread here, which is actually doing, what I want to do, but building the parts into my own script doesn't really work and I am not sure, wich parts I need and which not. As for example I don't need to compare the names, but only the type


That's what I have so far. I now it is not very much 😢

import c4d
from c4d import gui
#Welcome to the world of Python

def main() :
    mydoc = c4d.documents.GetActiveDocument()
    myobj = doc.GetActiveObject()
    t = myobj.GetFirstTag()
    while t:
        if t.GetType() == c4d.Tpolygonselection:
            tagselection = t.GetBaseSelect()
        t = t.GetNext()

if __name__=='__main__':

Currently it is only separating the whole object but not the polygons in the single selection tags. But I think it is going through all the selection tags, as I am currently testing it with a cube, which has 6 selection tags and I am getting 6 copies.

So why is it not making the new objects from the selection tag? Has anyone an idea? I thought the GetBaseSelect() would activate the polygon selection in the selection tag, wouldn't it?

Would be great if someone could give me some hints into the right direction.


On 03/05/2016 at 01:25, xxxxxxxx wrote:


you loop through all the tags and you call the "Split" command. But you don't tell the "Split" command what to do.

The "Split" command works with the current selection of the object. You don't set this selection, you just access the selection stored in the selection tag (and this does nothing).

So you have to access the selection stored in the selection tag and copy that selection onto the object. You can then access the selection of the PolygonObject with GetPolygonS(). Now you can copy the selections. You find an example in this thread: "Select polygons from Selection Tag"

best wishes,

On 09/05/2016 at 02:48, xxxxxxxx wrote:

Hi Sebastian,

thanks a lot for your reply and the explanations. It's now making sense and I am understanding how it is working.

Thank you very much for your help