123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
-
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Mechanical;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Extend;
- using SAGA.RevitUtils.Extends;
- using ServiceRevitLib.Common;
- namespace ServiceRevitLib.Extend
- {
-
-
-
- public static class ElementExtend
- {
-
-
-
-
-
- public static bool IsStart(this Element element)
- {
- return (element.GetParameterString(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS) ?? string.Empty).StartsWith(MBIConst.StartFlag);
- }
-
-
-
-
-
-
- public static bool IsEquipment(this Element element)
- {
- bool result = false;
-
-
-
-
-
- if (element is FamilyInstance fi)
- {
- var family = fi.GetFamilyName();
- result = Regex.IsMatch(family, $"{RegexConstPattern.IsEquip}");
- }
- return result;
- }
-
-
-
-
-
- public static bool IsEquipmentPart(this Element element)
- {
- bool result = false;
- if (element is FamilyInstance fi)
- {
- var family = fi.GetFamilyName();
- result = Regex.IsMatch(family, $"{RegexConstPattern.IsEquipPart}");
- }
- return result;
- }
-
-
-
-
-
- public static bool IsMbiEquipment(this Element element)
- {
- return element.IsEquipment()||element.IsEquipmentPart();
- }
-
-
-
-
-
- public static bool IsBeacon(this Element elem)
- {
- var family = elem.GetFamilyName();
- return family != null && (Regex.IsMatch(family, RegexConstPattern.IsBeacon));
- }
-
-
-
-
-
-
-
- public static bool IsSpace(this Element elem, bool ischeckzero = true)
- {
- var isspace = false;
- if (elem is Space space)
- {
-
- isspace = !ischeckzero || !(space.IsDeleteSpace());
-
-
- }
- return isspace;
- }
-
-
-
-
-
- public static XYZ GetLocationPointMBIXYZ(this Element element)
- {
-
-
-
-
-
-
-
-
-
-
-
- XYZ bimXyz = element.GetBoxCenter();
- return bimXyz;
- }
-
-
-
-
- public static string GetLocationPointMBI(this Element element)
- {
- string str = ",,";
- XYZ bimXyz = element.GetLocationPointMBIXYZ();
- if (bimXyz != null)
- {
- str = bimXyz.FromApi().ToString(null);
- };
-
-
-
-
-
- return str;
- }
-
-
-
-
- public static XYZ ToXyz(this string xyzstr)
- {
- XYZ xyz = null;
- var strs = xyzstr.Split(',');
- if (strs.Length == 3)
- {
- xyz = new XYZ(strs[0].ToDouble(), strs[1].ToDouble(), strs[2].ToDouble());
- }
-
-
-
-
-
- return xyz;
- }
-
-
-
-
-
- public static string GetFamilyCode(this Element element)
- {
- string code = "";
- if (element is FamilyInstance fi)
- {
- string familyName = fi.GetFamilyName();
- if (familyName == null) return code;
-
- int index = familyName.IndexOf('-');
- if (index != -1 && index + 1 != familyName.Length)
- code = familyName.Substring(0, familyName.IndexOf('-'));
-
- code = code.Trim();
- }
- return code;
- }
- public static string GetFamilyName(this Element element)
- {
- return element.GetFamily()?.Name;
- }
-
-
-
-
-
- public static Space GetReferenceSpace(this Element element, List<Space> spaces = null)
- {
- Space space = null;
- if (element is FamilyInstance fi)
- {
- space = fi.Space;
- if (space != null) return space;
- if (spaces == null)
- spaces = fi.Document.GetSpaces().Where(t => t.IsValidObject).ToList();
- var origin1 = fi.GetLocationPointMBIXYZ();
- foreach (Space tempSpace in spaces)
- {
-
- if (tempSpace.IsPointInSpace(origin1))
- {
- space = tempSpace;
- break;
- }
- }
- }
- return space;
- }
-
-
-
-
-
- public static Element GetPartParent(this Element element)
- {
- string code = element?.GetFamily().Name.Substring(0, 4); ;
- if (code.IsNullOrEmpty()) return null;
-
- var parentInst = element?.Document.GetElements(new ElementIntersectsElementFilter(element))
- .FirstOrDefault(t => !t.Id.IsEqual(element.Id) && t.GetFamilyCode() == code);
- return parentInst;
- }
- }
- }
|