public override bool Write(GH_IWriter writer) { staticData.PrepareWrite(activeUnit); bool result = base.Write(writer); staticData.RestoreWrite(activeUnit); if (activeUnit != null) { writer.CreateChunk("ActiveUnit").SetString("unitname", activeUnit.Name); } try { GH_IWriter val = writer.CreateChunk("EvalUnits"); val.SetInt32("count", evalUnits.Units.Count); for (int i = 0; i < evalUnits.Units.Count; i++) { EvaluationUnit evaluationUnit = evalUnits.Units[i]; GH_IWriter writer2 = val.CreateChunk("unit", i); evaluationUnit.Write(writer2); } return(result); } catch (Exception ex) { RhinoApp.WriteLine(ex.Message + "\n" + ex.StackTrace); throw ex; } }
public bool Write(GH_IWriter writer) { writer.SetString("name", Name); GH_IWriter val = writer.CreateChunk("params"); GH_IWriter val2 = val.CreateChunk("input"); val2.SetInt32("index", 0); val2.SetInt32("count", Inputs.Count); for (int i = 0; i < inputs.Count; i++) { if (inputs[i].Parameter.Attributes != null) { GH_IWriter val3 = val2.CreateChunk("p", i); inputs[i].Parameter.Write(val3); } } GH_IWriter val4 = val.CreateChunk("output"); val4.SetInt32("index", 0); val4.SetInt32("count", Outputs.Count); for (int j = 0; j < outputs.Count; j++) { if (outputs[j].Parameter.Attributes != null) { GH_IWriter val5 = val4.CreateChunk("p", j); outputs[j].Parameter.Write(val5); } } GH_IWriter writer2 = writer.CreateChunk("context"); return(cxt.Collection.Write(writer2)); }
public override bool Write(GH_IWriter writer) { var result = base.Write(writer); writer.SetString("source", SourceUri); m_inside.Write(writer.CreateChunk("m_inconnector")); m_outside.Write(writer.CreateChunk("m_outconnector")); return(result); }
public override bool WriteFull(GH_IWriter writer) { writer.CreateChunk("key"); writer.CreateChunk("proj"); writer.CreateChunk("filterbyname"); writer.CreateChunk("filteroldone"); writer.SetString("key", myControlPanel.key); writer.SetString("proj", myControlPanel.project); writer.SetBoolean("filterbyname", myControlPanel._filterbyname); writer.SetBoolean("filteroldone", myControlPanel._filteroldone); return(base.Write(writer)); }
/// <summary> /// Write all required data for deserialization to an IO archive. /// </summary> /// <param name="writer">Object to write with.</param> /// <returns> /// True on success, false on failure. /// </returns> public override bool Write(GH_IWriter writer) { //serialize the states GH_IWriter stateSetChunk = writer.CreateChunk("stateSetChunk"); stateSetChunk.SetInt32("StateCount", savedStates.states.Count); int i = 0; //the state //for each state in saved states foreach (KeyValuePair <string, State> statePair in savedStates.states) { string stateName = statePair.Key; GH_IWriter StateChunk = stateSetChunk.CreateChunk("State", i); StateChunk.SetString("stateName", stateName); State state = statePair.Value; StateChunk.SetInt32("itemCount", state.stateDict.Count); int j = 0; //Custom serialization logic //for each element in the state foreach (KeyValuePair <UIElement_Goo, object> stateItem in state.stateDict) { //get element and value UIElement_Goo element = stateItem.Key; object value = stateItem.Value; GH_IWriter stateItemChunk = StateChunk.CreateChunk("stateItem", j); //this info is used to retrieve the dynamic UI element on reserialization, by grabbing the component with matching instance guid //and getting the output item at the matching index. stateItemChunk.SetString("ElementID", element.instanceGuid.ToString()); stateItemChunk.SetInt32("ElementIndex", element.index); string stringValue = value.ToString(); string typeString = value.GetType().ToString(); //special case for lists of bool - all other element "states" are single items. This only applies to a checklist object. if (value is List <bool> ) { typeString = "LIST OF BOOL"; stringValue = HUI_Util.stringFromBools((List <bool>)value); } if (value is List <string> ) { typeString = "LIST OF STRING"; stringValue = HUI_Util.stringFromStrings((List <string>)value); } //store the value and a hint as to its type stateItemChunk.SetString("ElementValue", stringValue); stateItemChunk.SetString("ElementValueType", typeString); j++; //counting up elements in state } i++; //counting up states } return(base.Write(writer)); }
/* * public void Dispose() * { * foreach (Mesh m in this._meshCache) * { * m.Dispose(); * } * }*/ public override bool Write(GH_IWriter writer) { base.Write(writer); try { writer.RemoveChunk("PersistentData"); writer.SetInt32("GridCount", PersistentData.DataCount); var total = 0; for (var i = 0; i < PersistentData.Branches.Count; i++) { var path = PersistentData.Paths[i]; foreach (var ghvg in PersistentData.Branches[i]) { var currentGrid = writer.CreateChunk("Grid", total); currentGrid.SetString("Data", ByteHelper.ByteToHex(ByteHelper.Compress(ByteHelper.ToByte(ghvg.Value)))); currentGrid.SetString("Path", path.ToString()); total++; } } return(true); } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e + " " + e.StackTrace); return(true); } }
private static void WriteGH_ISerializable(GH_IWriter writer, GH_ISerializable data) { writer.SetString("TypeString", data.GetType().FullName); writer.SetString("AssemblyString", data.GetType().Assembly.FullName); var objectWriter = writer.CreateChunk("Data"); data.Write(objectWriter); }
public static bool SetList(this GH_IWriter writer, string listName, List <IGH_Goo> list) { var listWriter = writer.CreateChunk(listName); var tree = new GH_Structure <IGH_Goo>(); tree.AppendRange(list); return(tree.Write(listWriter)); }
public static bool SetGoo(this GH_IWriter writer, string itemName, IGH_Goo item) { var itemWriter = writer.CreateChunk(itemName); var tree = new GH_Structure <IGH_Goo>(); tree.Append(item); return(tree.Write(itemWriter)); }
public override bool Write(GH_IWriter writer) { GH_IWriter gH_IWriter = writer.CreateChunk("Slider", Index); gH_IWriter.SetDouble("MinValue", minValue); gH_IWriter.SetDouble("MaxValue", maxValue); gH_IWriter.SetDouble("CurrentValue", currentValue); gH_IWriter.SetInt32("NumDecimals", numDecimals); return(true); }
public override bool Write(GH_IWriter writer) { GH_IWriter writer2 = writer.CreateChunk("Panel", Index); for (int i = 0; i < _controls.Count; i++) { _controls[i].Write(writer2); } return(base.Write(writer)); }
public bool Write(GH_IWriter writer) { GH_IWriter val = writer.CreateChunk("Collection"); for (int i = 0; i < _menus.Count; i++) { GH_IWriter writer2 = val.CreateChunk("Menu", i); _menus[i].Write(writer2); } return(true); }
public static void SetDictionary <T1, T2>( this GH_IWriter writer, string itemName, IDictionary <T1, T2> data, Action <GH_IWriter, string, int, T1> keySetter, Action <GH_IWriter, string, int, T2> valueSetter ) { var dataWriter = writer.CreateChunk(itemName); WriteDictionary(dataWriter, data, keySetter, valueSetter); }
/// <summary> /// Serialization works over vectors instead of Guids. Because if documentObjects and the component are copied together the /// instanceGuid will be newly assigned and the new documentObjects will not be automatically selected. /// As the distances are preserved when copying this offers a good alternative. /// </summary> public override bool Write(GH_IWriter writer) { serializedDocumentObjectPivotVectors = selectedDocumentObjects.Select(x => new GH_Point2D(Math.Round(Math.Abs(Attributes.Pivot.X - x.Attributes.Pivot.X), 4), Math.Round(Math.Abs(Attributes.Pivot.Y - x.Attributes.Pivot.Y), 4))).ToArray(); var chunk = writer.CreateChunk("SelectedDocumentObjects"); for (var i = 0; i < selectedDocumentObjects.Length; i++) { chunk.SetPoint2D($"DocumentObject{i}", serializedDocumentObjectPivotVectors[i]); } return(base.Write(writer)); }
public override bool Write(GH_IWriter writer) { GH_IWriter obj = writer.CreateChunk("RadioButtonGroup", Index); int count = _buttons.Count; obj.SetInt32("Count", count); GH_IWriter val = obj.CreateChunk("Active"); for (int i = 0; i < count; i++) { val.SetBoolean("button", i, _buttons[i].Active); } return(true); }
public override bool Write(GH_IWriter writer) { if (!base.Write(writer)) { return(false); } writer.SetBoolean("Remap", RemapToTarget); if (container != null) { GH_IWriter gH_IWriter = writer.CreateChunk("LocalGraph"); return(container.Write(gH_IWriter)); } return(true); }
public override bool Write(GH_IWriter writer) { try { GH_IWriter writer2 = writer.CreateChunk("Hoopsnake_Data"); writer2.SetInt32("dataLimit", dataLimit); writer2.SetBoolean("resetCounter", resetCounterOnLoop); writer2.SetBoolean("updateView", updateView); writer2.SetBoolean("autoUpdate", autoUpdate); writer2.SetInt32("delay", delay); } catch {} return(base.Write(writer)); }
public override bool Write(GH_IWriter writer) { writer.SetInt32("ListMode", (int)this.ListMode); writer.SetInt32("ListCount", this.m_userItems.Count); int arg_36_0 = 0; int num = this.m_userItems.Count - 1; for (int i = arg_36_0; i <= num; i++) { GH_IWriter chunk = writer.CreateChunk("ListItem", i); chunk.SetString("Name", this.m_userItems[i].Name); chunk.SetString("Expression", this.m_userItems[i].Expression); chunk.SetBoolean("Selected", this.m_userItems[i].Selected); } return(base.Write(writer)); }
public override bool Write(GH_IWriter writer) { writer.SetInt32("ListMode", (int)ListMode); writer.SetInt32("ListCount", m_userItems.Count); int num1 = 0; int num2 = m_userItems.Count - 1; for (int chunk_index = num1; chunk_index <= num2; ++chunk_index) { GH_IWriter chunk = writer.CreateChunk("ListItem", chunk_index); chunk.SetString("Name", m_userItems[chunk_index].Name); chunk.SetString("Expression", m_userItems[chunk_index].Expression); chunk.SetBoolean("Selected", m_userItems[chunk_index].Selected); } return(base.Write(writer)); }
public override bool Write(GH_IWriter writer) { int n = 0; foreach (var pair in storage) { // Create a chunk with a specific name and an increasing index. var chunk = writer.CreateChunk("StoredData", n++); // Store the dictionary name as a string on the chunk. chunk.SetString("Key", pair.Key); // Store the dictionary value in a sub-chunk. var treeChunk = chunk.CreateChunk("Tree"); pair.Value.Write(treeChunk); } return(base.Write(writer)); }
public override bool Write(GH_IWriter writer) { writer.SetInt32("ListMode", (int)this.ListMode); writer.SetInt32("ListCount", this.m_userItems.Count); int arg_36_0 = 0; int num = this.m_userItems.Count - 1; for (int i = arg_36_0; i <= num; i++) { GH_IWriter chunk = writer.CreateChunk("ListItem", i); chunk.SetString("Name", this.m_userItems[i].Name); string serializedExpression = JsonConvert.SerializeObject(this.m_userItems[i].Expression); string serializedType = JsonConvert.SerializeObject(this.m_userItems[i].Expression.GetType(), typeof(Type), new JsonSerializerSettings()); chunk.SetString("Expression", serializedExpression); chunk.SetString("Type", serializedType); chunk.SetBoolean("Selected", this.m_userItems[i].Selected); } return(base.Write(writer)); }
// Convert.FromBase64String(x) public static byte[] SerializeGrasshopperData(GH_Structure <IGH_Goo> tree, string name = "default", bool isEmpty = false) { GH_LooseChunk ghLooseChunk = new GH_LooseChunk("Noah Data"); ghLooseChunk.SetGuid("OriginId", Guid.NewGuid()); GH_IWriter chunk = ghLooseChunk.CreateChunk("Block", 0); chunk.SetString("Name", name); chunk.SetBoolean("Empty", isEmpty); if (!isEmpty) { if (!tree.Write(chunk.CreateChunk("Data"))) { throw new Exception(string.Format("There was a problem writing the {0} data.", name)); } } return(ghLooseChunk.Serialize_Binary()); }
public override bool Write(GH_IWriter writer) { int n = 0; foreach (var pair in storage) { // Create a chunk with a specific name and an increasing index. var chunk = writer.CreateChunk("StoredData", n++); // Store the dictionary name as a string on the chunk. chunk.SetString("Key", pair.Key); // Store the dictionary value in a sub-chunk. var treeChunk = chunk.CreateChunk("Tree"); //json //this.JsonStringWrite = JsonSerializer.Serialize(IsRead, this.jso); pair.Value.Write(treeChunk); } //WriteSuccess = base.Write(writer); return(base.Write(writer)); }
public override bool Write(GH_IWriter writer) { writer.CreateChunk("MenuDropDown", Index).SetInt32("ActiveItemIndex", current_value); return(true); }
public override bool Write(GH_IWriter writer) { try { GH_IWriter writer2 = writer.CreateChunk("Hoopsnake_Data"); writer2.SetInt32("dataLimit", dataLimit); writer2.SetBoolean("resetCounter", resetCounterOnLoop); writer2.SetBoolean("updateView", updateView); writer2.SetBoolean("autoUpdate", autoUpdate); writer2.SetInt32("delay", delay); } catch {} return base.Write(writer); }
public override bool WriteFull(GH_IWriter writer) { writer.CreateChunk("channel"); writer.SetString("channel", myControlPanel.channel); return(base.Write(writer)); }
public override bool Write(GH_IWriter writer) { writer.CreateChunk("Checkbox", Index).SetBoolean("Active", _active); return(true); }
protected override void SolveInstance(IGH_DataAccess DA) { UpdateMessage(); PythonScript script = PythonScript.Create(); string outDir = ""; try { script.ExecuteScript("import scriptcontext as sc\nV=sc.sticky['NOAH_PROJECT']\nT=sc.sticky['TASK_TICKET']\nG=sc.sticky['NOAH_GENERATOR']\nID=sc.sticky['UUID']"); NOAH_PROJECT = (string)script.GetVariable("V"); TASK_TICKET = (string)script.GetVariable("T"); NOAH_GENERATOR = (string)script.GetVariable("G"); UUID = (string)script.GetVariable("ID"); if (File.Exists(NOAH_PROJECT)) { outDir = Path.Combine(Path.GetDirectoryName(NOAH_PROJECT), ".noah", "tasks", UUID, TASK_TICKET, "out"); ProjectInfo = JObject.Parse(File.ReadAllText(NOAH_PROJECT)); JArray generators = JArray.Parse(ProjectInfo["generators"].ToString()); FindJobjectFromJArray(generators, NOAH_GENERATOR, out Generator, out GeneratorIndex); } } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, ex.Message); } int outIndex = 0; DA.GetData(1, ref outIndex); JArray output = JArray.Parse(Generator["output"].ToString()); if (outIndex >= output.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "定义时未指定此输出端口"); } switch (m_mode) { case ExportMode.None: Message = null; break; case ExportMode.Rhino: string fileName = Convert.ToString(outIndex) + ".3dm"; string filePath = Path.Combine(outDir, fileName); File3dmWriter writer = new File3dmWriter(filePath); List <int> ll = new List <int>(); List <ObjectLayerInfo> layeredObj = new List <ObjectLayerInfo>(); DA.GetDataList(0, layeredObj); layeredObj.ForEach(x => { writer.ChildLayerSolution(x.Name); ll.Add(writer.CreateLayer(x.Name, x.Color)); }); if (layeredObj.Count > 0) { writer.Write(layeredObj, ll); if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } } break; case ExportMode.Text: if (!exported) { string outputData = ""; DA.GetData(0, ref outputData); ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = outputData; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; case ExportMode.Data: fileName = Convert.ToString(outIndex) + ".noahdata"; filePath = Path.Combine(outDir, fileName); if (string.IsNullOrWhiteSpace(filePath)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "未指定文件."); return; } GH_LooseChunk val = new GH_LooseChunk("Grasshopper Data"); val.SetGuid("OriginId", base.InstanceGuid); val.SetInt32("Count", base.Params.Input.Count); IGH_Param iGH_Param = base.Params.Input[0]; IGH_Structure volatileData = iGH_Param.VolatileData; GH_IWriter val2 = val.CreateChunk("Block", 0); val2.SetString("Name", iGH_Param.NickName); val2.SetBoolean("Empty", volatileData.IsEmpty); if (!volatileData.IsEmpty) { GH_Structure <IGH_Goo> tree = null; DA.GetDataTree(0, out tree); if (!tree.Write(val2.CreateChunk("Data"))) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"There was a problem writing the {iGH_Param.NickName} data."); } } byte[] bytes = val.Serialize_Binary(); try { File.WriteAllBytes(filePath, bytes); } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message); } if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; case ExportMode.CSV: fileName = Convert.ToString(outIndex) + ".csv"; filePath = Path.Combine(outDir, fileName); List <object> oList = new List <object>(); List <string> sList = new List <string>(); DA.GetDataList(0, oList); oList.ForEach(el => { string tmp = ""; GH_Convert.ToString(el, out tmp, GH_Conversion.Both); sList.Add(tmp); }); File.WriteAllText(filePath, string.Join(Environment.NewLine, sList)); if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; } }
public static void SetGeometryBase(this GH_IWriter writer, string itemName, GeometryBase data) { var dataWriter = writer.CreateChunk(itemName); WriteGeometryBase(dataWriter, data); }
public static bool SetTree(this GH_IWriter writer, string treeName, GH_Structure <IGH_Goo> tree) { var treeWriter = writer.CreateChunk(treeName); return(tree.Write(treeWriter)); }
public static void SetGH_ISerializable(this GH_IWriter writer, string itemName, GH_ISerializable data) { var dataWriter = writer.CreateChunk(itemName); WriteGH_ISerializable(dataWriter, data); }