Got invalid PolyLines after compiling in vs which work in the c# component

Hi,

as in the title described the problem is strange.
I copy the code from the c# component and compile it and it outputs invalid polylines when the division number is uneven:

 private void RunScript(Surface S, int U, int V, ref object A)
  {

    var pLines = new List<Polyline>();



    double uStep = 1.0 / U;
    double vStep = 1.0 / V;

    Point3d ptA;
    Point3d ptB;
    Point3d ptC;
    Point3d ptD;




    S.SetDomain(0, new Interval(0, 1));
    S.SetDomain(1, new Interval(0, 1));

    for (int i = 0; i < U + 1; i++)
    {
      for (int j = 0; j < V + 1; j++)
      {



        if ((i + j) % 2 == 1)
        {
          var pts = new List<Point3d>();
          if (i > 0)
          {
            ptA = S.PointAt((i - 1) * uStep, j * vStep);
            pts.Add(ptA);
          }
          else
          {
            ptA = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptA);
          }


          if (j > 0)
          {
            ptB = S.PointAt(i * uStep, (j - 1) * vStep);
            pts.Add(ptB);
          }

          else
          {
            ptB = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptB);
          }


          if (i < U)
          {
            ptC = S.PointAt((i + 1) * uStep, j * vStep);
            pts.Add(ptC);
          }

          else
          {
            ptC = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptC);
          }



          if (j <= V - 1)
          {
            ptD = S.PointAt(i * uStep, (j + 1) * vStep);
            pts.Add(ptD);
          }

          else
          {
            ptD = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptD);
          }

          pts.Add(ptA);


          pLines.Add(new Polyline(pts));

        }

      }

    }
    A = pLines;
  }

here the vs file:CrvDiamondComponent.cs (5.5 KB)
Thanks for aclaration!

Are you trying to make like Lunchboxes diamond surface component?

Hello, I have no idea if this is a problem. But this usually yields 0 if U is of type int.

you need to write double uStep = 1.0 / (double) U.

Similiar, but I want Polylines, since Surfaces are too heavy.

No it doesn’t ? 1.0 is a double, thus if any argument is double, double division is used?

Thanks Tom,
I still got the error, after I changed to that

oh you are right. I’m writing this everytime though. if you write 1 / U then it would be 0

My guess would be that this is a casting issue, which occurs when you call DA.SetDataList with the polyline list, while it expects a list of curves. Don’t know how to reproduce this though, to test this hypothesis.

Have you tried explicitly casting your list of polylines to a list of curves inside your script? Like iterate over the list, cast the polyline to a NurbsCurve, then check for nullity and validity?

Hi @dsonntag,

I just changed the outputParameter from Curve to Geometry and everything is fine.
I want to have Polylines as Output, thats why I dont want to cast them to NurbsCurve.

Thanks a lot !

There is the Diagrid for surface points. If you ever need in the future.

Thanks @Michael_Pryor,

forgot about this one.
It also works with merge instead of weave I think.

Regards!