How to access group.GetUserString in rhino 5?

How do I iterate over a grouptable in Rhino 5?

in 6 I can just do this:

import scriptcontext as sc

groups = sc.doc.ActiveDoc.Groups

for group in groups:
    group_name = group.Name
    group_objCount = sc.doc.ActiveDoc.Groups.GroupObjectCount(group.Index)
    some_value = group.GetUserString("some_key")

but Rhino 5 throws an error that groups is non-sequence…

so then I could do something like this:

for i in range(groups.Count):
    group_name = sc.doc.ActiveDoc.Groups.Groupmembers(i)[0]
    group_objCount = len(sc.doc.ActiveDoc.Groups.GroupNames(i))

but then how to get access to GetUserString()?

Hi @Gijs,

Unlike Rhino 6, Rhino 5 does not have a Rhino.DocObjects.Group class. Thus, it’s doubtful you can get the user strings from a Group object using RhinoCommon in Rhino 5.

– Dale

Thanks @dale

Can you recommend a workaround?

Hi @Gijs,

This might do it:

import Rhino
import scriptcontext as sc

def GetGroupUserText(id, key):
    rs = Rhino.RhinoApp.GetPlugInObject("RhinoScript")
    if rs:
        return rs.GetGroupUserText(id, key)
    return None

for index in range(sc.doc.Groups.Count):
    if not sc.doc.Groups.IsDeleted(index):
        group = sc.doc.Groups.FindIndex(index)
        if group:
            value = GetGroupUserText(group.Name, "test")
            if value:
                print "Name:", group.Name, ", Value:", value

– Dale

@dale that doesn’t seem to work, as there is no FindIndex attribute of groups in Rhino 5

Try this

for index in range(sc.doc.Groups.Count):
    if not sc.doc.Groups.IsDeleted(index):
        group = sc.doc.Groups.GroupName(index)
        if group:
            value = GetGroupUserText(group, "test")
            if value:
                print "Name:", group, ", Value:", value