protected override void SolveInstance(IGH_DataAccess DA) { GsaSection gsaSection = new GsaSection(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref gsaSection); } else { string profile = ""; gh_typ.CastTo(ref profile); gsaSection = new GsaSection(profile); } } if (gsaSection != null) { double conversionfactor = 1; if (Util.Unit.LengthSection != "m") { switch (Util.Unit.LengthSection) { case "mm": conversionfactor = 1000; break; case "cm": conversionfactor = 100; break; case "in": conversionfactor = 1000 / 25.4; break; case "ft": conversionfactor = 1000 / (12 * 25.4); break; } } DA.SetData(0, gsaSection.Section.Area * Math.Pow(conversionfactor, 2)); DA.SetData(1, gsaSection.Section.Iyy * Math.Pow(conversionfactor, 4)); DA.SetData(2, gsaSection.Section.Izz * Math.Pow(conversionfactor, 4)); DA.SetData(3, gsaSection.Section.Iyz * Math.Pow(conversionfactor, 4)); DA.SetData(4, gsaSection.Section.J * Math.Pow(conversionfactor, 4)); DA.SetData(5, gsaSection.Section.Ky); DA.SetData(6, gsaSection.Section.Kz); DA.SetData(7, gsaSection.Section.SurfaceAreaPerLength * Math.Pow(conversionfactor, 2)); DA.SetData(8, gsaSection.Section.VolumePerLength * Math.Pow(conversionfactor, 3)); } }
/// <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) { #region variables string materialName = "N/A"; int materailId = 0; Material_properties properties; #endregion GH_ObjectWrapper wrapprop = new GH_ObjectWrapper(); #region input DA.GetData(0, ref materialName); if (!DA.GetData(1, ref materailId)) { return; } if (!DA.GetData(2, ref wrapprop)) { return; } wrapprop.CastTo <Material_properties>(out properties); #endregion #region solve Material outMaterial = new Material(materialName, materailId, properties); #endregion #region output DA.SetData(0, outMaterial); #endregion }
/// <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) { #region variables GH_ObjectWrapper wrapNode = new GH_ObjectWrapper(); List <Node> nodes = new List <Node>(); List <int> nodeIds = new List <int>(); List <Node> outNodes = new List <Node>(); #endregion #region input if (!DA.GetData(0, ref wrapNode)) { return; } wrapNode.CastTo <List <Node> >(out nodes); if (!DA.GetDataList(1, nodeIds)) { return; } #endregion #region solve // foreach (Node n in nodes) for (int i = 0; i < nodeIds.Count; i++) { outNodes.Add(Node.FindNodeById(nodes, nodeIds[i])); } #endregion #region output DA.SetData(0, outNodes); #endregion }
public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GH_String) { string tempfile = ""; if (GH_Convert.ToString(gh_typ, out tempfile, GH_Conversion.Both)) { if (!tempfile.EndsWith(".gwb")) { tempfile = tempfile + ".gwb"; } GsaModel.FileName = tempfile; } } else if (gh_typ.Value is GsaAPI.Model) { GsaAPI.Model model = new Model(); gh_typ.CastTo(ref model); GsaModel.Model = model; } } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Mesh ghmesh = new GH_Mesh(); if (DA.GetData(0, ref ghmesh)) { if (ghmesh == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh input is null"); } Mesh mesh = new Mesh(); if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both)) { GsaElement2d elem = new GsaElement2d(mesh); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { for (int i = 0; i < elem.Elements.Count; i++) { elem.Elements[i].Property = idd; } prop2d = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } else { prop2d = null; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem)); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection sect = new GsaSection(); GsaSection gsaSection = new GsaSection(); if (DA.GetData(0, ref sect)) { gsaSection = sect.Clone(); } if (gsaSection != null) { // #### input #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { gsaSection.ID = id; } } // 2 profile string profile = ""; if (DA.GetData(2, ref profile)) { gsaSection.Section.Profile = profile; } // 3 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); gsaSection.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { gsaSection.Section.MaterialAnalysisProperty = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } }
/// <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) { // Fields GH_ObjectWrapper abstractSocket = new GH_ObjectWrapper(); bool run = false; bool getSocket = DA.GetData(0, ref abstractSocket); //Check input if (_clientSocket == null) { if (!getSocket) { return; } abstractSocket.CastTo(ref _clientSocket); } else if (_clientSocket != null && !getSocket) { try { _clientSocket = null; return; } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Waiting For Connection..."); return; } } if (!DA.GetData(1, ref run)) { return; } //If trigger is pressed, read data and output. if (run) { string response = Util.ReadVariable(ref _clientSocket, "$BASE", this); string response2 = Util.ReadVariable(ref _clientSocket, "$TOOL", this); frameBase.DeserializeFrame(response); frameTool.DeserializeFrame(response2); } DA.SetDataList(0, frameBase.GetValuesList()); DA.SetData(1, new GH_Plane(frameBase.GetPlane())); DA.SetDataList(2, frameTool.GetValuesList()); DA.SetData(3, new GH_Plane(frameTool.GetPlane())); }
protected override void SolveInstance(IGH_DataAccess DA) { Model model = new Model(); GsaModel gsaModel = new GsaModel(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ == null) { return; } if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref gsaModel); gsaSaveModel = gsaModel.Model; Message = ""; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model"); return; } if (!usersetFileName) { if (gsaModel.FileName != "") { fileName = gsaModel.FileName; } } string tempfile = ""; if (DA.GetData(2, ref tempfile)) { fileName = tempfile; } bool save = false; if (DA.GetData(1, ref save)) { if (save) { Message = gsaSaveModel.SaveAs(fileName).ToString(); } } DA.SetData(0, new GsaModelGoo(gsaModel)); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { #region variables List <Line> lines = new List <Line>(); List <Point3d> pts = new List <Point3d>(); List <Element> elems = new List <Element>(); List <Node> nodes = new List <Node>(); string elemTag = "N/A"; List <Vector3d> normalVec = new List <Vector3d>(); GH_ObjectWrapper wrapSec = new GH_ObjectWrapper(); Section rectSec; #endregion #region input if (!DA.GetDataList(0, lines)) { return; } DA.GetData(1, ref elemTag); DA.GetData(2, ref wrapSec); DA.GetDataList(3, normalVec); #endregion #region solve wrapSec.CastTo <Section>(out rectSec); elemTag = elemTag.Trim(); for (int i = 0; i < lines.Count; i++) { if (!lines[i].IsValid) { return; } Element tempElement = new Element(lines[i], elemTag); if (rectSec != null) { tempElement.RectSec = rectSec; } elems.Add(tempElement); } #endregion #region output DA.SetData(0, elems); #endregion }
protected override void SolveInstance(IGH_DataAccess DA) { GsaProp2d gsaProp2d = new GsaProp2d(); GsaProp2d prop = new GsaProp2d(); if (DA.GetData(0, ref gsaProp2d)) { prop = gsaProp2d.Clone(); } // #### inputs #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { prop.ID = id; } } // 2 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); prop.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { prop.Prop2d.MaterialAnalysisProperty = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Mesh ghmesh = new GH_Mesh(); if (DA.GetData(0, ref ghmesh)) { Mesh mesh = new Mesh(); if (GH_Convert.ToMesh(ghmesh, ref mesh, GH_Conversion.Both)) { GsaElement2d elem = new GsaElement2d(mesh); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaProp2d) { gh_typ.CastTo(ref prop2d); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { prop2d.ID = idd; } } } else { prop2d.ID = 1; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem)); } } }
/// <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) { #region variables GH_ObjectWrapper wrapNode = new GH_ObjectWrapper(); List <Node> nodes = new List <Node>(); List <Point3d> points = new List <Point3d>(); List <int> nodeIds = new List <int>(); DataTree <int> elemIdTree = new DataTree <int>(); #endregion #region input if (!DA.GetData(0, ref wrapNode)) { return; } wrapNode.CastTo <List <Node> >(out nodes); #endregion #region solve /* foreach (Node n in nodes) * for (int i = 0; i < nodes.Count; i++) * { * points.Add(nodes[i].Pt3d); * nodeIds.Add(nodes[i].ID); * GH_Path path = new GH_Path(i); * foreach (int j in nodes[i].ElemIds) * { * elemIdTree.Add(j, path); * * } * } */ #endregion #region output DA.SetDataList(0, points); DA.SetDataList(1, nodeIds); DA.SetDataTree(2, elemIdTree); #endregion }
protected override void SolveInstance(IGH_DataAccess DA) { GsaSection gsaSection = new GsaSection(); //profile GH_String gh_profile = new GH_String(); if (DA.GetData(0, ref gh_profile)) { if (GH_Convert.ToString(gh_profile, out string profile, GH_Conversion.Both)) { gsaSection.Section = new Section(); gsaSection.Section.Profile = profile; // 3 Material GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(1, ref gh_typ)) { GsaMaterial material = new GsaMaterial(); if (gh_typ.Value is GsaMaterialGoo) { gh_typ.CastTo(ref material); gsaSection.Material = material; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { gsaSection.Material = new GsaMaterial(idd); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } else { gsaSection.Material = new GsaMaterial(7); } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Line ghln = new GH_Line(); if (DA.GetData(0, ref ghln)) { if (ghln == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Line input is null"); } Line ln = new Line(); if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both)) { GsaElement1d elem = new GsaElement1d(new LineCurve(ln)); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); elem.Section = section; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { elem.Element.Property = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } DA.SetData(0, new GsaElement1dGoo(elem)); }
/// <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) { #region variables GH_ObjectWrapper wrapElem = new GH_ObjectWrapper(); List <Element> elems = new List <Element>(); List <string> elemTags = new List <string>(); List <Line> lines = new List <Line>(); List <int> elemids = new List <int>(); List <int> n0ids = new List <int>(); List <int> n1ids = new List <int>(); #endregion #region input if (!DA.GetData(0, ref wrapElem)) { return; } wrapElem.CastTo <List <Element> >(out elems); #endregion #region solve foreach (Element e in elems) { lines.Add(e.Ln); elemTags.Add(e.Tag); elemids.Add(e.ID); n0ids.Add(e.N0id); n1ids.Add(e.N1id); } #endregion #region output DA.SetDataList(0, lines); DA.SetDataList(1, elemTags); DA.SetDataList(2, elemids); DA.SetDataList(3, n0ids); DA.SetDataList(4, n1ids); #endregion }
protected override void SolveInstance(IGH_DataAccess DA) { string cmdOutput = "Not processed"; //string paramMod = ""; GH_ObjectWrapper _abstractSocket = new GH_ObjectWrapper(); if (_clientSocket == null) { if (!DA.GetData(0, ref _abstractSocket)) { return; } _abstractSocket.CastTo(ref _clientSocket); } else if (_clientSocket != null && !DA.GetData(0, ref _abstractSocket)) { try { _clientSocket = null; return; } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Waiting For Connection..."); return; } } IPEndPoint remoteIpEndPoint = _clientSocket.RemoteEndPoint as IPEndPoint; cmdOutput = callFromCmd(remoteIpEndPoint.ToString()); DA.SetData(0, cmdOutput); GH_Document doc = OnPingDocument(); if (doc != null) { doc.ScheduleSolution(1000, ScheduleCallback); } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Line ghln = new GH_Line(); if (DA.GetData(0, ref ghln)) { Line ln = new Line(); if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both)) { GsaElement1d elem = new GsaElement1d(new LineCurve(ln)); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSection) { gh_typ.CastTo(ref section); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { section.ID = idd; } } } else { section.ID = 1; } elem.Section = section; DA.SetData(0, new GsaElement1dGoo(elem)); } } }
public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params) { #region GetData GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref model); } if (!usersetFileName) { fileName = model.FileName; } } string tempfile = ""; if (DA.GetData(2, ref tempfile)) { fileName = tempfile; } DA.GetData(1, ref save); #endregion // manually add a warning if no input is set, as all inputs are optional if (model == null) { Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "GSA input parameter failed to collect data"); return; } if (fileName == null) { Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No file name found in GSA input. Please input file name"); return; } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper _abstractSocket = new GH_ObjectWrapper(); string _keyInput = "None"; bool _triggerWrite = false; long _stepResolution = 0; if (_clientSocket == null) { if (!DA.GetData(0, ref _abstractSocket)) { return; } _abstractSocket.CastTo(ref _clientSocket); } if (!DA.GetData(1, ref _keyInput)) { return; } if (!DA.GetData(2, ref _triggerWrite)) { return; } if (!DA.GetData(3, ref _stepResolution)) { return; } if (_triggerWrite) { _messenger.keyboardLoop(_keyInput, _stepResolution, ref _clientSocket, this); } DA.SetData(0, _keyInput); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaElement2d gsaElement2d = new GsaElement2d(); if (DA.GetData(0, ref gsaElement2d)) { if (gsaElement2d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element2D input is null"); } GsaElement2d elem = gsaElement2d.Duplicate(); // #### inputs #### // no good way of updating location of mesh on the fly // // suggest users re-create from scratch // // 1 ID List <GH_Integer> ghID = new List <GH_Integer>(); List <int> in_ids = new List <int>(); if (DA.GetDataList(1, ghID)) { for (int i = 0; i < ghID.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "ID input List Length is longer than number of elements." + System.Environment.NewLine + "Excess ID's have been ignored"); continue; } if (GH_Convert.ToInt32(ghID[i], out int id, GH_Conversion.Both)) { if (in_ids.Contains(id)) { if (id > 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "ID input(" + i + ") = " + id + " already exist in your input list." + System.Environment.NewLine + "You must provide a list of unique IDs, or set ID = 0 if you want to let GSA handle the numbering"); continue; } } in_ids.Add(id); } } } // 2 section List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); List <GsaProp2d> in_prop2Ds = new List <GsaProp2d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "PA input List Length is longer than number of elements." + System.Environment.NewLine + "Excess PA's have been ignored"); } GH_ObjectWrapper gh_typ = gh_types[i]; GsaProp2d prop2d = new GsaProp2d(); if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); in_prop2Ds.Add(prop2d); elem.Elements[i].Property = 0; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { elem.Elements[i].Property = idd; elem.Properties[i] = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaModel gsaModel = new GsaModel(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref gsaModel); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model"); return; } //GsaModel in_Model = gsaModel.Clone(); Model model = gsaModel.Model; // import lists string nodeList = "all"; if (DA.GetData(1, ref nodeList)) { nodeList = nodeList.ToString(); } string elemList = "all"; if (DA.GetData(2, ref elemList)) { elemList = elemList.ToString(); } string memList = "all"; if (DA.GetData(3, ref memList)) { memList = memList.ToString(); } // get dictionaries from model IReadOnlyDictionary <int, Node> nDict = model.Nodes(); IReadOnlyDictionary <int, Element> eDict = model.Elements(elemList); IReadOnlyDictionary <int, Member> mDict = model.Members(memList); IReadOnlyDictionary <int, Section> sDict = model.Sections(); IReadOnlyDictionary <int, Prop2D> pDict = model.Prop2Ds(); IReadOnlyDictionary <int, Node> out_nDict = (nodeList == "all") ? nDict : model.Nodes(nodeList); // create nodes List <GsaNodeGoo> nodes = Util.Gsa.FromGSA.GetNodes(out_nDict, model); // create elements Tuple <List <GsaElement1dGoo>, List <GsaElement2dGoo>, List <GsaElement3dGoo> > elementTuple = Util.Gsa.FromGSA.GetElements(eDict, nDict, sDict, pDict); // create members Tuple <List <GsaMember1dGoo>, List <GsaMember2dGoo>, List <GsaMember3dGoo> > memberTuple = Util.Gsa.FromGSA.GetMembers(mDict, nDict, sDict, pDict); DA.SetDataList(0, nodes); DA.SetDataList(1, elementTuple.Item1); DA.SetDataList(2, elementTuple.Item2); DA.SetDataList(3, elementTuple.Item3); DA.SetDataList(4, memberTuple.Item1); DA.SetDataList(5, memberTuple.Item2); DA.SetDataList(6, memberTuple.Item3); element2ds = elementTuple.Item2; } }
protected override void SolveInstance(IGH_DataAccess DA) { // Model to work on GsaModel in_Model = new GsaModel(); // Get Model GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { #region Inputs if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref in_Model); if (gsaModel != null) { if (in_Model.GUID != gsaModel.GUID) { gsaModel = in_Model; getresults = true; } } else { gsaModel = in_Model; } } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model"); return; } // Get analysis case GH_Integer gh_aCase = new GH_Integer(); DA.GetData(1, ref gh_aCase); GH_Convert.ToInt32(gh_aCase, out int tempanalCase, GH_Conversion.Both); // Get element filter list GH_String gh_elList = new GH_String(); DA.GetData(2, ref gh_elList); GH_Convert.ToString(gh_elList, out string tempelemList, GH_Conversion.Both); // Get colours List <Grasshopper.Kernel.Types.GH_Colour> gh_Colours = new List <Grasshopper.Kernel.Types.GH_Colour>(); List <System.Drawing.Color> colors = new List <System.Drawing.Color>(); if (DA.GetDataList(3, gh_Colours)) { for (int i = 0; i < gh_Colours.Count; i++) { System.Drawing.Color color = new System.Drawing.Color(); GH_Convert.ToColor(gh_Colours[i], out color, GH_Conversion.Both); colors.Add(color); } } Grasshopper.GUI.Gradient.GH_Gradient gH_Gradient = UI.Colour.Stress_Gradient(colors); #endregion #region get results? // check if we must get results or just update display if (analCase == 0 || analCase != tempanalCase) { analCase = tempanalCase; getresults = true; } if (elemList == "" || elemList != tempelemList) { elemList = tempelemList; getresults = true; } #endregion #region Create results output if (getresults) { #region Get results from GSA // ### Get results ### //Get analysis case from model AnalysisCaseResult analysisCaseResult = null; gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult); if (analysisCaseResult == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file"); return; } IReadOnlyDictionary <int, Element3DResult> globalResults = analysisCaseResult.Element3DResults(elemList); #endregion // ### Loop through results ### // clear existing result lists xyz_out = new DataTree <Vector3d>(); xxyyzz_out = new DataTree <Vector3d>(); // maximum and minimum result values for colouring later dmax_x = 0; dmax_y = 0; dmax_z = 0; dmax_xx = 0; dmax_yy = 0; dmax_zz = 0; dmax_xyz = 0; dmax_xxyyzz = 0; dmin_x = 0; dmin_y = 0; dmin_z = 0; dmin_xx = 0; dmin_yy = 0; dmin_zz = 0; dmin_xyz = 0; dmin_xxyyzz = 0; keys = new List <int>(); double unitfactorxyz = 1; double unitfactorxxyyzz = 1; foreach (int key in globalResults.Keys) { keys.Add(key); // lists for results Element3DResult elementResults; if (globalResults.TryGetValue(key, out elementResults)) { List <Vector3d> xyz = new List <Vector3d>(); List <Vector3d> xxyyzz = new List <Vector3d>(); switch (_mode) { case FoldMode.Displacement: unitfactorxyz = 0.001; List <Double3> trans_vals = elementResults.Displacement.ToList(); foreach (Double3 val in trans_vals) { Vector3d valxyz = new Vector3d { X = val.X / unitfactorxyz, Y = val.Y / unitfactorxyz, Z = val.Z / unitfactorxyz }; xyz.Add(valxyz); } break; case FoldMode.Stress: unitfactorxxyyzz = 1000000; List <Tensor3> stress_vals = elementResults.Stress.ToList(); foreach (Tensor3 val in stress_vals) { Vector3d valxxyyzz = new Vector3d { X = val.XX / unitfactorxxyyzz, Y = val.YY / unitfactorxxyyzz, Z = val.ZZ / unitfactorxxyyzz }; Vector3d valxyyzzx = new Vector3d { X = val.XY / unitfactorxxyyzz, Y = val.YZ / unitfactorxxyyzz, Z = val.ZX / unitfactorxxyyzz }; xyz.Add(valxxyyzz); xxyyzz.Add(valxyyzzx); } break; } // update max and min values dmax_x = Math.Max(xyz.Max(val => val.X), dmax_x); dmax_y = Math.Max(xyz.Max(val => val.Y), dmax_y); dmax_z = Math.Max(xyz.Max(val => val.Z), dmax_z); dmax_xyz = Math.Max( xyz.Max(val => Math.Sqrt( Math.Pow(val.X, 2) + Math.Pow(val.Y, 2) + Math.Pow(val.Z, 2))), dmax_xyz); dmin_x = Math.Min(xyz.Min(val => val.X), dmin_x); dmin_y = Math.Min(xyz.Min(val => val.Y), dmin_y); dmin_z = Math.Min(xyz.Min(val => val.Z), dmin_z); if (_mode == FoldMode.Stress) { dmax_xx = Math.Max(xxyyzz.Max(val => val.X), dmax_xx); dmax_yy = Math.Max(xxyyzz.Max(val => val.Y), dmax_yy); dmax_zz = Math.Max(xxyyzz.Max(val => val.Z), dmax_zz); dmin_xx = Math.Min(xxyyzz.Min(val => val.X), dmin_xx); dmin_yy = Math.Min(xxyyzz.Min(val => val.Y), dmin_yy); dmin_zz = Math.Min(xxyyzz.Min(val => val.Z), dmin_zz); } // add vector lists to main lists xyz_out.AddRange(xyz, new GH_Path(key - 1)); xxyyzz_out.AddRange(xxyyzz, new GH_Path(key - 1)); } } getresults = false; } #endregion #region Result mesh values // ### Coloured Result Meshes ### // round max and min to reasonable numbers double dmax = 0; double dmin = 0; switch (_disp) { case (DisplayValue.X): dmax = dmax_x; dmin = dmin_x; break; case (DisplayValue.Y): dmax = dmax_y; dmin = dmin_y; break; case (DisplayValue.Z): dmax = dmax_z; dmin = dmin_z; break; case (DisplayValue.resXYZ): dmax = dmax_xyz; dmin = dmin_xyz; break; case (DisplayValue.XX): dmax = dmax_xx; dmin = dmin_xx; break; case (DisplayValue.YY): dmax = dmax_yy; dmin = dmin_yy; break; case (DisplayValue.ZZ): dmax = dmax_zz; dmin = dmin_zz; break; case (DisplayValue.resXXYYZZ): dmax = dmax_xxyyzz; dmin = dmin_xxyyzz; break; } List <double> rounded = Util.Gsa.ResultHelper.SmartRounder(dmax, dmin); dmax = rounded[0]; dmin = rounded[1]; #region create mesh // create mesh // get elements and nodes from model elemList = string.Join(" ", keys.ToList()); IReadOnlyDictionary <int, Element> elems = gsaModel.Model.Elements(elemList); IReadOnlyDictionary <int, Node> nodes = gsaModel.Model.Nodes(); List <int> elemID = new List <int>(); List <int> parentMember = new List <int>(); List <ResultMesh> resultMeshes = new List <ResultMesh>(); List <Mesh> meshes = new List <Mesh>(); // loop through elements foreach (int key in elems.Keys) { elems.TryGetValue(key, out Element element); Mesh tempmesh = GhSA.Util.Gsa.FromGSA.ConvertElement3D(element, nodes); if (tempmesh == null) { continue; } List <Vector3d> transformation = null; // add mesh colour List <double> vals = new List <double>(); GH_Path path = new GH_Path(key - 1); List <Vector3d> tempXYZ = xyz_out.Branch(path); List <Vector3d> tempXXYYZZ = xxyyzz_out.Branch(path); switch (_disp) { case (DisplayValue.X): vals = tempXYZ.ConvertAll(val => val.X); transformation = new List <Vector3d>(); for (int i = 0; i < vals.Count; i++) { transformation.Add(new Vector3d(vals[i] * Value / 1000, 0, 0)); } break; case (DisplayValue.Y): vals = tempXYZ.ConvertAll(val => val.Y); transformation = new List <Vector3d>(); for (int i = 0; i < vals.Count; i++) { transformation.Add(new Vector3d(0, vals[i] * Value / 1000, 0)); } break; case (DisplayValue.Z): vals = tempXYZ.ConvertAll(val => val.Z); transformation = new List <Vector3d>(); for (int i = 0; i < vals.Count; i++) { transformation.Add(new Vector3d(0, 0, vals[i] * Value / 1000)); } break; case (DisplayValue.resXYZ): vals = tempXYZ.ConvertAll(val => ( Math.Sqrt( Math.Pow(val.X, 2) + Math.Pow(val.Y, 2) + Math.Pow(val.Z, 2)))); transformation = tempXYZ.ConvertAll(vec => Vector3d.Multiply(Value / 1000, vec)); break; case (DisplayValue.XX): vals = tempXXYYZZ.ConvertAll(val => val.X); break; case (DisplayValue.YY): vals = tempXXYYZZ.ConvertAll(val => val.Y); break; case (DisplayValue.ZZ): vals = tempXXYYZZ.ConvertAll(val => val.Z); break; case (DisplayValue.resXXYYZZ): vals = tempXXYYZZ.ConvertAll(val => ( Math.Sqrt( Math.Pow(val.X, 2) + Math.Pow(val.Y, 2) + Math.Pow(val.Z, 2)))); break; } for (int i = 1; i < vals.Count; i++) // start at i=1 as the first index is the centre point in GsaAPI output { //normalised value between -1 and 1 double tnorm = 2 * (vals[i] - dmin) / (dmax - dmin) - 1; System.Drawing.Color col = (double.IsNaN(tnorm)) ? System.Drawing.Color.Transparent : gH_Gradient.ColourAt(tnorm); tempmesh.VertexColors.Add(col); if (transformation != null) { Point3f def = tempmesh.Vertices[i - 1]; def.Transform(Transform.Translation(transformation[i])); tempmesh.Vertices[i - 1] = def; } } ResultMesh resultMesh = new ResultMesh(tempmesh, vals); meshes.Add(tempmesh); resultMeshes.Add(resultMesh); #endregion elemID.Add(key); parentMember.Add(element.ParentMember.Member); } #endregion #region Legend // ### Legend ### // loop through number of grip points in gradient to create legend //Find Colour and Values for legend output List <double> ts = new List <double>(); List <System.Drawing.Color> cs = new List <System.Drawing.Color>(); for (int i = 0; i < gH_Gradient.GripCount; i++) { double t = dmin + (dmax - dmin) / ((double)gH_Gradient.GripCount - 1) * (double)i; double scl = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(t))) + 1); scl = Math.Max(scl, 1); t = scl * Math.Round(t / scl, 3); ts.Add(t); System.Drawing.Color gradientcolour = gH_Gradient.ColourAt(2 * (double)i / ((double)gH_Gradient.GripCount - 1) - 1); cs.Add(gradientcolour); } #endregion // set outputs int outind = 0; DA.SetDataTree(outind++, xyz_out); if (_mode == FoldMode.Stress) { DA.SetDataTree(outind++, xxyyzz_out); } DA.SetDataList(outind++, resultMeshes); DA.SetDataList(outind++, cs); DA.SetDataList(outind++, ts); } }
protected override void SolveInstance(IGH_DataAccess DA) { // Model to work on GsaModel gsaModel = new GsaModel(); // Get Model GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { #region Inputs if (gh_typ.Value is GsaModelGoo) { gh_typ.CastTo(ref gsaModel); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error converting input to GSA Model"); return; } // Get analysis case GH_Integer gh_aCase = new GH_Integer(); DA.GetData(1, ref gh_aCase); int analCase = 1; GH_Convert.ToInt32(gh_aCase, out analCase, GH_Conversion.Both); #endregion #region Get results from GSA // ### Get results ### //Get analysis case from model AnalysisCaseResult analysisCaseResult = null; gsaModel.Model.Results().TryGetValue(analCase, out analysisCaseResult); if (analysisCaseResult == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No results exist for Analysis Case " + analCase + " in file"); return; } #endregion double unitfactorForce = 1000; double unitfactorMoment = 1000; Vector3d force = new Vector3d( analysisCaseResult.Global.TotalLoad.X / unitfactorForce, analysisCaseResult.Global.TotalLoad.Y / unitfactorForce, analysisCaseResult.Global.TotalLoad.Z / unitfactorForce); Vector3d moment = new Vector3d( analysisCaseResult.Global.TotalLoad.XX / unitfactorMoment, analysisCaseResult.Global.TotalLoad.YY / unitfactorMoment, analysisCaseResult.Global.TotalLoad.ZZ / unitfactorMoment); Vector3d reaction = new Vector3d( analysisCaseResult.Global.TotalReaction.X / unitfactorForce, analysisCaseResult.Global.TotalReaction.Y / unitfactorForce, analysisCaseResult.Global.TotalReaction.Z / unitfactorForce); Vector3d reactionmoment = new Vector3d( analysisCaseResult.Global.TotalReaction.XX / unitfactorMoment, analysisCaseResult.Global.TotalReaction.YY / unitfactorMoment, analysisCaseResult.Global.TotalReaction.ZZ / unitfactorMoment); Vector3d effMass = new Vector3d( analysisCaseResult.Global.EffectiveMass.X, analysisCaseResult.Global.EffectiveMass.Y, analysisCaseResult.Global.EffectiveMass.Z); Vector3d effStiff; if (analysisCaseResult.Global.EffectiveInertia != null) { effStiff = new Vector3d( analysisCaseResult.Global.EffectiveInertia.X, analysisCaseResult.Global.EffectiveInertia.Y, analysisCaseResult.Global.EffectiveInertia.Z); } else { effStiff = new Vector3d(); } Vector3d modal = new Vector3d( analysisCaseResult.Global.ModalMass, analysisCaseResult.Global.ModalStiffness, analysisCaseResult.Global.ModalGeometricStiffness); DA.SetData(0, force); DA.SetData(1, moment); DA.SetData(2, reaction); DA.SetData(3, reactionmoment); DA.SetData(4, effMass); DA.SetData(5, effStiff); DA.SetData(6, analysisCaseResult.Global.Mode); DA.SetData(7, modal); DA.SetData(8, analysisCaseResult.Global.Frequency); DA.SetData(9, analysisCaseResult.Global.LoadFactor); } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaMember1d gsaMember1d = new GsaMember1d(); if (DA.GetData(0, ref gsaMember1d)) { if (gsaMember1d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member1D input is null"); } GsaMember1d mem = gsaMember1d.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { mem.ID = id; } } // 2 curve GH_Curve ghcrv = new GH_Curve(); if (DA.GetData(2, ref ghcrv)) { Curve crv = null; if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both)) { GsaMember1d tempmem = new GsaMember1d(crv); mem.PolyCurve = tempmem.PolyCurve; mem.Topology = tempmem.Topology; mem.TopologyType = tempmem.TopologyType; } } // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaSection section = new GsaSection(); if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); mem.Section = section; mem.Member.Property = 0; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; mem.Section = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } }
protected override void SolveInstance(IGH_DataAccess DA) { Plane _targetPlane = new Plane(); Plane _worldPlane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1), new Vector3d(0, 1, 0)); GH_ObjectWrapper _abstractSocket = new GH_ObjectWrapper(); string _variableRead = "NA"; string _variableWrite = "NA"; bool _triggerRead = false; bool _triggerWrite = false; if (_clientSocket == null) { if (!DA.GetData(0, ref _abstractSocket)) { return; } _abstractSocket.CastTo(ref _clientSocket); } if (!DA.GetData(1, ref _targetPlane)) { return; } if (!DA.GetData(2, ref _worldPlane)) { return; } if (!DA.GetData(3, ref _variableRead)) { return; } if (!DA.GetData(4, ref _variableWrite)) { return; } if (!DA.GetData(5, ref _triggerRead)) { return; } if (!DA.GetData(6, ref _triggerWrite)) { return; } if (_triggerRead) { string response = Util.ReadVariable(ref _clientSocket, _variableRead, this); DA.SetData(0, response); } if (_triggerWrite) { string targetE6 = Util.calculateTargetE6Pos(_targetPlane, _worldPlane); string response = Util.WriteVariable(ref _clientSocket, _variableWrite, "hi", this); DA.SetData(1, response); } GH_Document doc = OnPingDocument(); if (doc != null) { // Schedule loop for every 20ms doc.ScheduleSolution(20, ScheduleCallback); } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { GsaNode gsaNode = new GsaNode(); Point3d tempPt = new Point3d(); if (gh_typ.Value is GsaNodeGoo) { gh_typ.CastTo(ref gsaNode); if (gsaNode == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null"); } if (gsaNode.Node == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null"); } } else if (GH_Convert.ToPoint3d(gh_typ.Value, ref tempPt, GH_Conversion.Both)) { gsaNode = new GsaNode(tempPt); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert input to Node"); return; } GsaNode node = gsaNode.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghInt = new GH_Integer(); if (DA.GetData(1, ref ghInt)) { if (GH_Convert.ToInt32(ghInt, out int id, GH_Conversion.Both)) { node.ID = id; } } // 2 Point GH_Point ghPt = new GH_Point(); if (DA.GetData(2, ref ghPt)) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghPt, ref pt, GH_Conversion.Both)) { node.Point = pt; node.Node.Position.X = pt.X; node.Node.Position.Y = pt.Y; node.Node.Position.Z = pt.Z; } } // 3 plane GH_Plane ghPln = new GH_Plane(); if (DA.GetData(3, ref ghPln)) { Plane pln = new Plane(); if (GH_Convert.ToPlane(ghPln, ref pln, GH_Conversion.Both)) { pln.Origin = node.Point; node.LocalAxis = pln; } } // 4 Restraint GsaBool6 restraint = new GsaBool6(); if (DA.GetData(4, ref restraint)) { node.Node.Restraint.X = restraint.X; node.Node.Restraint.Y = restraint.Y; node.Node.Restraint.Z = restraint.Z; node.Node.Restraint.XX = restraint.XX; node.Node.Restraint.YY = restraint.YY; node.Node.Restraint.ZZ = restraint.ZZ; } // 5 Spring GsaSpring spring = new GsaSpring(); if (DA.GetData(5, ref spring)) { if (spring != null) { node.Spring = spring; } } // 6 Name GH_String ghStr = new GH_String(); if (DA.GetData(6, ref ghStr)) { if (GH_Convert.ToString(ghStr, out string name, GH_Conversion.Both)) { node.Node.Name = name; } } // 7 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(7, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { node.Colour = col; } } // #### outputs #### DA.SetData(0, new GsaNodeGoo(node)); DA.SetData(1, node.ID); DA.SetData(2, node.Point); DA.SetData(3, node.LocalAxis); GsaBool6 restraint1 = new GsaBool6 { X = node.Node.Restraint.X, Y = node.Node.Restraint.Y, Z = node.Node.Restraint.Z, XX = node.Node.Restraint.XX, YY = node.Node.Restraint.YY, ZZ = node.Node.Restraint.ZZ }; DA.SetData(4, restraint1); GsaSpring spring1 = new GsaSpring(); if (node.Spring != null) { spring1 = node.Spring.Duplicate(); } DA.SetData(5, new GsaSpringGoo(spring1)); DA.SetData(6, node.Node.Name); DA.SetData(7, node.Colour); try { DA.SetDataList(8, node.Node.ConnectedElements); } catch (Exception) { } try { DA.SetDataList(9, node.Node.ConnectedMembers); } catch (Exception) { } } }
protected override void SolveInstance(IGH_DataAccess DA) { Model model = new Model(); GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { if (gh_typ.Value is GH_String) { string tempfile = ""; if (GH_Convert.ToString(gh_typ, out tempfile, GH_Conversion.Both)) { fileName = tempfile; } if (!fileName.EndsWith(".gwb")) { fileName = fileName + ".gwb"; } ReturnValue status = model.Open(fileName); if (status == 0) { GsaModel gsaModel = new GsaModel { Model = model, FileName = fileName }; Titles.GetTitlesFromGSA(model); string mes = Path.GetFileName(fileName); mes = mes.Substring(0, mes.Length - 4); Message = mes; DA.SetData(0, new GsaModelGoo(gsaModel)); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model" + System.Environment.NewLine + status.ToString()); return; } } else if (gh_typ.Value is GsaAPI.Model) { gh_typ.CastTo(ref model); GsaModel gsaModel = new GsaModel { Model = model, }; DA.SetData(0, new GsaModelGoo(gsaModel)); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model"); return; } } else { ReturnValue status = model.Open(fileName); if (status == 0) { GsaModel gsaModel = new GsaModel { Model = model, FileName = fileName }; Titles.GetTitlesFromGSA(model); string mes = Path.GetFileName(fileName); mes = mes.Substring(0, mes.Length - 4); Message = mes; DA.SetData(0, new GsaModelGoo(gsaModel)); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to open Model" + System.Environment.NewLine + status.ToString()); return; } } }
protected override void SolveInstance(IGH_DataAccess DA) { Plane _targetPlane = new Plane(); Plane _worldPlane = new Plane(); GH_ObjectWrapper _abstractSocket = new GH_ObjectWrapper(); Socket _clientSocket; if (!DA.GetData(0, ref _abstractSocket)) { return; } if (!DA.GetData(1, ref _targetPlane)) { return; } if (!DA.GetData(2, ref _worldPlane)) { return; } _abstractSocket.CastTo(out _clientSocket); double _targetX = _targetPlane.OriginX; double _targetY = _targetPlane.OriginY; double _targetZ = _targetPlane.OriginZ; Transform rotMatrix = Transform.ChangeBasis(_targetPlane, _worldPlane); double _targetA = Rhino.RhinoMath.ToDegrees(Math.Atan2(rotMatrix[2, 1], rotMatrix[2, 2])); double _targetB = Rhino.RhinoMath.ToDegrees(-Math.Atan2(rotMatrix[2, 0], Math.Sqrt(rotMatrix[2, 1] * rotMatrix[2, 1] + rotMatrix[2, 2] * rotMatrix[2, 2]))); double _targetC = Rhino.RhinoMath.ToDegrees(Math.Atan2(rotMatrix[1, 0], rotMatrix[0, 0])); // ----------------------------------------------------- string req = readMessageRequest("MYPOS"); byte[] messageReq = Encoding.UTF8.GetBytes(req); AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, BitConverter.ToString(messageReq)); byte[] bytes = new byte[256]; int sentBytes = 0; //AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "reqLength: " + req.Length.ToString() + " messageReqLength: " + messageReq.Length.ToString()); try { sentBytes = _clientSocket.Send(messageReq); AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Sent " + sentBytes.ToString() + " bytes as " + req); //i = _clientSocket.Receive(bytes); //AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Received :{0} bytes." + i.ToString()); } catch (SocketException e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "SocketException :{0}" + e.ToString()); } DA.SetData(0, _targetX); DA.SetData(1, _targetY); DA.SetData(2, _targetZ); DA.SetData(3, _targetA); DA.SetData(4, _targetB); DA.SetData(5, _targetC); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Brep ghbrep = new GH_Brep(); if (DA.GetData(0, ref ghbrep)) { if (ghbrep == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Brep input is null"); } Brep brep = new Brep(); if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { // 1 Points List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); List <Point3d> pts = new List <Point3d>(); List <GsaNode> nodes = new List <GsaNode>(); if (DA.GetDataList(1, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { Point3d pt = new Point3d(); if (gh_types[i].Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_types[i].CastTo(ref gsanode); nodes.Add(gsanode); } else if (GH_Convert.ToPoint3d(gh_types[i].Value, ref pt, GH_Conversion.Both)) { pts.Add(pt); } else { string type = gh_types[i].Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Point/Node input parameter of type " + type + " to point or node"); } } } // 2 Curves gh_types = new List <GH_ObjectWrapper>(); List <Curve> crvs = new List <Curve>(); List <GsaMember1d> mem1ds = new List <GsaMember1d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { Curve crv = null; if (gh_types[i].Value is GsaMember1dGoo) { GsaMember1d gsamem1d = new GsaMember1d(); gh_types[i].CastTo(ref gsamem1d); mem1ds.Add(gsamem1d); } else if (GH_Convert.ToCurve(gh_types[i].Value, ref crv, GH_Conversion.Both)) { crvs.Add(crv); } else { string type = gh_types[i].Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Curve/Mem1D input parameter of type " + type + " to curve or 1D Member"); } } } // 4 mesh size GH_Number ghmsz = new GH_Number(); double meshSize = 0; if (DA.GetData(4, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); meshSize = m_size; } // build new element2d with brep, crv and pts GsaElement2d elem2d = new GsaElement2d(brep, crvs, pts, meshSize, mem1ds, nodes); // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(3, ref gh_typ)) { if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { prop2d.ID = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } else { prop2d.ID = 1; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem2d.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem2d.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem2d)); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Curve ghcrv = new GH_Curve(); if (DA.GetData(0, ref ghcrv)) { if (ghcrv == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Curve input is null"); } Curve crv = null; if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both)) { GsaMember1d mem = new GsaMember1d(crv); GsaBool6 rel1 = new GsaBool6 { X = x1, Y = y1, Z = z1, XX = xx1, YY = yy1, ZZ = zz1 }; mem.ReleaseStart = rel1; GsaBool6 rel2 = new GsaBool6 { X = x2, Y = y2, Z = z2, XX = xx2, YY = yy2, ZZ = zz2 }; mem.ReleaseEnd = rel2; // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); mem.Section = section; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { mem.Member.Property = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } DA.SetData(0, new GsaMember1dGoo(mem)); }