123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- namespace RevitToJBim.Extension
- {
- public static class GeometryElementExtension
- {
-
-
-
-
-
-
- public static List<T> GetGeometryOriginalObjects<T>(this GeometryElement geoElement) where T : GeometryObject
- {
- List<T> listRtn = new List<T>();
- List<GeometryElement> useElements = new List<GeometryElement>() { geoElement };
- for (int i = 0; i < useElements.Count; i++)
- {
- var useGeoElement = useElements[i];
- foreach (var geoObject in useGeoElement)
- {
-
- if (geoObject is T)
- {
- listRtn.Add(geoObject as T);
- }
- else if (geoObject is GeometryInstance)
- {
- var childElment = (geoObject as GeometryInstance).GetInstanceGeometry();
- if (childElment != null)
- {
- useElements.Add(childElment);
- }
- }
- else if (geoObject is GeometryElement)
- {
- useElements.Add(geoObject as GeometryElement);
- }
- }
- }
- return listRtn;
- }
- public static List<T> GetGeometryObjects<T>(this GeometryElement geoElement) where T : GeometryObject
- {
- List<T> listRtn = geoElement.GetGeometryOriginalObjects<T>();
- if (listRtn.Count == 0)
- {
-
- var geoElementNew = geoElement.GetTransformed(Transform.Identity);
- listRtn = geoElementNew.GetGeometryOriginalObjects<T>();
- }
- return listRtn;
- }
-
-
-
-
-
-
-
- public static GeometryElement GetGeometryElement(this Element element, bool visibleObj = false, View view = null)
- {
- var options = new Options();
- options.ComputeReferences = true;
- options.IncludeNonVisibleObjects = visibleObj;
- if (view == null)
- {
- options.DetailLevel = ViewDetailLevel.Fine;
- }
- else
- {
- options.View = view;
- }
- return element.get_Geometry(options);
- }
-
-
-
-
-
-
-
- public static List<Solid> GetSolids(this Element elem, View view = null, bool visibleObj = false)
- {
- var geoElement = elem.GetGeometryElement(visibleObj, view);
- return geoElement.GetGeometryObjects<Solid>();
- }
-
-
-
-
-
-
-
- public static List<T> GetGeometryObjects<T>(this Element elem, View view = null, bool visibleObj = false) where T : GeometryObject
- {
- var geoElement = elem.GetGeometryElement(visibleObj, view);
- return geoElement.GetGeometryObjects<T>();
- }
- }
- }
|