# 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.

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 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);
//Count = Count + 1;

{
AA = filletcrv;
AB = filletcrv.MidPoint;
Print(tol.ToString());
Curve filletcrvNURBS = filletcrv.ToNurbsCurve();
Curve[] outCrv = {splitcrv[0], filletcrvNURBS, splitcrv[1]};
//AC = Curve.JoinCurves(outCrv, 0.0);
AC = outCrv;
search = false;
}