Showing hidden objects not working correctly

Hey there,

I want to hide certain objects in my file…

foreach (var obj in RhinoDoc.ActiveDoc.Objects)
{
    if (show_case == true)
    {
        RhinoDoc.ActiveDoc.Objects.Hide(obj, true);
    }
    else
    {
        RhinoDoc.ActiveDoc.Objects.Lock(obj, true);
    }
}
Rhino.RhinoDoc.ActiveDoc.Views.Redraw();

So far this is working (no idea if this is the most elegant way though.
But when I want to show them again here:

foreach (var obj in RhinoDoc.ActiveDoc.Objects)
{
    if (show_case == true)
    {
        RhinoDoc.ActiveDoc.Objects.Show(obj, true);
    }
    else
    {
    RhinoDoc.ActiveDoc.Objects.Unlock(obj, true);
    }
}
Rhino.RhinoDoc.ActiveDoc.Views.Redraw();

Unlocking them is working perfectly fine.
Showing them is not working at all!

What am I missing here?

Thanks in advance,
T.

Hi Tobias,

From what I’m aware of, RhinoDoc.ActiveDoc.Objects only returns visible objects of the document.

You may want to use GetObjectList() method instead. The following should work:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
	var settings = new ObjectEnumeratorSettings();
	settings.ActiveObjects = true;
	settings.NormalObjects = true;
	settings.HiddenObjects = true;
	settings.LockedObjects = true;
	settings.ObjectTypeFilter = ObjectType.AnyObject;

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

	foreach (var obj in objects)
	{
		RhinoApp.WriteLine(obj.Id.ToString());

		// Set objects visibility to true and commit changes
		obj.Attributes.Visible = true;
		obj.CommitChanges();
	}

	doc.Views.Redraw();
	
	return Result.Success;
}
1 Like

hi @jeffoulet,
that’s it.
I tried to take a look at IsHidden() to find out what is wrong and I only got back false.
This explains a lot now, as only visible objects are retruned in the ObjectTable.

Thanks a lot!
T.