Proper access of Rhino Objects from GrassHopper?

OK, so when I try to list the Rhino objects from a grasshopper component SolveInstance method (using C#), I see a “warning” text in the mouseover help text, suggesting that I do not use ActiveDoc to retrieve Rhino objects.

foreach (... Rhino.RhinoDoc.ActiveDoc.Objects.GetObjectList(ObjectType.Mesh))

What is the recommended safe way to list Rhino objects?

// Rolf

ActiveDoc is problematic because Rhino on Mac is multi-document capable, and quite possibly future versions of Rhino for Windows will be as well. So if your code is executing within the context of some specific document, using ActiveDoc may give you the wrong document.

However this document context is typically only provided to you when you’re writing Rhino Command plug-ins. From within Grasshopper, you have little choice but to use this dangerous method.

OK, I will have to use it then.

In cases where this would be risky, is it possible to check if there are multiple documents open?

// Rolf

Yup, RhinoDoc.OpenDocuments(). Never used that method in my life, but I think that’s what it’s for.

1 Like

Ah, there it was. Thanks.

// Rolf