Deleting Rhino objects during solution time

How would I delete objects in RhinoDoc and not break GH?
I have pipeline components getting objects on layers and I’d like to use GhPy
to delete objects by layer. It would generate an error saying the guid is no longer available during solution.

This is a new question… I’ll move it to a new thread.

The simple answer is that you cannot delete referenced Rhino objects during a Grasshopper solution (within SolveInstance(), or RunScript()). You can however do that outside the solution time. For example, in the def OnClicked(self, obj, args): method mentioned in the original thread:

In general, it would be best to only delete non-referenced objects.
@DavidRutten could have more info regarding this.

1 Like

In original post, OnClick() has a nested method Update(), which called ExpireSolution() at the end. Does it mean I have to find all my pipeline components and call ExpireSolution() on them?

If you delete a referenced object, the changes of which are being listened to, that deletion should trigger the update by itself. I didn’t write the Pipeline, so I am interpreting @DavidRutten’s coding intentions.

Just starting to understand the OnClick() a little more. It’s only run upon clicking the context menu on the component.
For my case I can’t really trigger the OnClick() by an input into the component, can I? That would be in the RunScript(), therefore re-run GH solution.

No, you can’t. Just as you said, by design, an input change will raise a recalculation. There are some ways to circumvent it but it’s against GH’s philosophy.

Possibly, possibly not. I do respond immediately to all Rhino object events but I don’t start expiring stuff or triggering new solution until the RhinoDoc.EndOpenDocument or Command.UndoRedo events fire.

So if you start making changes to the Rhino document outside a command or an undo block, there will not be an automatic update in GH.