Memorize objects for easily finding in a later command/session?

If I have a file with 500 objects, and I use a command to set the Attribute user text of 15 objects. Is there a way to store the guid’s of those objects somewhere within the file so that I can access them easily in a later stage?
Let’s say I in a new rhino session want to set attribute user texts to other objects, is there a way that I can immediately call a group of guid’s (which I created earlier) and lock them without having to loop through all objects and check if they have attribute user text?
I was thinking of creating a reference layer with point objects that contain different attribute user texts with all the GUID’s written in there but I’m thinking there must be a built-in way of doing this?

Hoi Siemen

Are you concerned about the time it takes to find these objects again?

I think it should not be much of a delay:

import rhinoscriptsyntax as rs
import time

stime = time.time()

found = []
for id in rs.AllObjects():
    if rs.GetUserText(id,'should_be_locked') == 'yes':
        found.append(id)

etime = time.time()

rs.LockObjects(found)

print 'searched {} objects in {} sec'.format(len(rs.AllObjects()), etime-stime)

resulted in a file with 495 parts:
searched 495 objects in 0.0109710693359 sec

and a larger file I’m working on atm:
searched 79048 objects in 1.01530456543 sec

-Willem

PS you could store a comma delimited string as a documentusertext and split it to retrieve the ids again:

import rhinoscriptsyntax as rs


ids = rs.GetObjects()
all_string = ','.join([str(id) for id in ids])
rs.SetDocumentUserText('my_stored_ids', all_string)

read_string = rs.GetDocumentUserText('my_stored_ids')
read_ids = read_string.split(',')
rs.FlashObject(read_ids)
rs.FlashObject(read_ids)

Hey Willem!

I would think it have more of an impact on the calculation speed in comparison to your results, yes. But it was also a bit of a general question out of curiosity. Thanks a lot (again) for your examples!

1 Like