private void LoadGhDocument() { if (content.type != TaskContentType.file) { return; } string file = content.value; if (!File.Exists(file)) { ErrorEvent(this, "Work file is not exist!"); return; } GH_DocumentIO io = new GH_DocumentIO(); io.Open(file); GH_Document doc = GH_Document.DuplicateDocument(io.Document); if (doc == null) { ErrorEvent(this, "Cannot read this file!"); return; } GH_DocumentServer server = Instances.DocumentServer; if (server == null) { ErrorEvent(this, "No Document Server exist!"); return; } server.AddDocument(doc); doc.Properties.ProjectFileName = ID.ToString(); GH_Canvas activeCanvas = Instances.ActiveCanvas; if (activeCanvas == null) { ErrorEvent(this, "No Active Canvas exist!"); return; } activeCanvas.Document = doc; activeCanvas.Document.IsModified = false; activeCanvas.Refresh(); // SolutionEndCnt = 0; doc.SolutionEnd += Doc_SolutionEnd; UpdateData(true); }
private void LoadGhDocument(string file) { if (!System.IO.File.Exists(file)) { return; } GH_DocumentIO io = new GH_DocumentIO(); io.Open(file); GH_Document doc = GH_Document.DuplicateDocument(io.Document); if (doc == null) { return; } GH_DocumentServer server = Instances.DocumentServer; if (server == null) { return; } server.AddDocument(doc); doc.Properties.ProjectFileName = ID.ToString(); GH_Canvas activeCanvas = Instances.ActiveCanvas; if (activeCanvas == null) { return; } activeCanvas.Document = doc; activeCanvas.Document.IsModified = false; activeCanvas.Refresh(); doc.SolutionEnd += Doc_SolutionEnd; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { string D = ""; if (!DA.GetData(0, ref D)) { return; } string F = ""; if (!DA.GetData(1, ref F)) { return; } bool S = false; DA.GetData(2, ref S); GH_Document ghDoc = null;// = Grasshopper.Instances.ActiveCanvas.Document; try { ghDoc = OnPingDocument(); } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Document not found"); } if (ghDoc == null || !ghDoc.IsFilePathDefined) { return; } GH_DocumentIO docIO = new GH_DocumentIO(GH_Document.DuplicateDocument(Grasshopper.Instances.ActiveCanvas.Document)); string path, file; int nameLen = ghDoc.DisplayName.TrimEnd('*').Length + 3; // +3 accounts for the '.gh' extension missing here int fileLen = ghDoc.FilePath.TrimEnd('*').Length; if (D == "" || D == null) { path = ghDoc.FilePath.Substring(0, fileLen - nameLen); } else { path = D; } if (F == "" || F == null) { file = ghDoc.DisplayName.TrimEnd('*') + ".gh"; } else { file = F + ".gh"; } docIO.Document.FilePath = path + file; if (S) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } docIO.Save(); } DA.SetData(0, docIO.Document.FilePath); }