How to save .gh file directly from python component?

Hi All,
I wonder if it’s possible to save a .gh file (with custom filename in a pre-selected dir) directly from gh python component.

Thank you in advance for all your tips.

1 Like

Save the file you’re in? Or some file you made up on the spot?

Either way the best way forward is probably the GH_DocumentIO class. It allows you to save and read memory and file based documents.

Thank you David,

I mean the file I am in and perform from gh python component the script that executes this command:
01

Yeah, GH_DocumentIO is what you need. Don’t know how it would look in python, but in C# the code is like this:

      var io = new GH_DocumentIO(GrasshopperDocument);
      io.SaveAs();
2 Likes

Something like this should do it:

import Grasshopper as gh
io = gh.Kernel.GH_DocumentIO(ghenv.Component.OnPingDocument())
io.SaveAs()
2 Likes

Perfect! Thank you so much, David and Anders.
I will try!