private DataTree <object> SolutionTrigger() { DataTree <object> dataTree = null; GH_Document doc = m_document; if (doc == null) { throw new Exception("File could not be opened."); } doc.Enabled = true; doc.NewSolution(true, GH_SolutionMode.Silent); GH_ClusterOutputHook[] outputs = doc.ClusterOutputHooks(); dataTree = new DataTree <object>(); var hint = new GH_NullHint(); dataTree.MergeStructure(outputs[0].VolatileData, hint); doc.Dispose(); return(dataTree); }
private void AdjustPackageOutput() { if (m_document != null) { GH_ClusterOutputHook[] outputs = m_document.ClusterOutputHooks(); for (int i = 0; i < outputs.Length; i++) { Params.RegisterOutputParam(CreateParameter(GH_ParameterSide.Output, i)); GH_ClusterOutputHook outputHook = outputs[i]; //outputHook.Sources Params.Output[0].NickName = outputHook.NickName; } outputAdjusted = true; } }
private void StoreOutput() { DebugEvent("Start Store Output"); GH_DocumentServer doc_server = Instances.DocumentServer; if (doc_server == null) { throw new Exception("No Document Server exist!"); } GH_Document doc = doc_server.ToList().Find(x => x.Properties.ProjectFileName == ID.ToString()); if (doc == null) { throw new Exception("Tasker 未找到GH_Document"); } if (string.IsNullOrEmpty(workspace) || string.IsNullOrEmpty(ticket)) { throw new Exception("工作目录和Ticket为空"); } string outDir = Path.Combine(taskspace, ID.ToString(), ticket); var hooks = doc.ClusterOutputHooks(); if (hooks == null) { return; } foreach (var hook in hooks) { string info = hook.CustomDescription; if (string.IsNullOrEmpty(info)) { continue; } var paraMap = ConvertUrlParam(info); if (!paraMap.TryGetValue("Index", out string index) || !paraMap.TryGetValue("Type", out string type)) { continue; } DebugEvent($"Index: {index}; Type: {type}"); string fileName = Path.Combine(outDir, index + "@" + DateTime.Now.ToString("HH-mm-ss MM-dd")); var volatileData = hook.VolatileData; if (volatileData.IsEmpty) { continue; } dynamic content = null; switch (type) { case "CSV": { var allData = volatileData.AllData(true); List <string> sList = new List <string>(); allData.ToList().ForEach(el => { GH_Convert.ToString(el, out string tmp, GH_Conversion.Both); sList.Add(tmp); }); string csv = string.Join(Environment.NewLine, sList); fileName += ".csv"; File.WriteAllText(fileName, csv, Encoding.UTF8); content = fileName; break; } case "3DM": { fileName += ".3dm"; File3dmWriter writer = new File3dmWriter(fileName); foreach (var data in volatileData.AllData(true)) { GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } string layer = obj.GetUserString("Layer"); if (layer == null) { continue; } ObjectAttributes att = new ObjectAttributes { LayerIndex = writer.GetLayer(layer, Color.Black) }; writer.ObjectMap.Add(att, obj); } writer.Write(); content = fileName; break; } case "Data": { try { GH_Structure <IGH_Goo> tree = volatileData as GH_Structure <IGH_Goo>; content = IO.SerializeGrasshopperData(tree, hook.CustomName, volatileData.IsEmpty); } catch (Exception ex) { ErrorEvent(this, ex.Message); } break; } case "EPS": { List <GeometryBase> objs = new List <GeometryBase>(); foreach (var data in volatileData.AllData(true)) { if (data == null) { continue; } GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } objs.Add(obj); } if (!Directory.Exists(fileName)) { Directory.CreateDirectory(fileName); } content = JsonConvert.SerializeObject(SaveAdobeDocument(fileName, objs, AdobeDocType.EPS)); break; } case "PDF": { List <GeometryBase> objs = new List <GeometryBase>(); fileName += ".pdf"; foreach (var data in volatileData.AllData(true)) { if (data == null) { continue; } GeometryBase obj = GH_Convert.ToGeometryBase(data); if (obj == null) { continue; } objs.Add(obj); } var res = SaveAdobeDocument(fileName, objs, AdobeDocType.PDF); if (res == null || res.Count == 0) { break; } content = res[0]; break; } case "RhinoPDF": { var pdf = FilePdf.Create(); fileName += ".pdf"; DebugEvent("RhinoPDF Begin"); foreach (var page in volatileData.AllData(true)) { DebugEvent("RhinoPDF got 1 page"); if (!page.CastTo(out RhinoPageView view)) { DebugEvent(string.Format("{0} can not convert to RhinoPageView", page.GetType())); continue; } DebugEvent("Data is converted to RhinoPage"); ViewCaptureSettings settings = new ViewCaptureSettings(view, 300) { OutputColor = ViewCaptureSettings.ColorMode.DisplayColor, RasterMode = true }; pdf.AddPage(settings); } pdf.Write(fileName); content = fileName; break; } case "DXF": { break; } default: break; } StoreEvent(this, new JObject { ["route"] = "task-stored", ["id"] = ID.ToString(), ["index"] = index.ToString(), ["type"] = type, ["content"] = content }.ToString()); } }