Get all components in the document that have Preview Off

Is there a way to filter a list of document objects by whether they are on/off? So doc.Objects() returns a list of IGH_DocumentObject and since this is an interface, we don’t have access to Hidden property. I would hate to try and cast all of these interfaces into concrete types. Any easier way that I can get at the Hidden property?

Ps. I know I can use Reflection like so: (bool) x.GetType().GetProperty("Hidden")?.GetValue(x, null) but it somehow feels dirty.



The Hidden property comes from the IGH_PreviewObject interface so with Linq you can do doc.Objects.OfType<IGH_PreviewObject>().Where(o => o.Hidden);

1 Like

That works. Thanks!