rs.ObjectsByType - state filter not working for Locked and Hidden objects

I cannot get locked or hidden objects using ObjectsByType.

I have some normal objects, some locked, some hidden, some locked and hidden.

According to the documentation, a state parameter of 2 or 4 should only select Hidden or Locked objects. However, no objects are selected.

print(len(rs.ObjectsByType(0, select = False, state = 2))) -> outputs 0
print(len(rs.ObjectsByType(0, select = False, state = 4))) -> outputs 0

Using state = 0 selects all objects, and state = 1 only normal objects, as expexted.

I noticed that in the documentation, the state parameter is defined as a boolean, this might be the issue?

Hi @RobinB,

It looks like the function is taking the object’s state (normal, locked, hidden) into account, and not looking to see of the object is on a layer that is locked or hidden.

An alternative to using the rhinoscriptsyntax function is to go straight to RhinoCommon and use the ObjectTable.GetObjectList method and then filter on the state after the fact.

For example:

import Rhino
import scriptcontext as sc

def GetHiddenCurveObjects():
    rc = []
    settings = Rhino.DocObjects.ObjectEnumeratorSettings()
    settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Curve
    settings.IncludeLights = False
    settings.IncludeGrips = False
    settings.NormalObjects = True
    settings.LockedObjects = True
    settings.HiddenObjects = True
    settings.ReferenceObjects = False
    for rh_obj in sc.doc.Objects.GetObjectList(settings):
      if rh_obj.IsHidden:
        rc.append(rh_obj)
    return rc
    
crv_objs = GetHiddenCurveObjects()
print(len(crv_objs))

– Dale

Thanks, in that case i will use IsLayerLocked and IsLayerOn to filter the layers that I need