Grasshopper/Rhino SDK - How does one get the name of the current open file from an External Application?

Hello,

I do know how to use the COM interfaces to manipulate Rhino and also how to get the the Grasshopper plugin COM interface so that I can manipulate Grasshopper.

I would like to know if there is any way using this method to get the name of the file that is currently open in Grasshopper - not in Rhino.

I am also comfortable to create my own Rhino plugin so that I can use it to get this information.

But, for that, I would have to know how one can get the Grasshopper filename of the currently open document from within Rhino. (I know that you can call Rhino functions from a Grasshopper custom component, but I don’t know if it is possible to do the other way around).

Thank you for the assistance!

I guess you’re looking for Grasshopper.Instances class:

import Rhino
import clr
clr.AddReferenceByName("Grasshopper")
import Grasshopper

gh = Rhino.RhinoApp.GetPlugInObject("Grasshopper")
if not gh.IsEditorLoaded():
    print "Grasshopper editor is not loaded"
else:
    for doc in Grasshopper.Instances.DocumentServer.Document:
        print doc

If you only want to get the active document you can use:

Grasshopper.Instances.ActiveCanvas.Document

GrasshopperDocuments.py (301 Bytes)

1 Like

Hello!

Thank you so much. I did manage to put this inside a function of my custom COM plugin.
This function runs within Rhino, gets the data and then transmits to my client application.

Thank you again.