Help: how to find midpoint of Nurbs curve? using to filletcurves

Good day all,

I am trying to fillet two line curves so that the new fillet arc is a user-defined distance away from the previous apex.

I have created a C# script and am stuck at trying to find the midpoint of the nurbscuve ‘filletcrvNURBS’.
i intend to use the midpoint to calculate the distance away from the apex, then update the ‘radius’ variable until the correct fillet arc is drawn at desired distance away.

I am receiving an error ‘Object reference not set to an instance of an object’?

Could a kind teacher guide my way? Many thanks!
I have only started learning to script last week, so my error might be a silly one.

fillet curves till x distance away away from apex.gh (8.4 KB)

Moved to #rhino-developer category

solved

private void RunScript(Curve icurves, double deRadius, ref object A, ref object B, ref object C, ref object D, ref object E, ref object F, ref object AA, ref object AB, ref object AC)
{
//fetch discontinuity of curve
double t0 = 0.0;
double t1 = 1.0;
double tout;

icurves.GetNextDiscontinuity(Continuity.G2_continuous, t0, t1, out tout);

Curve[] splitcrv = null;
splitcrv = icurves.Split(tout);
A = splitcrv[0];
B = splitcrv[0].PointAtStart;
C = splitcrv[0].PointAtEnd;
D = splitcrv[1];
E = splitcrv[1].PointAtStart;
F = splitcrv[1].PointAtEnd;

double rad = RhinoMath.Epsilon;
double radStep = 0.05;
double tol = radStep / 50;
bool search = true;
//int Count = 1;

while(search)
{
  //update radius and draw new filletcrv

  var filletcrv = Curve.CreateFillet(splitcrv[0], splitcrv[1], rad, t1, t0);
  var midpoint = filletcrv.MidPoint;
  var currLength = midpoint.DistanceTo(splitcrv[0].PointAtEnd);
  //Print("Radius step too large x{0} {1}", Count, rad);
  //Count = Count + 1;

  if((deRadius - currLength) < tol && (deRadius - currLength > RhinoMath.Epsilon))
  {
    AA = filletcrv;
    AB = filletcrv.MidPoint;
    Print((deRadius - currLength).ToString());
    Print(tol.ToString());
    Curve filletcrvNURBS = filletcrv.ToNurbsCurve();
    Curve[] outCrv = {splitcrv[0], filletcrvNURBS, splitcrv[1]};
    //AC = Curve.JoinCurves(outCrv, 0.0);
    AC = outCrv;
    search = false;
  }

  if((deRadius - currLength < RhinoMath.Epsilon))
  {
    //radius step is too large and causes a miss
    //reset radius and half the step size
    rad = RhinoMath.Epsilon;
    radStep /= 2;
    //Count = 1;
  }

  rad += radStep;
}

}