/***************************************************/ private static bool TryAddSurface(this BRepBuilder brep, PlanarSurface ps) { try { BH.oM.Geometry.Plane p = ps.ExternalBoundary.IFitPlane(); Autodesk.Revit.DB.Plane rp = p.ToRevit(); BRepBuilderSurfaceGeometry bbsg = BRepBuilderSurfaceGeometry.Create(rp, null); BRepBuilderGeometryId face = brep.AddFace(bbsg, false); brep.AddLoop(face, rp.Normal, ps.ExternalBoundary, true); foreach (ICurve c in ps.InternalBoundaries) { brep.AddLoop(face, rp.Normal, c, false); } brep.FinishFace(face); } catch { BH.Engine.Reflection.Compute.RecordError("An attempt to create a planar surface failed."); return(false); } return(true); }
/***************************************************/ /**** 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); }