Copy Points along Z Axis - c# code Rhinocommons


Newbie here at coding, I have been doing a lot this weekend though on a project and have created a mass of random points along my surface (topography). I now want to copy these points along the Z axis, all the same amount, and then connect the two points to create lines that will represent trees.

I have created this code to create the points, on my surface, which I have outputted to A = Points

I want to, in a new c# component, now, as I said, copy these points vertically by some “z” amount (does not really matter), and then make lines between them.

I have a simple Grasshopper script that can do this, but I have been challenged to do this all in code…and for the life cannot figure it out.

I saw this other post which was projecting points, using this method:

    // Create verticals
var vert = new List<Line>();
for (int i = 0; i < segments; i++)
  var vertTemp = new Line(topChPts[i], botChPts[i]);
  if (vertTemp.Length > 0)

and something tells me I can use this and just replace the new Line(topChPts[i], botChPts[i]);

Portion w/ my points (topChPts being moved pts on top, and bot the bottom ones)

But in practice I do not know how to get my output of bottom points into the script and move them, and then incorporate those.

Any help much appreciated, thanks. File (13.0 KB)

If you just want to move points just add two points together:

Line line = new Line(topChPts[i], topChPts[i]+ new Point3d(0,0,z));

Hi Petras,

I was actually just looking at your PDF of c# on issuu…and from that I figured out how to accomplish what I want to do, sort of.

See here:


So I move all of the points up by 3 (meters in this case)

But for some reason it gives me this:
The same number of points (9408), but they are spread out much more… See the Green points are the original pts below,

All I want to do is copy those UP 3m.

the output A from RandomPts, are those points, which I input into pts in the next component.

Any idea how to fix?


Try to change all what you wrote.


Point3d pts_ = new Point3d(pts);
pts_ +=Vector3d.ZAxis*3;

You need to copy object first before and only then change its z coord.

Or in one line

A = new Point3d(pts.X, pts.Y, pts.Z+3);

Perfect! So I understand, why am I multiplying ZAxis*3, and not stating the Z as 3?

And if I want to create lines between these two points now, would it just be:

Line tree = new Line(new Point3d(pts.X, pts.Y, pts.Z), new Point3d (npts.X, npts.Y, npts.Z));

A = tree;


Line tree = new Line(pts,npts);

Should work too.

I am now trying to make pipes using the lines I previously created, using the BREPCreatePipe, but I am unsure how to syntax it correctly:

Brep[] CreatePipe(trees, double 0.1, true, Rhino.Geometry.PipeCapMode.Flat, bool fitRail, double 0.001, double 0.001);

is what I did, but …it does not work.

For Lines here’s the thing (TR : radius, tol: DocTol):

Meaning that you’ll get the first item ([0]) of the resulting Array … but better safe than sorry : use try/catch always. Some check of the TR/Line Length (VS tol or some other value) is not a bad idea either. In the above all these checks are done already elsewhere. If the Line is a LineCurve you don’t need the .ToNurbsCurve() part.

PS: You can use a public var (of type PipeCapMode) and control the result via some user defined value.