Python: How to find all groups?

Hi…,

how to find and traverse all groups with Python?

group = sc.doc.Objects.FindByGroup(number)

I play with FindByGroup(number), but what is number? 0,1,2,3 or 0, 2, 4,5, when groups where deleted?

Thanks

Michael
www.flexiCAD.com

Hi…,

now I try this:

groupNames = rs.GroupNames()
for groupName in groupNames:
    objects = rs.ObjectsByGroup( groupName )
    if ( objects ):
        print( groupName )
        for object in objects:
            if ( rs.IsPolyCurve( object ) ):
                print( object )

rs.IsPolyCurve( object ) gives me the error “unable to convert c015cf83-ccbc-40b5-a1b9-5bae6e2ffc8e into Curve geometry”.

Why rs.IsPolyCurve( object ) isn’t working?

Thanks

Michael
www.flexiCAD.com

Looks like you need to ensure your only calling IsPolyCurve with curve objects, or wrap the call in a try/except block. You’ll probably also want to check for the no-group situation, and the empty/deleted group case.

Pre-filter version:

groupNames = rs.GroupNames()
for groupName in groupNames:
    objects = rs.ObjectsByGroup( groupName )
    if ( objects ):
        print( groupName )
        for object in objects:
            if rs.ObjectType(object) != rs.filter.curve:
                print "Skipping non curve object"
                continue
            if ( rs.IsPolyCurve( object ) ):
                print( object )

Try/except version:

groupNames = rs.GroupNames()
for groupName in groupNames:
    objects = rs.ObjectsByGroup( groupName )
    if ( objects ):
        print( groupName )
        for object in objects:
            try:
                if ( rs.IsPolyCurve( object ) ):
                    print( object )
            except:
                print "Skipped unusable object."          
1 Like

Hi mgi,

I didn’t know that I have to precheck an object for geometry, I thought rs.IsPolyCurve() does this too.

With your code it works here very nicely.

Thank you very much

Michael
www.flexiCAD.com