Grasshopper

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

Views: 1404

Attachments:

Replies to This Discussion

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

thanks huaxiamengqing,

but how can I substitute the delfault assigned index to a defined integer i want to use?

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:

  1. Have the indices as a separate output list, ordered in the same manner as the points.
  2. Make a custom parameter containing a list of points and a list of indices.
  3. Make either a 2D array or a list of 1D array, such that meshPoints[i][0] has index, meshPoints[i][1] has X coordinate, meshPoints[i][2] has Y coordinate, and so on.

These are just from the top of my head, I am sure there are more solutions out there.

thanks Faberyayo!

I think i understood it!

m

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service