GH - FileName & Path to currently open model + save mesh -> .obj


#1

From a GH component, how can I find the FileName or Filepath?

From GrassHopper I can access the GH file like so:

Print(Grasshopper.Instances.ActiveCanvas.Document.FilePath)

but what about the Rhino Model FilePath?

Print(Rhino....??? )

Edit:
Also, I want to save one mesh out of multiple meshes in a .3dm file into a separate .obj file, how can that be done from a GH component?

// Rolf


(David Rutten) #2

Rhino.RhinoDoc.ActiveDoc.Path Although ideally you wouldn’t use ActiveDoc but get a reference to the relevant document. The same is true (even more so) for ActiveCanvas.Document. ActiveCanvas may be null or disposed, and Document may be null as well. Furthermore Grasshopper on Windows may maintain a lot of documents at the same time, whereas Rhino for windows only ever has one.

You can get the document associated with any given component using the OnPingDocument() method. If this method returns null, the object is not associated with a document.


#3

OK, so if I start Rhino from a batch file, and then let Rhino scan a folder full of meshes (say; “c:\jobs\meshes*.obj”) and save them into sub folders or with new filenames, and when done, then close down Rhino, how do I do that safely?

I would have another instance of Rhino running at the same time.

// Rolf


(David Rutten) #4

I don’t know much about Rhino automation, I’ll change the category to Rhino instead of Grasshopper so someone who does know will see it more readily.