/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static Element ToCurveElement(this ModelInstance modelInstance, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { CurveElement curveElement = refObjects.GetValue <CurveElement>(document, modelInstance.BHoM_Guid); if (curveElement != null) { return(curveElement); } settings = settings.DefaultIfNull(); ICurve curve = modelInstance.Location as ICurve; if (curve == null) { return(null); } if (!curve.IIsPlanar(settings.DistanceTolerance)) { modelInstance.NonPlanarCurveError(); return(null); } Curve revitCurve = curve.IToRevit(); if (revitCurve == null) { return(null); } if ((revitCurve is NurbSpline || revitCurve is HermiteSpline) && curve.IIsClosed(settings.DistanceTolerance)) { modelInstance.ClosedNurbsCurveError(); return(null); } Autodesk.Revit.DB.Plane revitPlane; BH.oM.Geometry.Plane plane = curve.IFitPlane(); if (plane == null) { revitPlane = revitCurve.ArbitraryPlane(); } else { revitPlane = plane.ToRevit(); } SketchPlane sketchPlane = SketchPlane.Create(document, revitPlane); curveElement = document.Create.NewModelCurve(revitCurve, sketchPlane); if (modelInstance.Properties != null) { string name = modelInstance.Properties.Name; if (!string.IsNullOrEmpty(name)) { Element element = new FilteredElementCollector(document).OfClass(typeof(GraphicsStyle)).ToList().Find(x => x.Name == name); if (element != null) { curveElement.LineStyle = element; } } } refObjects.AddOrReplace(modelInstance, curveElement); return(curveElement); }