const double PRECISION = 0.00001; //precision when judge whether two doubles are equal /// <summary> /// get all faces that compose the geometry solid of given element /// </summary> /// <param name="elem">element to be calculated</param> /// <returns>all faces</returns> public static FaceArray GetFaces(Element elem) { List <Face> faces = new List <Face>(); Autodesk.Revit.DB.Options geoOptions = Command.CommandData.Application.Application.Create.NewGeometryOptions(); geoOptions.ComputeReferences = true; GeoElement geoElem = elem.get_Geometry(geoOptions); //GeometryObjectArray geoElems = geoElem.Objects; IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator(); //foreach (object o in geoElems) while (Objects.MoveNext()) { object o = Objects.Current; GeoSolid geoSolid = o as GeoSolid; if (null == geoSolid) { continue; } return(geoSolid.Faces); } return(null); }
/// <summary> /// Get Solids from Element /// </summary> /// <param name="element"></param> /// <returns></returns> private static IList <Autodesk.Revit.DB.Solid> GetSolidsFromElement(Autodesk.Revit.DB.Element element) { GeometryElement geo = element.get_Geometry(new Options() { ComputeReferences = true }); List <Autodesk.Revit.DB.Solid> solids = new List <Autodesk.Revit.DB.Solid>(); foreach (object obj in geo) { GeometryInstance geoinstance = obj as GeometryInstance; if (geoinstance != null) { foreach (object solidobj in geoinstance.GetInstanceGeometry()) { if (solidobj.GetType() == typeof(Autodesk.Revit.DB.Solid)) { Autodesk.Revit.DB.Solid solid = solidobj as Autodesk.Revit.DB.Solid; solids.Add(solid); } } } } return(solids); }
/// <summary> /// Private constructor that constructs a FreeForm from a user-provided /// solid /// </summary> /// <param name="solid"></param> private FreeForm(Autodesk.Revit.DB.Solid mySolid) { //Phase 1 - Check to see if the object exists and should be rebound var ele = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FreeFormElement>(Document); // mutate with new solid, if possible if (ele != null) { InternalSetFreeFormElement(ele); if (InternalSetSolid(mySolid)) { return; } } // recreate freeform TransactionManager.Instance.EnsureInTransaction(Document); var freeForm = FreeFormElement.Create(Document, mySolid); InternalSetFreeFormElement(freeForm); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }
/// <summary> /// Attempt to set the internal solid. If this method fails, return false. /// </summary> /// <param name="solid"></param> /// <returns></returns> private bool InternalSetSolid(Autodesk.Revit.DB.Solid solid) { var revitAPIAssembly = System.Reflection.Assembly.GetAssembly(typeof(GenericForm)); var FreeFormType = revitAPIAssembly.GetType("Autodesk.Revit.DB.FreeFormElement", true); var freeFormInstanceMethods = FreeFormType.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); var nameOfMethodUpdate = "UpdateToSolidGeometry"; var nameOfMethodUpdateAlt = "UpdateSolidGeometry"; var method = freeFormInstanceMethods.FirstOrDefault( x => x.Name == nameOfMethodUpdate || x.Name == nameOfMethodUpdateAlt); if (method != null) { TransactionManager.Instance.EnsureInTransaction(Document); method.Invoke(InternalFreeFormElement, new object[] { solid }); TransactionManager.Instance.TransactionTaskDone(); return(true); } return(false); }
public static Brep ToRhino(this DB.Solid solid) { return(solid.Faces. Cast <DB.Face>(). Select(x => x.ToRhino()). ToArray(). JoinAndMerge(Revit.VertexTolerance)); }
public static Brep ToRhino(DB.Solid solid) { if (solid is null) { return(null); } var brep = new Brep(); if (!solid.Faces.IsEmpty) { var brepEdges = new Dictionary <DB.Edge, BrepEdge>(); foreach (var face in solid.Faces.Cast <DB.Face>()) { // Set surface var si = AddSurface(brep, face, out var shells, brepEdges); if (si < 0) { continue; } // Set edges & trims TrimSurface(brep, si, !face.MatchesSurfaceOrientation(), shells); } // Set vertices brep.SetVertices(); // Set flags brep.SetTolerancesBoxesAndFlags ( true, true, true, true, true, true, true, true ); if (!brep.IsValid) { #if DEBUG brep.IsValidWithLog(out var log); Debug.WriteLine($"{MethodInfo.GetCurrentMethod().DeclaringType.FullName}.{MethodInfo.GetCurrentMethod().Name}()\n{log}"); #endif brep.Repair(Revit.VertexTolerance); } } return(brep); }
/// <summary> /// Removes all painted faces on an elementl /// </summary> /// <param name="Element">The element to removve painted faces</param> /// <returns name="Element">The modified element</returns> public static DynaElem RemovePaintElement(DynaElem Element) { string transactionName = "Remove Painted Faces of Element"; RevitDoc document = Element.InternalElement.Document; RevitElemId elementId = Element.InternalElement.Id; RevitDB.Options op = new RevitDB.Options(); RevitDB.GeometryElement geoElem = Element.InternalElement.get_Geometry(op); IList <RevitDB.Face> faces = new List <RevitDB.Face>(); foreach (RevitDB.GeometryObject geo in geoElem) { if (geo is RevitDB.Solid) { RevitDB.Solid solid = geo as RevitDB.Solid; foreach (RevitDB.Face face in solid.Faces) { faces.Add(face); } } else if (geo is RevitDB.Face) { faces.Add(geo as RevitDB.Face); } Action <RevitElemId, IList <RevitDB.Face> > RemovePaintedFaces = (RevitElemId elemId, IList <RevitDB.Face> faceList) => { foreach (RevitDB.Face face in faceList) { document.RemovePaint(elemId, face); } }; if (document.IsModifiable) { TransactionManager.Instance.EnsureInTransaction(document); RemovePaintedFaces(elementId, faces); TransactionManager.Instance.TransactionTaskDone(); } else { using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document)) { trans.Start(transactionName); RemovePaintedFaces(elementId, faces); trans.Commit(); } } } return(Element); }
internal static Brep ToBrep(DB.Solid solid) { return(JoinAndMerge ( solid.Faces. Cast <DB.Face>(). Select(x => ToBrep(x)). ToArray(), Revit.VertexTolerance )); }
public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args) { Solid thisSolid = (Solid)((FScheme.Value.Container)args[0]).Item; Line selectLine = (Line)((FScheme.Value.Container)args[1]).Item; FaceArray faceArr = thisSolid.Faces; var thisEnum = faceArr.GetEnumerator(); SortedList <double, Autodesk.Revit.DB.Face> intersectingFaces = new SortedList <double, Autodesk.Revit.DB.Face>(); for (; thisEnum.MoveNext();) { Autodesk.Revit.DB.Face thisFace = (Autodesk.Revit.DB.Face)thisEnum.Current; IntersectionResultArray resultArray = null; SetComparisonResult resultIntersect = thisFace.Intersect(selectLine, out resultArray); if (resultIntersect != SetComparisonResult.Overlap) { continue; } bool first = true; double linePar = -1.0; foreach (IntersectionResult ir in resultArray) { double irPar = ir.Parameter; if (first == true) { linePar = irPar; first = false; } else if (irPar < linePar) { linePar = irPar; } } intersectingFaces.Add(linePar, thisFace); } var result = FSharpList <FScheme.Value> .Empty; var intersectingFacesEnum = intersectingFaces.Reverse().GetEnumerator(); for (; intersectingFacesEnum.MoveNext();) { Autodesk.Revit.DB.Face faceObj = intersectingFacesEnum.Current.Value; result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(faceObj), result); } return(FScheme.Value.NewList(result)); }
static Rhino.Geometry.GeometryBase ToRhino(this Autodesk.Revit.DB.Solid solid) { bool hasNonPlanarFaces = false; foreach (var face in solid.Faces) { if (hasNonPlanarFaces = !(face is PlanarFace)) { break; } } if (hasNonPlanarFaces) { // Emergency conversion to mesh var triangulateLevelOfDetail = GraphicAttributes.Peek.TriangulateLevelOfDetail; var facesMeshes = new List <Rhino.Geometry.Mesh>(solid.Faces.Size); foreach (var face in solid.Faces.OfType <Face>()) { facesMeshes.Add((double.IsNaN(triangulateLevelOfDetail) ? face.Triangulate() : face.Triangulate(triangulateLevelOfDetail)).ToRhino()); } if (facesMeshes.Count > 0) { var mesh = new Rhino.Geometry.Mesh(); mesh.Append(facesMeshes); return(mesh); } return(null); } else { var faces = new List <Rhino.Geometry.Brep>(solid.Faces.Size); foreach (var face in solid.Faces) { switch (face) { case PlanarFace planarFace: faces.AddRange(planarFace.ToRhino()); break; } } var breps = Rhino.Geometry.Brep.JoinBreps(faces, Revit.VertexTolerance); return(Rhino.Geometry.Brep.MergeBreps(breps, Revit.VertexTolerance)); } }
public static Brep ToRhino(DB.Solid solid) { if (solid.Faces.IsEmpty) { return(null); } var brep = new Brep(); var brepEdges = new Dictionary <DB.Edge, BrepEdge>(); foreach (var face in solid.Faces.Cast <DB.Face>()) { // Set surface var si = AddSurface(brep, face, out var shells, brepEdges); if (si < 0) { continue; } // Set edges & trims TrimSurface(brep, si, !face.MatchesSurfaceOrientation(), shells); } // Set vertices brep.SetVertices(); // Set flags brep.SetTolerancesBoxesAndFlags ( true, true, true, true, true, true, true, true ); if (!brep.IsValid) { #if DEBUG brep.IsValidWithLog(out var log); #endif brep.Repair(Revit.VertexTolerance); } return(brep); }
public Autodesk.Revit.DB.Solid CreateSolidFromBoundingBox(Autodesk.Revit.DB.Solid inputSolid) { BoundingBoxXYZ bbox = inputSolid.GetBoundingBox(); // Corners in BBox coords XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z); XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z); XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z); XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z); // Edges in BBox coords Autodesk.Revit.DB.Line edge0 = Autodesk.Revit.DB.Line.CreateBound(pt0, pt1); Autodesk.Revit.DB.Line edge1 = Autodesk.Revit.DB.Line.CreateBound(pt1, pt2); Autodesk.Revit.DB.Line edge2 = Autodesk.Revit.DB.Line.CreateBound(pt2, pt3); Autodesk.Revit.DB.Line edge3 = Autodesk.Revit.DB.Line.CreateBound(pt3, pt0); // Create loop, still in BBox coords List <Autodesk.Revit.DB.Curve> edges = new List <Autodesk.Revit.DB.Curve>(); edges.Add(edge0); edges.Add(edge1); edges.Add(edge2); edges.Add(edge3); double height = bbox.Max.Z - bbox.Min.Z; CurveLoop baseLoop = CurveLoop.Create(edges); List <CurveLoop> loopList = new List <CurveLoop>(); loopList.Add(baseLoop); Autodesk.Revit.DB.Solid preTransformBox = GeometryCreationUtilities .CreateExtrusionGeometry(loopList, XYZ.BasisZ, height); Autodesk.Revit.DB.Solid transformBox = SolidUtils.CreateTransformed( preTransformBox, bbox.Transform); return(preTransformBox); }
/// <summary> /// Obtain a point collection outlining a Solid GeometryObject /// </summary> /// <param name="solid"></param> /// <param name="pts"></param> protected static void GetPointCloud(Autodesk.Revit.DB.Solid solid, List <XYZ> pts) { foreach (Edge gEdge in solid.Edges) { var c = gEdge.AsCurve(); if (c is Line) { pts.Add(c.Evaluate(0, true)); pts.Add(c.Evaluate(1, true)); } else { IList <XYZ> xyzArray = gEdge.Tessellate(); pts.AddRange(xyzArray); } } }
/// <summary> /// Get the edges and faces from the solid and convert them /// </summary> /// <param name="solid"></param> /// <param name="reference"></param> /// <param name="transform"></param> /// <returns></returns> public static IEnumerable <object> ConvertToMany(this Autodesk.Revit.DB.Solid solid, Autodesk.Revit.DB.Reference reference = null, Autodesk.DesignScript.Geometry.CoordinateSystem transform = null) { if (solid == null) { return(null); } try { var convertedGeoms = InternalConvertToMany(solid); return(convertedGeoms.Select(x => { return Tag(Transform(x, transform), reference); })); } catch (Exception) { return(null); } }
public static void DrawSolid(RenderDescription description, object obj) { Autodesk.Revit.DB.Solid solid = obj as Autodesk.Revit.DB.Solid; if (solid == null) { return; } foreach (Face f in solid.Faces) { DrawFace(description, f); } foreach (Edge edge in solid.Edges) { DrawCurve(description, edge.AsCurve()); } }
public static List <Curve> IntersectWithCurve(global::Revit.Elements.Room room, Curve curve) { List <Curve> curveList = null; Autodesk.Revit.DB.Architecture.Room internalRoom = (Autodesk.Revit.DB.Architecture.Room)room.InternalElement; Autodesk.Revit.DB.GeometryElement roomGeometryElement = internalRoom.ClosedShell; foreach (GeometryObject geoObj in roomGeometryElement) { if (geoObj is Autodesk.Revit.DB.Solid) { Autodesk.Revit.DB.Solid geoSolid = geoObj as Autodesk.Revit.DB.Solid; Autodesk.Revit.DB.SolidCurveIntersection intersectingCurve = geoSolid.IntersectWithCurve(curve.ToRevitType(), new SolidCurveIntersectionOptions()); curveList = intersectingCurve.Select(c => c.ToProtoType()).ToList(); } } return(curveList); }
const double PRECISION = 0.00001; //precision when judge whether two doubles are equal /// <summary> /// get all faces that compose the geometry solid of given element /// </summary> /// <param name="elem">element to be calculated</param> /// <returns>all faces</returns> public static FaceArray GetFaces(Element elem) { List <Face> faces = new List <Face>(); Autodesk.Revit.DB.Options geoOptions = Command.CommandData.Application.Application.Create.NewGeometryOptions(); geoOptions.ComputeReferences = true; GeoElement geoElem = elem.get_Geometry(geoOptions); GeometryObjectArray geoElems = geoElem.Objects; foreach (object o in geoElems) { GeoSolid geoSolid = o as GeoSolid; if (null == geoSolid) { continue; } return(geoSolid.Faces); } return(null); }
static Rhino.Geometry.Mesh ToRhino(this Autodesk.Revit.DB.Solid solid) { var facesMeshes = new List <Rhino.Geometry.Mesh>(solid.Faces.Size); foreach (var face in solid.Faces) { switch (face) { case Face meshableFace: facesMeshes.Add(meshableFace.Triangulate().ToRhino()); break; } } if (facesMeshes.Count > 0) { var mesh = new Rhino.Geometry.Mesh(); mesh.Append(facesMeshes); mesh.Vertices.Align(Revit.VertexTolerance); return(mesh); } return(null); }
public static Brep ToBrep(this DB.Solid value) { var rhino = RawDecoder.ToRhino(value); UnitConverter.Scale(rhino, UnitConverter.ToRhinoUnits); return(rhino); }
public static Brep ToRhino(this DB.Solid solid) => RawDecoder.ToRhino(solid);
/// <summary> /// /// </summary> /// <param name="category"></param> /// <param name="refresh"></param> /// <returns></returns> public static List <List <Autodesk.DesignScript.Geometry.Point> > IntersectionPointsByCategory(Revit.Elements.Category category, Document document = null, bool refresh = false) { List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>(); List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >(); List <List <Autodesk.DesignScript.Geometry.Point> > cPoints = new List <List <Autodesk.DesignScript.Geometry.Point> >(); if (refresh) { BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true); Document doc = DocumentManager.Instance.CurrentDBDocument; //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication; //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument; ElementCategoryFilter filter = new ElementCategoryFilter(myCatEnum); ElementCategoryFilter exclude = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel); FilteredElementCollector excluded = new FilteredElementCollector(doc).WherePasses(exclude); FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType(); collector.Excluding(excluded.ToElementIds()); foreach (Autodesk.Revit.DB.Element e in collector) { DynaFunctions f = new DynaFunctions(); ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e); FilteredElementCollector interElem = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType(); if (interElem.GetElementCount() > 0) { List <Autodesk.Revit.DB.Solid> elGeoms = new List <Autodesk.Revit.DB.Solid>(); GeometryElement geomEl = e.get_Geometry(new Options()); foreach (GeometryObject geomObj in geomEl) { elGeoms.Add(geomObj as Autodesk.Revit.DB.Solid); } elList.Add(doc.GetElement(e.Id).ToDSType(true)); List <Autodesk.Revit.DB.Solid> iS = new List <Autodesk.Revit.DB.Solid>(); List <Autodesk.DesignScript.Geometry.Point> cPoint = new List <Autodesk.DesignScript.Geometry.Point>(); List <Autodesk.DesignScript.Geometry.Solid> iSS = new List <Autodesk.DesignScript.Geometry.Solid>(); foreach (Autodesk.Revit.DB.Element el in interElem) { GeometryElement intEl = el.get_Geometry(new Options()); foreach (GeometryObject intObj in intEl) { iS.Add(intObj as Autodesk.Revit.DB.Solid); } } foreach (Autodesk.Revit.DB.Solid s0 in elGeoms) { foreach (Autodesk.Revit.DB.Solid s1 in iS) { Autodesk.Revit.DB.Solid i = BooleanOperationsUtils.ExecuteBooleanOperation(s0, s1, BooleanOperationsType.Intersect); if (i != null) { iSS.Add(Revit.GeometryConversion.RevitToProtoSolid.ToProtoType(i)); DisplayUnitType dt = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits; XYZ coord = new XYZ(f.convertToUnit(i.ComputeCentroid().X, dt), f.convertToUnit(i.ComputeCentroid().Y, dt), f.convertToUnit(i.ComputeCentroid().Z, dt)); //XYZ coord = new XYZ(i.ComputeCentroid().X, i.ComputeCentroid().Y, i.ComputeCentroid().Z); Autodesk.DesignScript.Geometry.Point p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(coord.X, coord.Y, coord.Z); cPoint.Add(p); } } } cPoints.Add(cPoint); } } } return(cPoints); }
/// <summary> /// /// </summary> /// <param name="category"></param> /// <param name="refresh"></param> /// <returns></returns> public static List <List <Autodesk.DesignScript.Geometry.Solid> > IntersectionSolidsByCategory(Revit.Elements.Category category, Document document = null, bool refresh = false) { List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>(); List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >(); List <List <Autodesk.DesignScript.Geometry.Solid> > interGeoms = new List <List <Autodesk.DesignScript.Geometry.Solid> >(); if (refresh) { BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true); Document doc = DocumentManager.Instance.CurrentDBDocument; //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication; //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument; ElementCategoryFilter filter = new ElementCategoryFilter(myCatEnum); ElementCategoryFilter exclude = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel); FilteredElementCollector excluded = new FilteredElementCollector(doc).WherePasses(exclude); FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType(); collector.Excluding(excluded.ToElementIds()); foreach (Autodesk.Revit.DB.Element e in collector) { DynaFunctions f = new DynaFunctions(); ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e); FilteredElementCollector interElem = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType(); if (interElem.GetElementCount() > 0) { List <Autodesk.Revit.DB.Solid> elGeoms = new List <Autodesk.Revit.DB.Solid>(); GeometryElement geomEl = e.get_Geometry(new Options()); foreach (GeometryObject geomObj in geomEl) { elGeoms.Add(geomObj as Autodesk.Revit.DB.Solid); } List <Autodesk.Revit.DB.Solid> iS = new List <Autodesk.Revit.DB.Solid>(); List <Autodesk.DesignScript.Geometry.Solid> iSS = new List <Autodesk.DesignScript.Geometry.Solid>(); foreach (Autodesk.Revit.DB.Element el in interElem) { GeometryElement intEl = el.get_Geometry(new Options()); foreach (GeometryObject intObj in intEl) { iS.Add(intObj as Autodesk.Revit.DB.Solid); } } foreach (Autodesk.Revit.DB.Solid s0 in elGeoms) { foreach (Autodesk.Revit.DB.Solid s1 in iS) { Autodesk.Revit.DB.Solid i = BooleanOperationsUtils.ExecuteBooleanOperation(s0, s1, BooleanOperationsType.Intersect); if (i != null) { Autodesk.Revit.DB.Solid bbox = f.CreateSolidFromBoundingBox(i); iSS.Add(Revit.GeometryConversion.RevitToProtoSolid.ToProtoType(i)); } } } interGeoms.Add(iSS); } } } return(interGeoms); }
public static IEnumerable <Autodesk.Revit.DB.Face> GetRevitFaces(Autodesk.Revit.DB.Solid geom) { return(geom.Faces.Cast <Autodesk.Revit.DB.Face>()); }
public static IEnumerable <Surface> GetTrimmedSurfacesFromSolid(Autodesk.Revit.DB.Solid geom) { return(geom.Faces.Cast <Autodesk.Revit.DB.Face>().SelectMany(x => x.ToProtoType(false))); }
static FreeForm BySolid(Autodesk.Revit.DB.Solid s) { throw new NotImplementedException(); }
/// <summary> /// Gets the rectangular openings. /// </summary> /// <returns></returns> /// <remarks>This method uses walls, doors, windows and generic models bounding boxes to determine the rectangles. /// These objects can be in the host file or in linked Revit files.</remarks> public static IList <Autodesk.DesignScript.Geometry.Rectangle> GetRectangularOpenings() { Utils.Log(string.Format("OpeningUtils.GetRectangularOpenings started...", "")); Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //look for Walls, Doors, Windows, Generic Models in the current document and in the linked documents ElementCategoryFilter wallFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls); ElementCategoryFilter doorFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); ElementCategoryFilter windowFilter = new ElementCategoryFilter(BuiltInCategory.OST_Windows); ElementCategoryFilter genericFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel); IList <ElementFilter> filterList = new List <ElementFilter>() { wallFilter, doorFilter, windowFilter, genericFilter }; LogicalOrFilter orFilter = new LogicalOrFilter(filterList); IList <Autodesk.DesignScript.Geometry.Solid> solids = new List <Autodesk.DesignScript.Geometry.Solid>(); IList <Autodesk.DesignScript.Geometry.Rectangle> output = new List <Autodesk.DesignScript.Geometry.Rectangle>(); foreach (Autodesk.Revit.DB.Element e in new FilteredElementCollector(doc) .WherePasses(orFilter) .WhereElementIsNotElementType() .Where(x => x.Parameters.Cast <Autodesk.Revit.DB.Parameter>() .First(p => p.Id.IntegerValue == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).HasValue)) { string comments = e.Parameters.Cast <Autodesk.Revit.DB.Parameter>().First(p => p.Id.IntegerValue == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString(); if (comments.ToLower() != "opening") { continue; } Transform tr = Transform.Identity; if (e is Instance) { Instance instance = e as Instance; tr = instance.GetTotalTransform(); } IList <Autodesk.Revit.DB.Solid> temp = new List <Autodesk.Revit.DB.Solid>(); foreach (GeometryObject go in e.get_Geometry(new Options())) { if (go is GeometryInstance) { GeometryInstance geoInstance = go as GeometryInstance; foreach (var gi in geoInstance.SymbolGeometry) { if (gi is Autodesk.Revit.DB.Solid) { Autodesk.Revit.DB.Solid s = gi as Autodesk.Revit.DB.Solid; s = SolidUtils.CreateTransformed(s, tr); temp.Add(s); } } } else { if (go is Autodesk.Revit.DB.Solid) { Autodesk.Revit.DB.Solid s = go as Autodesk.Revit.DB.Solid; s = SolidUtils.CreateTransformed(s, tr); temp.Add(s); } } } if (temp.Count > 0) { Autodesk.Revit.DB.Solid s0 = temp[0]; for (int i = 1; i < temp.Count; ++i) { s0 = BooleanOperationsUtils.ExecuteBooleanOperation(s0, temp[i], BooleanOperationsType.Union); } solids.Add(s0.ToProtoType()); } } foreach (RevitLinkInstance rli in new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance)).WhereElementIsNotElementType()) { Autodesk.Revit.DB.Document link = rli.GetLinkDocument(); foreach (Autodesk.Revit.DB.Element e in new FilteredElementCollector(link) .WherePasses(orFilter) .WhereElementIsNotElementType() .Where(x => x.Parameters.Cast <Autodesk.Revit.DB.Parameter>() .First(p => p.Id.IntegerValue == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).HasValue)) { Transform tr = rli.GetTotalTransform(); string comments = e.Parameters.Cast <Autodesk.Revit.DB.Parameter>().First(p => p.Id.IntegerValue == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString(); if (comments.ToLower() != "opening") { continue; } if (e is Instance) { Instance instance = e as Instance; tr = tr.Multiply(instance.GetTotalTransform()); } IList <Autodesk.Revit.DB.Solid> temp = new List <Autodesk.Revit.DB.Solid>(); foreach (var go in e.get_Geometry(new Options())) { if (go is GeometryInstance) { GeometryInstance geoInstance = go as GeometryInstance; foreach (var gi in geoInstance.SymbolGeometry) { if (gi is Autodesk.Revit.DB.Solid) { Autodesk.Revit.DB.Solid s = gi as Autodesk.Revit.DB.Solid; s = SolidUtils.CreateTransformed(s, tr); temp.Add(s); } } } else { if (go is Autodesk.Revit.DB.Solid) { Autodesk.Revit.DB.Solid s = go as Autodesk.Revit.DB.Solid; s = SolidUtils.CreateTransformed(s, tr); temp.Add(s); } } } if (temp.Count > 0) { Autodesk.Revit.DB.Solid s0 = temp[0]; for (int i = 1; i < temp.Count; ++i) { s0 = BooleanOperationsUtils.ExecuteBooleanOperation(s0, temp[i], BooleanOperationsType.Union); } solids.Add(s0.ToProtoType()); } } } foreach (var s in solids) { IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); foreach (var v in s.Vertices) { points.Add(v.PointGeometry); } points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); Autodesk.DesignScript.Geometry.Plane plane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(points); plane = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(points.Last(), plane.Normal); IList <Autodesk.DesignScript.Geometry.Point> temp = new List <Autodesk.DesignScript.Geometry.Point>(); foreach (var p in points) { foreach (var q in p.Project(plane, plane.Normal)) { temp.Add(q as Autodesk.DesignScript.Geometry.Point); } foreach (var q in p.Project(plane, plane.Normal.Reverse())) { temp.Add(q as Autodesk.DesignScript.Geometry.Point); } } temp = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(temp); CoordinateSystem cs = CoordinateSystem.ByPlane(plane); IList <Autodesk.DesignScript.Geometry.Point> relative = new List <Autodesk.DesignScript.Geometry.Point>(); foreach (var p in temp) { relative.Add(p.Transform(cs.Inverse()) as Autodesk.DesignScript.Geometry.Point); } var min = Autodesk.DesignScript.Geometry.Point.ByCoordinates(relative.Min(p => p.X), relative.Min(p => p.Y), relative.Min(p => p.Z)); var max = Autodesk.DesignScript.Geometry.Point.ByCoordinates(relative.Max(p => p.X), relative.Max(p => p.Y), relative.Max(p => p.Z)); double width = max.X - min.X; double height = max.Y - min.Y; min = min.Transform(cs) as Autodesk.DesignScript.Geometry.Point; max = max.Transform(cs) as Autodesk.DesignScript.Geometry.Point; plane = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(min, max).PointAtParameter(0.5), plane.Normal); Autodesk.DesignScript.Geometry.Rectangle rectangle = Autodesk.DesignScript.Geometry.Rectangle.ByWidthLength(plane, width, height); output.Add(rectangle); plane.Dispose(); cs.Dispose(); min.Dispose(); max.Dispose(); } Utils.Log(string.Format("OpeningUtils.GetRectangularOpenings completed.", "")); return(output); }