1

I am trying to use the DivideByLength method below based on the RhinoCommon SDK but I cannot understand what the third argument is. I have tried to write the code below based on this method but I get the following error message: Error: 'Rhino.Geometry.Point3d' is a 'type' but is used like a 'variable'

I thought the third argument was to specify that I wanted points as output and not doubles. What am I doing wrong?

Method:

Public Function DivideByLength ( _
    segmentLength As Double, _
    includeStart As Boolean, _
    <OutAttribute> ByRef points As Point3d() _
) As Double()

Code:

List<Point3d> pts = new List<Point3d>();

for(int i = 0; i < crv.Count;i = i + 2)
{
  pts.Add(crv[i].DivideByLength(nb, true, out Point3d()));
}
Brian Gillespie
  • 3,213
  • 5
  • 27
  • 37
Arthur Mamou-Mani
  • 2,303
  • 10
  • 43
  • 69
  • You have to specify a variable next to the out keyword. More here http://msdn.microsoft.com/en-us/library/t3c3bfhx(v=vs.80).aspx – Soeholm Nov 09 '12 at 16:05

4 Answers4

7

It looks like this is what you're looking for:

List<Point3d[]> pts = new List<Point3d[]>();

for(int i = 0; i < crv.Count;i = i + 2)
{
  Point3d[] pointArray;
  crv[i].DivideByLength(nb, true, out pointArray);
  pts.Add(pointArray);
}

See the out parameter documentation for more info.

Tim S.
  • 55,448
  • 7
  • 96
  • 122
  • Yes, I just caught that (my unfamiliarity with VB caused me to glance over it at first). Thanks. – Tim S. Nov 09 '12 at 16:08
2

Try to use in c#:

List<Point3d[]> ptlist = new List<Point3d[]>();
    Point3d[] pts;

    for(int i = 0; i < crv.Count;i = i + 2)
    {
       crv[i].DivideByLength(nb, true, out pts);
       ptlist.add(pts);
    }

Using new is not wrong but useless since is the function returning the array as an output.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
2

I think this might be what you're after. Your out parameter is an array of Point3d objects and it looks like you want to get a list of all of the ones in all of the returned arrays. So you'd have your list, and need to AddRange the results.

List<Point3d> pts = new List<Point3d>();

for(int i = 0; i < crv.Count;i = i + 2)
{
    Point3d[] arr;
    crv[i].DivideByLength(nb, true, out arr);
    pts.AddRange(arr);
}
Joe Enos
  • 39,478
  • 11
  • 80
  • 136
  • 2
    For the record, it's easy enough to flatten a `List` if that's what's needed. +1 for the good observation though. – Servy Nov 09 '12 at 16:14
  • @Servy Good point (pun intended). The `List` may be the better option, so you get the choice later on whether you want to flatten or not. – Joe Enos Nov 09 '12 at 16:21
1

You need new Point3d() instead of Point3d() you need to instanstiate the Point3d instead of passing Point3d

Point3d objPoint3d = new Point3d();

pts.Add(crv[i].DivideByLength(nb, true, out objPoint3d));
Adil
  • 146,340
  • 25
  • 209
  • 204
  • 1
    You don't need to instantiate the variable. The `out` clause means the variable will be instantiated inside the method. Plus it's an array, not a single instance of `Point3d`, so it would be `Point3d[]`. – Joe Enos Nov 09 '12 at 16:08