public static void ConvertElement3D(GsaElement3d element3d, ref Dictionary <int, Element> existingElements, ref int elementidcounter, ref Dictionary <int, Node> existingNodes, ref int nodeidcounter ) { List <Point3d> meshVerticies = element3d.Topology; //Loop through all faces in mesh to update topology list to fit model nodes for (int i = 0; i < element3d.Elements.Count; i++) { Element apiMeshElement = element3d.Elements[i]; List <int> meshVertexIndex = element3d.TopoInt[i]; List <int> topo = new List <int>(); // temp topologylist //Loop through topology for (int j = 0; j < meshVertexIndex.Count; j++) { int id = Nodes.GetExistingNodeID(existingNodes, meshVerticies[meshVertexIndex[j]]); if (id > 0) { topo.Add(id); } else { existingNodes.Add(nodeidcounter, Nodes.NodeFromPoint(meshVerticies[meshVertexIndex[j]])); topo.Add(nodeidcounter); nodeidcounter++; } } //update topology in Element apiMeshElement.Topology = new ReadOnlyCollection <int>(topo.ToList()); // section //if (apiMeshElement.Property == 0) // apiMeshElement.Property = Prop2ds.ConvertProp2d(element2d.Properties[i], ref existingProp2Ds, ref prop2didcounter); // set api element in dictionary if (element3d.ID[i] > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list { existingElements[element3d.ID[i]] = apiMeshElement; } else { existingElements.Add(elementidcounter, apiMeshElement); elementidcounter++; } } }
public static void ConvertElement3D(List <GsaElement3d> element3ds, ref Dictionary <int, Element> existingElements, ref int elementidcounter, ref Dictionary <int, Node> existingNodes, GrasshopperAsyncComponent.WorkerInstance workerInstance = null, Action <string, double> ReportProgress = null) { // create a counter for creating new elements, nodes and properties int nodeidcounter = (existingNodes.Count > 0) ? existingNodes.Keys.Max() + 1 : 1; //int prop2didcounter = (existingProp2Ds.Count > 0) ? existingProp2Ds.Keys.Max() + 1 : 1; //checking the existing model // Elem3ds if (element3ds != null) { for (int i = 0; i < element3ds.Count; i++) { if (workerInstance != null) { if (workerInstance.CancellationToken.IsCancellationRequested) { return; } ReportProgress("Elem3D ", (double)i / (element3ds.Count - 1)); } if (element3ds[i] != null) { GsaElement3d element3d = element3ds[i]; ConvertElement3D(element3d, ref existingElements, ref elementidcounter, ref existingNodes, ref nodeidcounter); } } } if (workerInstance != null) { ReportProgress("Elem3D assembled", -2); } }
protected override void SolveInstance(IGH_DataAccess DA) { #region GetData Models = null; Nodes = null; Elem1ds = null; Elem2ds = null; Elem3ds = null; Mem1ds = null; Mem2ds = null; Mem3ds = null; Loads = null; Sections = null; Prop2Ds = null; GridPlaneSurfaces = null; // Get Model input List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(0, gh_types)) { List <GsaModel> in_models = new List <GsaModel>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ == null) { Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input is null"); return; } if (gh_typ.Value is GsaModelGoo) { GsaModel in_model = new GsaModel(); gh_typ.CastTo(ref in_model); in_models.Add(in_model); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " + type + " to GsaModel"); return; } } Models = in_models; } // Get Section Property input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(1, gh_types)) { List <GsaSection> in_sect = new List <GsaSection>(); List <GsaProp2d> in_prop = new List <GsaProp2d>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaSectionGoo) { GsaSection gsasection = new GsaSection(); gh_typ.CastTo(ref gsasection); in_sect.Add(gsasection.Duplicate()); } else if (gh_typ.Value is GsaProp2dGoo) { GsaProp2d gsaprop = new GsaProp2d(); gh_typ.CastTo(ref gsaprop); in_prop.Add(gsaprop.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " + type + " to GsaSection or GsaProp2d"); return; } } if (in_sect.Count > 0) { Sections = in_sect; } if (in_prop.Count > 0) { Prop2Ds = in_prop; } } // Get Geometry input gh_types = new List <GH_ObjectWrapper>(); List <GsaNode> in_nodes = new List <GsaNode>(); List <GsaElement1d> in_elem1ds = new List <GsaElement1d>(); List <GsaElement2d> in_elem2ds = new List <GsaElement2d>(); List <GsaElement3d> in_elem3ds = new List <GsaElement3d>(); List <GsaMember1d> in_mem1ds = new List <GsaMember1d>(); List <GsaMember2d> in_mem2ds = new List <GsaMember2d>(); List <GsaMember3d> in_mem3ds = new List <GsaMember3d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); gh_typ = gh_types[i]; if (gh_typ.Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_typ.CastTo(ref gsanode); in_nodes.Add(gsanode.Duplicate()); } else if (gh_typ.Value is GsaElement1dGoo) { GsaElement1d gsaelem1 = new GsaElement1d(); gh_typ.CastTo(ref gsaelem1); in_elem1ds.Add(gsaelem1.Duplicate()); } else if (gh_typ.Value is GsaElement2dGoo) { GsaElement2d gsaelem2 = new GsaElement2d(); gh_typ.CastTo(ref gsaelem2); in_elem2ds.Add(gsaelem2.Duplicate()); } else if (gh_typ.Value is GsaElement3dGoo) { GsaElement3d gsaelem3 = new GsaElement3d(); gh_typ.CastTo(ref gsaelem3); in_elem3ds.Add(gsaelem3.Duplicate()); } else if (gh_typ.Value is GsaMember1dGoo) { GsaMember1d gsamem1 = new GsaMember1d(); gh_typ.CastTo(ref gsamem1); in_mem1ds.Add(gsamem1.Duplicate()); } else if (gh_typ.Value is GsaMember2dGoo) { GsaMember2d gsamem2 = new GsaMember2d(); gh_typ.CastTo(ref gsamem2); in_mem2ds.Add(gsamem2.Duplicate()); } else if (gh_typ.Value is GsaMember3dGoo) { GsaMember3d gsamem3 = new GsaMember3d(); gh_typ.CastTo(ref gsamem3); in_mem3ds.Add(gsamem3.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " + type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D"); return; } } if (in_nodes.Count > 0) { Nodes = in_nodes; } if (in_elem1ds.Count > 0) { Elem1ds = in_elem1ds; } if (in_elem2ds.Count > 0) { Elem2ds = in_elem2ds; } if (in_elem3ds.Count > 0) { Elem3ds = in_elem3ds; } if (in_mem1ds.Count > 0) { Mem1ds = in_mem1ds; } if (in_mem2ds.Count > 0) { Mem2ds = in_mem2ds; } if (in_mem3ds.Count > 0) { Mem3ds = in_mem3ds; } } // Get Loads input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(3, gh_types)) { List <GsaLoad> in_loads = new List <GsaLoad>(); List <GsaGridPlaneSurface> in_gps = new List <GsaGridPlaneSurface>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaLoadGoo) { GsaLoad gsaload = null; gh_typ.CastTo(ref gsaload); in_loads.Add(gsaload.Duplicate()); } else if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface(); gh_typ.CastTo(ref gsaGPS); in_gps.Add(gsaGPS.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " + type + " to Load or GridPlaneSurface"); return; } } if (in_loads.Count > 0) { Loads = in_loads; } if (in_gps.Count > 0) { GridPlaneSurfaces = in_gps; } } // manually add a warning if no input is set, as all inputs are optional if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null & Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data"); return; } #endregion #region DoWork GsaModel analysisModel = null; if (Models != null) { if (Models.Count > 0) { if (Models.Count > 1) { analysisModel = Util.Gsa.ToGSA.Models.MergeModel(Models); } else { analysisModel = Models[0].Clone(); } } } if (analysisModel != null) { OutModel = analysisModel; } else { OutModel = new GsaModel(); } // Assemble model Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(analysisModel, Nodes, Elem1ds, Elem2ds, Elem3ds, Mem1ds, Mem2ds, Mem3ds, Sections, Prop2Ds, Loads, GridPlaneSurfaces); //gsa.SaveAs(@"C:\Users\Kristjan.Nielsen\Desktop\test3.gwb"); #region meshing // Create elements from members gsa.CreateElementsFromMembers(); #endregion #region analysis //analysis IReadOnlyDictionary <int, AnalysisTask> gsaTasks = gsa.AnalysisTasks(); if (gsaTasks.Count < 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Model contains no Analysis Tasks"); } foreach (KeyValuePair <int, AnalysisTask> task in gsaTasks) { if (!(gsa.Analyse(task.Key))) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warning Analysis Case " + task.Key + " could not be analysed"); } } #endregion OutModel.Model = gsa; //gsa.SaveAs("C:\\Users\\Kristjan.Nielsen\\Desktop\\GsaGH_test.gwb"); #endregion #region SetData DA.SetData(0, new GsaModelGoo(OutModel)); #endregion }
public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params) { #region GetData Models = null; Nodes = null; Elem1ds = null; Elem2ds = null; Elem3ds = null; Mem1ds = null; Mem2ds = null; Mem3ds = null; Loads = null; Sections = null; Prop2Ds = null; GridPlaneSurfaces = null; OutModel = null; component = Params.Owner; // Get Model input List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(0, gh_types)) { List <GsaModel> in_models = new List <GsaModel>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaModelGoo) { GsaModel in_model = new GsaModel(); gh_typ.CastTo(ref in_model); in_models.Add(in_model); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " + type + " to GsaModel"); return; } } Models = in_models; } // Get Section Property input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(1, gh_types)) { List <GsaSection> in_sect = new List <GsaSection>(); List <GsaProp2d> in_prop = new List <GsaProp2d>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaSectionGoo) { GsaSection gsasection = new GsaSection(); gh_typ.CastTo(ref gsasection); in_sect.Add(gsasection.Duplicate()); } else if (gh_typ.Value is GsaProp2dGoo) { GsaProp2d gsaprop = new GsaProp2d(); gh_typ.CastTo(ref gsaprop); in_prop.Add(gsaprop.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " + type + " to GsaSection or GsaProp2d"); return; } } if (in_sect.Count > 0) { Sections = in_sect; } if (in_prop.Count > 0) { Prop2Ds = in_prop; } } // Get Geometry input gh_types = new List <GH_ObjectWrapper>(); List <GsaNode> in_nodes = new List <GsaNode>(); List <GsaElement1d> in_elem1ds = new List <GsaElement1d>(); List <GsaElement2d> in_elem2ds = new List <GsaElement2d>(); List <GsaElement3d> in_elem3ds = new List <GsaElement3d>(); List <GsaMember1d> in_mem1ds = new List <GsaMember1d>(); List <GsaMember2d> in_mem2ds = new List <GsaMember2d>(); List <GsaMember3d> in_mem3ds = new List <GsaMember3d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_typ.CastTo(ref gsanode); in_nodes.Add(gsanode.Duplicate()); } else if (gh_typ.Value is GsaElement1dGoo) { GsaElement1d gsaelem1 = new GsaElement1d(); gh_typ.CastTo(ref gsaelem1); in_elem1ds.Add(gsaelem1.Duplicate()); } else if (gh_typ.Value is GsaElement2dGoo) { GsaElement2d gsaelem2 = new GsaElement2d(); gh_typ.CastTo(ref gsaelem2); in_elem2ds.Add(gsaelem2.Duplicate()); } else if (gh_typ.Value is GsaElement3dGoo) { GsaElement3d gsaelem3 = new GsaElement3d(); gh_typ.CastTo(ref gsaelem3); in_elem3ds.Add(gsaelem3.Duplicate()); } else if (gh_typ.Value is GsaMember1dGoo) { GsaMember1d gsamem1 = new GsaMember1d(); gh_typ.CastTo(ref gsamem1); in_mem1ds.Add(gsamem1.Duplicate()); } else if (gh_typ.Value is GsaMember2dGoo) { GsaMember2d gsamem2 = new GsaMember2d(); gh_typ.CastTo(ref gsamem2); in_mem2ds.Add(gsamem2.Duplicate()); } else if (gh_typ.Value is GsaMember3dGoo) { GsaMember3d gsamem3 = new GsaMember3d(); gh_typ.CastTo(ref gsamem3); in_mem3ds.Add(gsamem3.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " + type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D"); return; } } if (in_nodes.Count > 0) { Nodes = in_nodes; } if (in_elem1ds.Count > 0) { Elem1ds = in_elem1ds; } if (in_elem2ds.Count > 0) { Elem2ds = in_elem2ds; } if (in_elem3ds.Count > 0) { Elem3ds = in_elem3ds; } if (in_mem1ds.Count > 0) { Mem1ds = in_mem1ds; } if (in_mem2ds.Count > 0) { Mem2ds = in_mem2ds; } if (in_mem3ds.Count > 0) { Mem3ds = in_mem3ds; } } // Get Loads input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(3, gh_types)) { List <GsaLoad> in_loads = new List <GsaLoad>(); List <GsaGridPlaneSurface> in_gps = new List <GsaGridPlaneSurface>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaLoadGoo) { GsaLoad gsaload = null; gh_typ.CastTo(ref gsaload); in_loads.Add(gsaload.Duplicate()); } else if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface(); gh_typ.CastTo(ref gsaGPS); in_gps.Add(gsaGPS.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " + type + " to Load or GridPlaneSurface"); return; } } if (in_loads.Count > 0) { Loads = in_loads; } if (in_gps.Count > 0) { GridPlaneSurfaces = in_gps; } } #endregion // manually add a warning if no input is set, as all inputs are optional if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null & Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null) { hasInput = false; Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data"); return; } else { hasInput = true; } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaElement3d gsaElement3d = new GsaElement3d(); if (DA.GetData(0, ref gsaElement3d)) { if (gsaElement3d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element3D input is null"); } GsaElement3d elem = gsaElement3d.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); } } } List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); // 2 section //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; // } // } // } //} // 3 Group List <GH_Integer> ghgrp = new List <GH_Integer>(); List <int> in_groups = new List <int>(); if (DA.GetDataList(3, ghgrp)) { for (int i = 0; i < ghgrp.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Group input List Length is longer than number of elements." + System.Environment.NewLine + "Excess Group numbers have been ignored"); continue; } if (GH_Convert.ToInt32(ghgrp[i], out int grp, GH_Conversion.Both)) { in_groups.Add(grp); } } } // 4 name List <GH_String> ghnm = new List <GH_String>(); List <string> in_names = new List <string>(); if (DA.GetDataList(4, ghnm)) { for (int i = 0; i < ghnm.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Name input List Length is longer than number of elements." + System.Environment.NewLine + "Excess Names have been ignored"); continue; } if (GH_Convert.ToString(ghnm[i], out string name, GH_Conversion.Both)) { in_names.Add(name); } } } // 5 Colour List <GH_Colour> ghcol = new List <GH_Colour>(); List <System.Drawing.Color> in_colours = new List <System.Drawing.Color>(); if (DA.GetDataList(5, ghcol)) { for (int i = 0; i < ghcol.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Colour input List Length is longer than number of elements." + System.Environment.NewLine + "Excess Colours have been ignored"); continue; } if (GH_Convert.ToColor(ghcol[i], out System.Drawing.Color col, GH_Conversion.Both)) { in_colours.Add(col); } } } // 6 Dummy List <GH_Boolean> ghdum = new List <GH_Boolean>(); List <bool> in_dummies = new List <bool>(); if (DA.GetDataList(6, ghdum)) { for (int i = 0; i < ghdum.Count; i++) { if (i > elem.Elements.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Dummy input List Length is longer than number of elements." + System.Environment.NewLine + "Excess Dummy booleans have been ignored"); continue; } if (GH_Convert.ToBoolean(ghdum[i], out bool dum, GH_Conversion.Both)) { in_dummies.Add(dum); } } } // loop through all elements and set collected lists. // handle too short or too long input lists here // for short lists copy last item for (int i = 0; i < elem.Elements.Count; i++) { //if (in_prop2Ds.Count > 0) //{ // if (i < in_prop2Ds.Count) // elem.Properties[i] = in_prop2Ds[i]; // else // elem.Properties[i] = in_prop2Ds[in_prop2Ds.Count - 1]; //} if (in_ids.Count > 0) { if (i < in_ids.Count) { elem.ID[i] = in_ids[i]; } else { elem.ID[i] = 0; // do not set ID (element number) as it must be unique } } if (in_names.Count > 0) { if (i < in_names.Count) { elem.Elements[i].Name = in_names[i]; } else { elem.Elements[i].Name = in_names[in_names.Count - 1]; } } if (in_groups.Count > 0) { if (i < in_groups.Count) { elem.Elements[i].Group = in_groups[i]; } else { elem.Elements[i].Group = in_groups[in_groups.Count - 1]; } } if (in_colours.Count > 0) { if (i < in_colours.Count) { elem.Elements[i].Colour = in_colours[i]; } else { elem.Elements[i].Colour = in_colours[in_colours.Count - 1]; } } if (in_dummies.Count > 0) { if (i < in_dummies.Count) { elem.Elements[i].IsDummy = in_dummies[i]; } else { elem.Elements[i].IsDummy = in_dummies[in_dummies.Count - 1]; } } } // convert mesh to output meshes List <Mesh> out_meshes = new List <Mesh>(); Mesh x = elem.NgonMesh; List <MeshNgon> ngons = x.GetNgonAndFacesEnumerable().ToList(); for (int i = 0; i < ngons.Count; i++) { Mesh m = new Mesh(); m.Vertices.AddVertices(x.Vertices.ToList()); List <int> faceindex = ngons[i].FaceIndexList().Select(u => (int)u).ToList(); for (int j = 0; j < faceindex.Count; j++) { m.Faces.AddFace(x.Faces[faceindex[j]]); } m.Vertices.CullUnused(); m.RebuildNormals(); out_meshes.Add(m); } // #### outputs #### DA.SetData(0, new GsaElement3dGoo(elem)); DA.SetDataList(1, elem.ID); DA.SetDataList(2, out_meshes); List <GsaOffset> out_offsets = new List <GsaOffset>(); List <string> type = new List <string>(); List <string> out_names = new List <string>(); List <int> out_groups = new List <int>(); List <System.Drawing.Color> out_colours = new List <System.Drawing.Color>(); List <int> pmems = new List <int>(); List <bool> out_dummies = new List <bool>(); for (int i = 0; i < elem.Elements.Count; i++) { GsaOffset offset1 = new GsaOffset { Z = elem.Elements[i].Offset.Z }; out_offsets.Add(offset1); type.Add(elem.Elements[i].TypeAsString()); out_names.Add(elem.Elements[i].Name); out_groups.Add(elem.Elements[i].Group); out_colours.Add((System.Drawing.Color)elem.Elements[i].Colour); out_dummies.Add(elem.Elements[i].IsDummy); try { pmems.Add(elem.Elements[i].ParentMember.Member); } catch (Exception) { pmems.Add(0); } ; } //DA.SetDataList(3, elem.Properties); DA.SetDataList(4, out_groups); DA.SetDataList(5, type); DA.SetDataList(6, out_names); DA.SetDataList(7, out_colours); DA.SetDataList(8, out_dummies); DA.SetDataList(9, pmems); } }