I have a problem. When I try to use the FindByUserString Command, it doesn’t find the Objects. I can set and get the UserString Data. Is it a bug or am I doing it wrong.

Here is the code:

import System
import copy
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino.Geometry as rg
import Rhino.Input as ri
import Rhino.DocObjects as rd
import time
import math
import random

def Main():
rc, brep_ref = ri.RhinoGet.GetOneObject(“Select obj to write”, False, Rhino.DocObjects.ObjectType.Brep)
if rc <> Rhino.Commands.Result.Success or brep_ref == None:
return rc
obj_brep = brep_ref.Object()
geo_brep = obj_brep.Geometry
key = "01"
value = "A"
getstring = rg.Brep.GetUserString(geo_brep,key)
arrObj = sc.doc.Objects.FindByUserString(key,value,False,False,True,Rhino.DocObjects.ObjectType.AnyObject)


try this:

    enum = rd.ObjectEnumeratorSettings()
    arrObj = sc.doc.Objects.FindByUserString(key, value, False, False, True, enum)

does this work?

@jordy1989 No unfortunately this doesn’t work either. Looks like there is a hidden bug.

I’m curious to know what is going on here …
I too am unable to find objects with data attached to geometry.
Only data attached to attributes are found …

BTW … shouldn’t the flags in the method call be

False, True, False

in order to look for data attached to geometry ?

@emilio @jordy1989 Yes the flags were wrong, but even then it doesn’t work. :frowning:

@emilio @jordy1989 So does the code work for you or is the non working FindByUserstring really a bug?
I still hope you can help me. :slight_smile:

No I can’t get it to work either :frowning:

Else you have to loop through all objects and getvalue(key) and check if the value matches…

@jordy1989 I know, but that’s rather slow and not really beautiful. :disappointed_relieved:

No, no way.


i am running into above problem using V5 SR12, FindByUserString does not find any key or value attached to geometry. I’ve read that there where fixes in regard to UserData in SR13, do they cover above problem ?

If i am forced to attach my UserText to attribute, it will remain if eg. an object is exploded which is a potential risk in the downstream.


@clement does this work in the Rhino WIP? Can you provide a simple code block that isn’t working for you?

I’m not seeing any changes, with this function, between SR12 and SR13.

– Dale

Hi @dale,

no it fails in the Rhino WIP and in Rhino 5 SR12. Below is some sample code and a sample object. The object in the file got user text key="Rhino" and val="SR12" which was assigned to “Object” not “Attributes”.

import Rhino
import scriptcontext as sc
def DoSomething():
    key = "Rhino"
    val = "SR12"
    filter = Rhino.DocObjects.ObjectType.AnyObject
    rc = sc.doc.Objects.FindByUserString(key, val, False, True, False, filter)
    print "Found {} objects".format(rc.Count)

TestObject.3dm (43.1 KB)

I have to make it work in V5, V6 and on Mac but i guess there is no chance to get this done in V5 which is the clients main platform.


Hi @clement,

I can see where the function is failing - it’s an easy fix that I can make in the WIP.

As for Rhino 5, its possible to write your own “FindByUserString” function. You just need to iterate the document and look for what you want, unfortunately. Let me know if you want help writing such a deal.

– Dale

Thanks Dale, i’ll try to write that.


RH-38915 is fixed in the latest WIP