Accessing active Document

I have a custom component in GH (C#) and I am accessing the active Document in GH to do some rewiring like so:

var activeCanvas = Grasshopper.Instances.ActiveCanvas;
GH_Document doc = activeCanvas.Document;

However the activeCanvas when running this definition in RhinoCompute returns null. Is there another way to access the GH_Document while in RhinoCompute, or this is not allowed?

How are you calling the definition with your custom component? Since Rhino.Compute runs headless, there isn’t a concept of an active document on the canvas (or an active RhinoDoc for that matter).

Hey Luis thanks for answering. So I am calling the grasshopper script through Resthopper. The component happens to be on the canvas of that script.

I understand the active canvas concept is not really making sense but are there any similar objects or processes I can access to achieve the same thing?

I believe you can call OnPingDocument() function in your custom component

1 Like