Get GUIDs of Objects from the Document

I wanted to try and do a script which would report the layer locations of hidden objects in the document. I apparently have 120 locked/hidden in show selected, which is slowing down my document down when I run the command.

I couldn’t find anything in the python API

I know I’ll need rs.IsObjectHidden and rs.IsObjectLocked. Still counting down to my actual Python course in February…

Edit: Will AllObjects take into account locked and hidden objects?


1 Like

all = rs.AllObjects()

hidden = []
layernames = []

for i in all:
    testhidden = rs.IsObjectHidden(i)
    if testhidden is True:
        testhidden = False

for i in hidden:
    layername = rs.ObjectLayer(i)
    print layername

When I print the lists, I get the “System GUID at … etc” prefix. So I can still make the data output clearer.

Seems to be more or less OK. I don’t get the “System GUID at…” here though when I print, just the name.

You can shorten your script considerably though (unless you want the intermediate results as well):

import rhinoscriptsyntax as rs

all_objs = rs.AllObjects()
layernames = set()

for obj in all_objs:
    if rs.IsObjectHidden(obj): layernames.add(rs.ObjectLayer(obj))

if layernames:
    for layername in layernames: print layername
    print "No hidden objects found!"

Why did I use set() for the layer names instead of a list[]? Well, if you have multiple objects hidden on the same layer, each object adds the same name to the list, so you will print the layer multiple times. Unlike a list, a set in Python is composed only of unique members, so there will be only one instance of a layer name in there even if multiple objects are hidden on the same layer. On the other hand a set is “unordered” so you cannot depend on the order the layer names will be printed like you might with a list.

Yeah that’s a lot better. I was doing quite a bit of intermediary printing to check.

all = rs.AllObjects()

hidden = []
layernames = []

for guid in all:
    testhidden = rs.IsObjectHidden(guid)
    if testhidden is True:

print "_hidden is " + str(hidden)

for l in hidden:
    layername = rs.ObjectLayer(l)

print "hidden is " + str(hidden)
print "Last layername was " + str(layername)
print str(len(layernames)) + " items, " + "Layernames are " + str(layernames)

_hidden is [<System.Guid object at 0x0000000000000229 [d2691fe2-c89f-4fad-aab5-0ee158ad02b6]>

Yep mine will still be convoluted and long winded until I get better… but thank you!