Manipulate ControlPoints on Curves from GH-C#?

OK, so I was thinking of manipulating (stacking / moving) curves by manipulating ControlPoints from a C# script, but I can’t find out how to gain access the CP’s of a given curve. Given a Line or Curve in GH I want to be able to :

  1. Define N number of Controlpoints for the curve.
  2. Set Degree for the curve.
  3. Remove any number of CP’s from the Curve.
  4. Move any of the CP’s

BTW, can all this also be done using GH std components?

// Rolf

OK, I found out that if converting to NurbsCurve I can access the control points.

// Rolf

1 Like

Yea it is like:

//Point3d
nurbscrv.Points[i].Location;

//Weight
nurbscrv.Points[i].Weight;

//Knot
nurbscrv.Knots[i];

1 Like

@Michael_Pryor, Do you know how to add new ControlPoints to an existing NurbsCurve?

I tried the following, but the SetPoint method totally crashes Rhino (with or whithout doing Rebuild before SetPoint), perhaps because SetPoint doesn’t seem like it’s actually adding any point? (it doesn’t even try to overwrite an existing point at index…).

    var insert_cnt = 100;
    var degree = 3;
    crv.Rebuild(insert_cnt, degree, false);    
    // ... but this did NOT change the CP count. :( 

    // ... so I tried this instead:
    for (var i = 1; i < insert_cnt; i++)
    {
         var new_cp = // at a distance from each other ;
         crv.Points.SetPoint(i, new_cp);
    }

    Print("DEBUG| CP Count   : " + crv.Points.Count.ToString());
}

… but no go. How do I add CP’s??

// Rolf

You insert knots I believe. Because it adds the control points and adjusts the control points around it to keep the curve shape.

NurbsCurve nurbs = C.ToNurbsCurve();
nurbs.Knots.InsertKnot(0.5);

1 Like

You can then change the control points position like this:

nurbs.Points[i] = new ControlPoint(pt);

http://developer.rhino3d.com/5/api/RhinoCommon/html/T_Rhino_Geometry_ControlPoint.htm

Thank you Michael, that was very helpful. I got it working now.

// Rolf

1 Like

I need to insert knots point on a curve by parameters on curve domain.
Like the Rhino command “InsertKnot”

Could you create a grasshopper script to do this?
Can you help me please?

Patrick

@Michael_Pryor