private static ElementId createModelCurve(Document document, Curve curve, SketchPlane sp = null) { Line line = curve as Line; Arc arc = curve as Arc; Ellipse ellipse = curve as Ellipse; HermiteSpline spline = curve as HermiteSpline; NurbSpline nbSpline = curve as NurbSpline; if (line != null && null == sp) { XYZ normal = getVertVec(line.Direction).Normalize(); XYZ origin = line.GetEndPoint(0); sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin)); } else if (arc != null && null == sp) { XYZ normal = arc.Normal; sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, arc.Center)); } else if (ellipse != null && null == sp) { XYZ normal = ellipse.Normal; sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, ellipse.Center)); } else if (spline != null && null == sp) { Transform tran = spline.ComputeDerivatives(0, false); XYZ normal = getVertVec(tran.BasisX).Normalize(); XYZ origin = spline.GetEndPoint(0); sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin)); } else if (nbSpline != null && null == sp) { Transform tran = nbSpline.ComputeDerivatives(0, false); XYZ normal = getVertVec(tran.BasisX).Normalize(); XYZ origin = nbSpline.GetEndPoint(0); sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin)); } if (sp == null) { throw new ArgumentException("Not valid sketchplane to create curve:" + curve.GetType().Name); } // // create model line with curve and the specified sketch plane. ModelCurve mCurve = document.Create.NewModelCurve(curve, sp); return((null != mCurve) ? mCurve.Id : ElementId.InvalidElementId); }