algorithmic modeling for Rhino
Hi to everybody,
I am trying to import a list of points through a custom script from an excel file to GH.
I was able to import the coordinate and so the points, but I want to assign to each point a determinate index that I will need to determine the mesh topology according to the output list from an FEM software.
how can I assign a determinate index to a list of point? what is the difference between list and monodimensional arrays?
here I post my code and a screenshot of the excel file I am working whit:
as you can see in the code I was able to turn the input cell content in a index, but then i do not know how to assign this as index to the determinate point of the list.
I have another question: because the FEM software starts to assign the index point from 1001 I was wondering if the list of point uses the first 1000 entries and, even if this entries are empty, do the list allocate some memories for these empty entries?
protected override void SolveInstance(IGH_DataAccess DA)
{
string path = null;
if (!DA.GetData(0, ref path)) return;
int sheet = 0;
if (!DA.GetData(1, ref sheet)) return;
ClosedXML.Excel.XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook(path);
var ws = workbook.Worksheet(sheet);
//This for-cycle reads the quad mesh point and WIP creates an index consinstent list of these
List<Point3d> meshPoints = new List<Point3d>();
for (int i = 2; i <= ws.LastCellUsed().Address.RowNumber; i++)
{
GH_Path p = new GH_Path(i - 1);
GH_String cellData = new GH_String();
int index =new int();
cellData.Value = ws.Cell(i, 1).Value.ToString();
index = int.Parse(ws.Cell(i, 1).Value.ToString());
Point3d meshPt = new Point3d();
cellData.Value = ws.Cell(i, 2).Value.ToString();
meshPt.X = double.Parse(ws.Cell(i, 2).Value.ToString());
cellData.Value = ws.Cell(i, 3).Value.ToString();
meshPt.Y = double.Parse(ws.Cell(i, 3).Value.ToString());
cellData.Value = ws.Cell(i, 4).Value.ToString();
meshPt.Z = double.Parse(ws.Cell(i, 4).Value.ToString());
meshPoints.Add(new Point3d(meshPt));
}
DA.SetDataList(1, meshPoints);
}
thanks a lot in advance for your help!
Matteo
Tags:
the point's index is assined by itself when add it to an list or an array. I think array and list have no difference in nature.
" do the list allocate some memories for these empty entries"
Yes ,of coures
array(i) = value
list(i) = value即可。
An array has a fixed length whereas a list is dynamic in nature, with its length increasing and decreasing when you add or remove items.
With an array of Point3d, you can assign nothing to the first 1000 indices and then start assigning the mesh points from 1001 index onwards, but I doubt taht is the most efficient solution. Some alternatives:
These are just from the top of my head, I am sure there are more solutions out there.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by