Get name of hidden object

Is there a way to get the name of an object, if it is hidden? This code, along with the blah, blah, works if the hull is visible, but not if it is hidden.

            foreach (var or in doc.Objects) 
            {
                if (or.Attributes.Name.ToString().ToUpper() == "HULL")
                {
                    var orID = or.Id.ToString();
                    .
                    .
                    .
                    HullIsNamed= true;
                }
            }
            if (!HullIsNamed)
            {
                MessageBox.Show("Your hull surface/polysurface must be named 'HULL'. \n\r Please correct and try again");
                return Result.Failure;
            }

Hi @cestes001,

Use ObjectTable.FindByFilter.

import Rhino
import scriptcontext as sc

def test_findbyfilter():
    # Construct enumerator settings
    settings = Rhino.DocObjects.ObjectEnumeratorSettings()
    settings.NormalObjects = True
    settings.HiddenObjects = True
    settings.ActiveObjects = True
    settings.ReferenceObjects = True
    
    # Find the objects
    rh_objects = sc.doc.Objects.FindByFilter(settings)
    if not rh_objects or len(rh_objects) == 0:
        print("No objects found.")
        return
    
    for rh_obj in rh_objects:
        if rh_obj.ObjectType != Rhino.DocObjects.ObjectType.Brep:
            continue
        name = rh_obj.Attributes.Name
        if not name:
            name = "<unnamed>"
        print("Name: {0}, Hidden: {1}".format(name, rh_obj.IsHidden))
    
if __name__ == "__main__":
    test_findbyfilter()

– Dale

1 Like

Thx, Dale. What language is that?

Python

Does anyone have an example in c#? I’m afraid I’'m python illiterate.

Not that much difference, honestly.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  // Construct enumerator settings
  var settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
  settings.NormalObjects = true;
  settings.HiddenObjects = true;
  settings.ActiveObjects = true;
  settings.ReferenceObjects = true;

  // Find the objects
  var rh_objects = doc.Objects.FindByFilter(settings);
  if (null == rh_objects || 0 == rh_objects.Length)
  {
    RhinoApp.WriteLine("No objects found.");
    return Result.Success;
  }

  foreach (var rh_obj in rh_objects)
  {
    if (rh_obj.ObjectType != Rhino.DocObjects.ObjectType.Brep)
      continue;

    var name = rh_obj.Attributes.Name;
    if (string.IsNullOrEmpty(name))
      name = "<unnamed>";
    RhinoApp.WriteLine("Name: {0}, Hidden: {1}", name, rh_obj.IsHidden);
  }

  return Result.Success;
}

– D

1 Like

Thx, Dale. Perhaps, in my next life, I’ll learn python. :slight_smile: