doc.Objects only Viewport dependent, does not retrieve hidden rhObj

I wanne retreive all RhinoObjects that are currently hidden in the Viewport (done via the Hide Command), but the problem is that doc.Objects cant event find those objects.

Am I using the right tool, here?

The idea is, that we wanne give the user feedback, about objects that are hidden and have UserDefinedData.

This was a first test, using C#7.3:

using Rhino;
using Rhino.DocObjects;
using Rhino.Commands;
using System.Collections.Generic;

public class GetHiddenObjectGuids : Command
{
    public override string EnglishName => "GetHiddenObjectGuids";

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
        List<System.Guid> invisibleObjectGuids = new List<System.Guid>();
        List<System.Guid> allObjectsGuids = new List<System.Guid>();
        foreach (RhinoObject obj in doc.Objects)
        {
            allObjectsGuids.Add(obj.Id);

            bool isHidden = obj.IsHidden;
            bool isOnHiddenLayer = !doc.Layers[obj.Attributes.LayerIndex].IsVisible;

            if (isHidden || isOnHiddenLayer)
            {
                invisibleObjectGuids.Add(obj.Id);
            }
        }

        foreach (var guid in invisibleObjectGuids)
        {
            RhinoApp.WriteLine($"Invisible: {guid.ToString()}");
        }

        foreach(var guid in allObjectsGuids)
        {
            RhinoApp.WriteLine($"Not Invisible: {guid.ToString()}");
        }

        return Result.Success;
    }
}

Hi @Benterich,

Use a ObjectEnumeratorSettings object.

SampleCsObjectEnumerator.cs

ā€“ Dale

1 Like

That worked amazing! Thank you I didnt know about it :)!

This is how I updated it for anyone who is interested:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    var settings = new Rhino.DocObjects.ObjectEnumeratorSettings
    {
        HiddenObjects = true, 
        LockedObjects = false, 
        NormalObjects = true,  
    };

    var objectList = doc.Objects.GetObjectList(settings);

    List<System.Guid> invisibleObjectGuids = new List<System.Guid>();
    List<System.Guid> allObjectsGuids = new List<System.Guid>();

    foreach (RhinoObject obj in doc.Objects)
    {
        allObjectsGuids.Add(obj.Id);
    }

    foreach (RhinoObject obj in objectList)
    {
        invisibleObjectGuids.Add(obj.Id);
    }

    // Print the results
    foreach (var guid in invisibleObjectGuids)
    {
        RhinoApp.WriteLine($"Invisible: {guid.ToString()}");
    }

    foreach (var guid in allObjectsGuids)
    {
        if (!invisibleObjectGuids.Contains(guid))
        {
            RhinoApp.WriteLine($"Not Invisible: {guid.ToString()}");
        }
    }

    return Result.Success;
}