using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Plumbing; namespace FWindSoft.Revit { public static class ElementExtension { /// /// 获取定位线 /// /// /// public static Curve GetLocationCurve(this Element element) { return element.Location?.ConvertToCurve(); } /// /// 获取定位线 /// /// /// public static Line GetLocationLine(this Element element) { return element.Location?.ConvertToLine(); } /// /// 获取元素定位点 /// /// /// public static XYZ GetLocationPoint(this Element element) { return element.Location?.ConvertToPoint(); } /// /// 获取元素开始点 /// /// /// public static XYZ StartPoint(this Element element) { return element.GetLocationCurve()?.StartPoint(); } /// /// 获取元素结束点 /// /// /// public static XYZ EndPoint(this Element element) { return element.GetLocationCurve()?.EndPoint(); } public static BuiltInCategory GetCategory(this Element elem) { var bic = BuiltInCategory.INVALID; if (elem.Category != null) { bic = (BuiltInCategory)elem.Category.Id.IntegerValue; } return bic; } /// /// 元素旋转信息 /// /// /// /// public static void Rotate(this Element element, Line axis, double angle) { ElementTransformUtils.RotateElement(element.Document, element.Id, axis, angle); } /// /// 获取元素的内置分类 /// /// /// public static BuiltInCategory GetBuiltInCategory(this Element elem) { var bic = BuiltInCategory.INVALID; if (!elem.IsValidObject) return BuiltInCategory.INVALID; if (elem.Category != null && elem.Category.Id != null) { bic = (BuiltInCategory)elem.Category.Id.IntegerValue; } return bic; } public static bool IsWaterComponment(this Element element) { return element is Pipe || element is FlexPipe || (element is FamilyInstance && element.GetBuiltInCategory() == BuiltInCategory.OST_PipeFitting); } public static bool IsHavcComponment(this Element element) { return element is Duct|| element is FlexDuct || (element is FamilyInstance && element.GetBuiltInCategory() == BuiltInCategory.OST_DuctFitting); } /// /// 获取图元类型 /// /// /// public static ElementType GetElementType(this Element element) { ElementId id = element.GetTypeId(); if (id != null && id != ElementId.InvalidElementId) { Element elementType = element.Document.GetElement(id); return elementType as ElementType; } return null; } /// /// 获取图元类型 /// /// /// /// public static T GetElementType(this Element element) where T : ElementType { ElementId id = element.GetTypeId(); if (id != null && id != ElementId.InvalidElementId) { Element elementType = element.Document.GetElement(id); return elementType as T; } return null; } /// /// 获取参照标高 /// /// /// public static Level GetLevel(this Element element) { Level level = null; ElementId eId = element.GetLevelId(); if (eId != ElementId.InvalidElementId) { level = element.Document.GetElement(eId) as Level; } return level; } /// /// 获取参照标高Id /// /// /// public static ElementId GetLevelId(this Element element) { return element.GetParameterElementId(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM); } /// /// 参照标高 /// /// /// public static void SetLevel(this Element element, Level level) { if (level != null) { element.SetLevel(level.Id); } } /// /// 设置参照标高参照标高 /// /// /// public static void SetLevel(this Element element, ElementId levelId) { element.SetParameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM, levelId); } } }