Grasshopper

algorithmic modeling for Rhino

private void RunScript(List<Curve> na, double lendist, ref object A, ref object B)
  {
    List<double[]> list1 = new List<double[]>();
    List<Point3d[]> list2 = new List<Point3d[]>();
    for (int i = 0 ;(i <= (na.Count) - 1 ); i++)
    {
      list1.Add(na[i].DivideByLength(lendist, true,                     ???                ));
    }
    A = list1;
    B = list2;
}

Hello, someone can tell me how to use the third param "out" of the methode DivideByLength() ,it will help me a lot ^^

Views: 398

Replies to This Discussion

Point3d[] pts = null;
crv.DivideByLength(1.0, true, out pts);


--
David Rutten
david@mcneel.com
Poprad, Slovakia
Here some changes to your code. You could still add some error checks (for example, that the distance is not 0, etc...). You need to work with trees for Grasshopper to understand the data types.

DataTree<double> tree1 = new DataTree<double>();
DataTree<Point3d> tree2 = new DataTree<Point3d>();

for(int i = 0; i < na.Count; i++)
{
  GH_Path p = new GH_Path(i);

  Point3d[] pts;
  tree1.AddRange(na[i].DivideByLength(lendist, true, out pts), p);
  tree2.AddRange(pts, p);
}
A = tree1;
B = tree2;
out means that is require a variable for the function to pass the results to, in your case you are dividing a curve so it want a temporary place holder for the points you are adding

List list1 = new List();
List list2 = new List();

Point3d[] tempPoints;

for (int i = 0 ; i < na.Count; i++)
{
list1.Add(na[i].DivideByLength(lendist, true, out tempPoints));
list2.Add(tempPoints);
}
A = list1;
B = list2;


but you have a bigger problem, you are trying to return a list of lists. the grasshopper script component cannot do this. you need to use trees!

/\
/ \
/ \
/ \
------
|
a simple solution is change your inputs to be a single curve not a list and graft the list of curves before you pass them to the component and it will work like this

private void RunScript(Curve na, double lendist, ref object A, ref object B)
{
List list1 = new List();
List list2 = new List();
Point3d[] tempPoints;

A = na.DivideByLength(lendist, true, out tempPoints);
B = tempPoints;
}
Thanks all, i was'nt familiar with the "out" param, now all is perfectly clear, thanks for the fast feed back ;)
another question please, about the forum, how can i write my code in spécial space like Giulio and David in this topic ?
Encase your code with the html code tags:

<code> your code here! </code>

--
David Rutten
david@mcneel.com
Poprad, Slovakia

Print("well done thanks David ;) ");

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