Select Group Code Only

Is there a way to select a group by name with code only. I do not want to pick from a dialogue box. I have the names and want to select with python code only.

Thanks

Eric

Hi @eric.bunn, you might try below:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def SelGroupName(group_name=None):
    
    group = scriptcontext.doc.Groups.FindName(group_name)
    if not group: return
    
    for rh_obj in scriptcontext.doc.Groups.GroupMembers(group.Index):
        if rh_obj.IsSelectable(): rh_obj.Select(True, True)
    
    scriptcontext.doc.Views.Redraw()
    
SelGroupName("Group03")

_
c.

I should have mentioned that I am running Rhino 5. I’m getting this error when I run the script:

Message: ‘GroupTable’ object has no attribute ‘FindName’

Traceback:
line 8, in SelGroupName, “C:\Temp\TempScript.py”
line 16, in , “C:\Temp\TempScript.py”

Thanks,

Eric

Well, if you are willing to use rhinoscriptsyntax and you know the group name, you can use simply:

import rhinoscriptsyntax as rs
objs=rs.ObjectsByGroup(groupname,True)

I’ll try that. Thank you.

Eric.

This worked for me thanks.