Script to attach polyline/curve to a single Point3d handle

Hi all,

Within a script I’m trying to control a whole polyline via a single Point3d called handle. For now I’d be happy if the translation of the handle just causes the translation of all the points of the polyline by the same amount. Later, I’d tune the move of the different polyline points with several weights.

I don’t know exactly how to code this, as I’m completely new to developing in Rhino. I have experience from Maya Autodesk, where I coded these objects via nodes and control their dependency with a dynamically override update function. In Rhino, I do not know exactly

  1. Which method should I override that is called at every viewport refresh? Is protected override Result RunCommand (Rhino.RhinoDoc doc, RunMode mode) such a method?
  2. How to access these nodes, i.e. a polyline and the Point3d handle?

Many thanks!

Hi Pablo,

Are you scripting with Python, or are you trying to write a plug-in with C#?

It sounds like you are just trying to move a polyline from one point to another, correct?

– Dale

Hi Dale,

I’m coding a plug-in with C#. Indeed, I’m just moving a polyline from one point to another, being this translation given by the user with the offset of a Point3d.

Many thanks!

Here is a pretty basic example:

https://github.com/dalefugier/SampleCsCommands/blob/master/SampleCsMove.cs

– Dale

Hi Dale,

Thank you very much! If I understand correctly, you pick the polyline as a whole ObjRef objref, you take the user defined translation as Transform.translation xform, and perform the transform with Rhino.RhinoDoc.Objects.Transform(objref, xform, true).

Assume now that you know in advance that your objref is a polyline, or a Point3d array points, of say size 3. I want the translation xform to happen to points[0] and points[2] with an amount 1.0, i.e. they are translated xform times, and to points[1] with amount 2.0, i.e. the middle point is translated 2.0 xform times. How can I specify this difference in component translations? In other words, how can I access the subcomponents of my objref and manipulate each one separately?

Thanks again!

In this case, you won’t be able to provide a single transform for the entire object. Thus, you will need to modify each point location individually.

For example:

// Get underlying curve geometry
var polyline_curve = go.Object(0).Geometry() as PolylineCurve;
if (null == polyline_curve)
  return Result.Failure;

// Make a copy of the geometry
var new_polyline_curve = polyline_curve.DuplicateCurve() as PolylineCurve;
if (null == new_polyline_curve)
  return Result.Failure;

// Modify the geometry in some way
for (var i = 0; i < new_polyline_curve.PointCount; i++)
{
  var point = new_polyline_curve.Point(i);
  if (i%2 != 0)
  {
    point.X += 1;
    point.Y += 1;
  }
  else
  {
    point.X -= 1;
    point.Y -= 1;
  }
  new_polyline_curve.SetPoint(i, point);
}

// Replace the original object (geometry) with the modified one.
doc.Objects.Replace(go.Object(0), new_polyline_curve);
doc.Views.Redraw();

https://github.com/dalefugier/SampleCsCommands/blob/master/SampleCsEditPolyline.cs

1 Like

With a mixture of this code and the previous one I think I found what I want. This way of filtering the geometry and extracting the polyline and its components is very interesting.
I’ll come back to you if I need further help, thanks for your help!