algorithmic modeling for Rhino
Hi all,
I'm trying to make a custom VB component that can initialize a saving routine on the current .gh document, I want to be able to specify the path (filename).
I tried some code like the one below:
If activate Then
Dim io_util As New GH_DocumentIO(doc)io_util.SaveAs(path)
End If
""I know that the GH_DocumentIO(doc) should not be "doc" but the active GH document, but I dont know how to write that
""It seems that SaveAs doesn't take a path as parameter, probably I'm using a wrong function.
I want to make sure that the save is a SaveCopy. So I'm still working on my org document. Tks a lot for any help.
Cheers
Victor
Tags:
I found that the following script worked, but I could not specify a file name.
If activate Then
Dim io_util As New GH_DocumentIO(owner.OnPingDocument())
io_util.SaveBackup()
End If
Do I need another method to serialize the doc and write the file using a writer?
Hi Victor,
GH_DocumentIO is a wrapper class written primarily for UI use. If you want to save a document to a specific location, do this:
Dim doc As GH_Document = owner.OnPingDocument()
If (doc Is Nothing) Then Return
Dim oldPath As String = doc.FilePath
doc.FilePath = "C:\myspecialsave.gh"
Dim io As New GH_DocumentIO(doc)
io.Save()
doc.FilePath = oldPath
This will however append the document to the MRU list and it will also set the Modified flag to false.
--
David Rutten
david@mcneel.com
Barcelona, Spain
Here's how to save a document from scratch:
Dim archive As New GH_IO.Serialization.GH_Archive()
If (Not archive.AppendObject(doc, "Definition")) Then Return
archive.WriteToFile("C:\myspecialsave.gh", True, False)
You can also ask the Archive to give you the xml string or byte array in case you want to do something with the file contents right away.
--
David Rutten
david@mcneel.com
Barcelona, Spain
Thank you very much Daivd.
Both worked so well.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by