FindByUserString


#1

Hi,

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)
sc.doc.Objects.UnselectAll()
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"
rg.Brep.SetUserString(geo_brep,key,value)
getstring = rg.Brep.GetUserString(geo_brep,key)
arrObj = sc.doc.Objects.FindByUserString(key,value,False,False,True,Rhino.DocObjects.ObjectType.AnyObject)
sc.doc.Views.Redraw()

Main()


#2

try this:

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

does this work?


#3

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


#4

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 ?


#5

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


#6

@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:


#7

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…


#8

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


#9

No, no way.


#10

@Dale,

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.

c.


(Dale Fugier) #11

@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


#12

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)
    
DoSomething()

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.

c.


(Dale Fugier) #13

Hi @clement,

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

https://mcneel.myjetbrains.com/youtrack/issue/RH-38915

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


#14

Thanks Dale, i’ll try to write that.

c.


(Brian Gillespie) #15

RH-38915 is fixed in the latest WIP