using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.UI.Selection; using SAGA.DotNetUtils; using SAGA.DotNetUtils.Extend; using SAGA.RevitAPI; using SAGA.RevitUtils.MEP; namespace SAGA.RevitUtils.Extends { public static class DocumentExtend { /// /// rvt项目名称 /// /// /// public static string GetShortTitle(this Document doc) { string strTitle = doc.Title; string strExtend = Path.GetExtension(strTitle); if (strExtend != null && strExtend.Length > 0) { if (!strExtend.StartsWith(".")) strExtend = "." + strExtend; int intIndex = strTitle.IndexOf(strExtend); if (intIndex > 0) strTitle = strTitle.Substring(0, intIndex); } if (strTitle.Length > 12 + 3) { if (strExtend != null && strExtend.Length > 0) { return strTitle.Substring(0, 12) + "..." + strExtend; } return strTitle.Substring(0, 12) + "..."; } return doc.Title; } /// /// 文档信息 /// /// /// public static string GetPathNameOrTitle(this Document doc) { //新建时为空,返回项目名称 if (string.IsNullOrEmpty(doc.PathName)) return doc.Title; //项目磁盘全文件名 return doc.PathName; } /// /// 文档所有图元 /// /// /// 默认只取实例图元 /// public static List GetAllElements(this Document doc, bool isContainElementType = false) { if (isContainElementType) { FilteredElementCollector elemTypeCtor = (new FilteredElementCollector(doc)).WhereElementIsElementType(); FilteredElementCollector notElemTypeCtor = (new FilteredElementCollector(doc)).WhereElementIsNotElementType(); FilteredElementCollector allElementCtor = elemTypeCtor.UnionWith(notElemTypeCtor); return allElementCtor.ToElements().ToList(); } else { FilteredElementCollector notElemTypeCtor = (new FilteredElementCollector(doc)).WhereElementIsNotElementType(); return notElemTypeCtor.ToElements().ToList(); } } /// /// 大部分几何图元,有一部分没用的 /// /// /// public static List GetGeomElements(this Document doc) { double dExtend = 1000000; dExtend = dExtend.ToApi(); XYZ ptMin = new XYZ(-dExtend, -dExtend, -dExtend); XYZ ptMax = new XYZ(dExtend, dExtend, dExtend); Outline otl = new Outline(ptMin, ptMax); return doc.GetElements(otl); } /// /// 空间矩形框 /// /// /// /// /// /// /// public static Outline CreateOutline(this Document doc, Level baseLevel, Level topLevel, double baseOffset, double topOffset) { if (baseLevel.IsEqual(topLevel)) { List listLevel = doc.GetLevels(); int intIndex = listLevel.FindIndex(p => p.IsEqual(baseLevel)); if (intIndex == 0) { topLevel = listLevel[intIndex + 1]; } if (intIndex > 0) { baseLevel = listLevel[intIndex - 1]; } } double dExtend = 9999999999d.ToApi(); baseOffset = baseOffset.ToApi(); topOffset = topOffset.ToApi(); XYZ ptMin = new XYZ(-dExtend, -dExtend, baseLevel.Elevation + baseOffset); XYZ ptMax = new XYZ(dExtend, dExtend, topLevel.Elevation + topOffset); Outline otl = new Outline(ptMin, ptMax); return otl; } public static ElementFilter CreateAvailablyFilter(this Document doc) { if (true) { LogicalAndFilter andFilter = new LogicalAndFilter(new List { new ElementCategoryFilter(BuiltInCategory.OST_Elev, true), new ElementCategoryFilter(BuiltInCategory.OST_Cameras, true), new ElementCategoryFilter(BuiltInCategory.OST_Views, true), new ElementCategoryFilter(BuiltInCategory.OST_Viewers, true), new ElementCategoryFilter(BuiltInCategory.OST_Grids, true), new ElementCategoryFilter(BuiltInCategory.OST_SharedBasePoint, true), new ElementCategoryFilter(BuiltInCategory.OST_ProjectBasePoint, true), new ElementCategoryFilter(BuiltInCategory.OST_AnalyticalNodes, true), //new ElementCategoryFilter(BuiltInCategory.OST_WallAnalytical, true), }); return andFilter; } else { LogicalOrFilter orFilter = new LogicalOrFilter(new List { new ElementCategoryFilter(BuiltInCategory.OST_StructConnections), new ElementCategoryFilter(BuiltInCategory.OST_StructConnectionTags), //new ElementCategoryFilter(BuiltInCategory.OST_StructLocationLineControl), new ElementCategoryFilter(BuiltInCategory.OST_StructuralAnnotations), new ElementCategoryFilter(BuiltInCategory.OST_StructuralBracePlanReps), new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns), new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumnTags), //new ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundation), //new ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundationTags), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingOpening), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingOther), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingSystem), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingTags), new ElementCategoryFilter(BuiltInCategory.OST_StructuralStiffener), new ElementCategoryFilter(BuiltInCategory.OST_StructuralStiffenerTags), new ElementCategoryFilter(BuiltInCategory.OST_StructuralTruss), new ElementCategoryFilter(BuiltInCategory.OST_Floors), new ElementCategoryFilter(BuiltInCategory.OST_FloorOpening), new ElementCategoryFilter(BuiltInCategory.OST_FloorTags), new ElementCategoryFilter(BuiltInCategory.OST_Walls), new ElementCategoryFilter(BuiltInCategory.OST_WallTags), new ElementCategoryFilter(BuiltInCategory.OST_GenericModel), new ElementCategoryFilter(BuiltInCategory.OST_GenericModel), }); return orFilter; } } /// /// 两个标高之间和图元 /// /// /// /// /// /// /// /// public static List GetAvailablyElements(this Document doc, Level levelBase, Level levelTop, double baseOffset, double topOffset, ViewDisciplineT viewDisciplineT) { Outline otl = doc.CreateOutline(levelBase, levelTop, baseOffset, topOffset); ElementFilter elementeFilter = doc.CreateAvailablyFilter(viewDisciplineT); return doc.GetElements(otl, elementeFilter); } public static ElementFilter CreateAvailablyFilter(this Document doc, ViewDisciplineT viewDisciplineT) { if (viewDisciplineT == ViewDisciplineT.Architectural) { LogicalAndFilter andFilter = new LogicalAndFilter(new List { new ElementCategoryFilter(BuiltInCategory.OST_Elev, true), new ElementCategoryFilter(BuiltInCategory.OST_Cameras, true), new ElementCategoryFilter(BuiltInCategory.OST_Views, true), new ElementCategoryFilter(BuiltInCategory.OST_Viewers, true), new ElementCategoryFilter(BuiltInCategory.OST_Grids, true), new ElementCategoryFilter(BuiltInCategory.OST_SharedBasePoint, true), new ElementCategoryFilter(BuiltInCategory.OST_ProjectBasePoint, true), new ElementCategoryFilter(BuiltInCategory.OST_AnalyticalNodes, true), //new ElementCategoryFilter(BuiltInCategory.OST_WallAnalytical, true), }); return andFilter; } else { LogicalOrFilter orFilter = new LogicalOrFilter(new List { new ElementCategoryFilter(BuiltInCategory.OST_StructConnections), new ElementCategoryFilter(BuiltInCategory.OST_StructConnectionTags), //new ElementCategoryFilter(BuiltInCategory.OST_StructLocationLineControl), new ElementCategoryFilter(BuiltInCategory.OST_StructuralAnnotations), new ElementCategoryFilter(BuiltInCategory.OST_StructuralBracePlanReps), new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns), new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumnTags), //new ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundation), //new ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundationTags), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingOpening), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingOther), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingSystem), new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingTags), new ElementCategoryFilter(BuiltInCategory.OST_StructuralStiffener), new ElementCategoryFilter(BuiltInCategory.OST_StructuralStiffenerTags), new ElementCategoryFilter(BuiltInCategory.OST_StructuralTruss), new ElementCategoryFilter(BuiltInCategory.OST_Floors), new ElementCategoryFilter(BuiltInCategory.OST_FloorOpening), new ElementCategoryFilter(BuiltInCategory.OST_FloorTags), new ElementCategoryFilter(BuiltInCategory.OST_Walls), new ElementCategoryFilter(BuiltInCategory.OST_WallTags), new ElementCategoryFilter(BuiltInCategory.OST_GenericModel), new ElementCategoryFilter(BuiltInCategory.OST_GenericModel), }); return orFilter; } } public static List GetAvailablyElements(this Document doc, Level levelBase, Level levelTop, double baseOffset, double topOffset, ViewDisciplineT viewDisciplineT, out List allElements) { allElements = null; Outline otl = doc.CreateOutline(levelBase, levelTop, baseOffset, topOffset); ElementFilter elementeFilter = doc.CreateAvailablyFilter(viewDisciplineT); allElements = doc.GetElements(otl); return doc.GetElements(otl, elementeFilter); } public static double GetWallSweepOrSteps(this Document doc, Wall wall, out double h) { h = 0; List wallSweepFilter = doc.FilterElements(); List instanceFilter = doc.FilterElements().Where(p => p.Symbol.Name.Contains("坡道")).ToList(); if (wallSweepFilter.Count > 0) { foreach (WallSweep wallSweep in wallSweepFilter) { List ids = wallSweep.GetHostIds().ToList(); foreach (ElementId id in ids) { if (id.IntegerValue == wall.Id.IntegerValue) { double heigth = wallSweep.GetParameterDoubleMm(BuiltInParameter.WALL_SWEEP_OFFSET_PARAM); //foreach (FamilyInstance instance in instanceFilter) //{ //if (instance.Host.Id.IntegerValue == wall.Id.IntegerValue) //{ if (heigth == 0) h = heigth; else h = heigth - 0.5; //} //} } } } } return h; } public static double GetWallSweepOrStairs(this Document doc, Wall wall, out double h) { h = 0; List wallSweepFilter = doc.FilterElements(); List instanceFilter = doc.FilterElements().Where(p => p.Symbol.Family.Name.Contains("台阶")).ToList(); if (wallSweepFilter.Count > 0) { foreach (WallSweep wallSweep in wallSweepFilter) { List ids = wallSweep.GetHostIds().ToList(); foreach (ElementId id in ids) { if (id.IntegerValue == wall.Id.IntegerValue) { double heigth = wallSweep.GetParameterDoubleMm(BuiltInParameter.WALL_SWEEP_OFFSET_PARAM); //foreach (FamilyInstance instance in instanceFilter) //{ //if (instance.Host.Id.IntegerValue == wall.Id.IntegerValue) //{ if (heigth == 0) h = heigth; else h = heigth - 0.5; //} //} } } } } return h; } public static List GetWallOrBeams(this Document doc) { ElementClassFilter wallFilter = new ElementClassFilter(typeof(Wall)); ElementClassFilter instanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementStructuralTypeFilter structuralTypeFilter = new ElementStructuralTypeFilter(StructuralType.Beam); LogicalAndFilter beamFilter = new LogicalAndFilter(instanceFilter, structuralTypeFilter); LogicalOrFilter wallOrBeam = new LogicalOrFilter(wallFilter, beamFilter); return doc.GetElements(doc.ActiveView, wallOrBeam); } /// /// 分类 /// /// /// /// public static Category GetCategory(this Document doc, BuiltInCategory category) { try { //有报错,如OST_StairsStringerCarriage 2015-10-26 return doc.Settings.Categories.get_Item(category); } catch (Exception ex) { Console.WriteLine(ex.Message); } return null; } /// /// 获取某一类别的重叠元素集(注:主要针对梁柱墙板构件) /// /// /// /// public static List> GetOverlapElements(this Document doc, BuiltInCategory category) { List> listElementList = new List>(); List elementList = new List(); elementList = doc.FilterElements(category); //建筑柱和建筑柱重叠需要检查,建筑柱和结构柱重叠,不算重叠。注:mjy 修改BUG foreach (Element element in elementList) { List resultList = new List(); switch (category) { case BuiltInCategory.OST_Columns: case BuiltInCategory.OST_StructuralColumns: FamilyInstance column = element as FamilyInstance; //double height = column.GetParameterDouble("柱截面高"); //double baseOffset = column.GetParameterDouble(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM); //double topOffset = column.GetParameterDouble(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM); //XYZ point = (element as FamilyInstance).GetLocationPoint(); //XYZ basePoint = point.NewZ(point.Z + baseOffset); //XYZ topPoint = point.NewZ(point.Z + baseOffset + height + topOffset); //Outline outline = new Outline(basePoint, topPoint); //BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(outline); //ElementCategoryFilter categoryFilter = new ElementCategoryFilter(category); //LogicalAndFilter andFiter = new LogicalAndFilter(filter, categoryFilter); //resultList = doc.GetElements(andFiter); ElementCategoryFilter categoryFilter = new ElementCategoryFilter(category); resultList = doc.GetElements(column, categoryFilter, 10d.ToApi()); break; case BuiltInCategory.OST_StructuralFraming: Curve curve = (element as FamilyInstance).GetLocationCurve(); XYZ startPoint = curve.StartPoint(); XYZ endPoint = curve.EndPoint(); XYZ norm = endPoint.Subtract(startPoint).Normalize(); startPoint += 0.01 * norm; endPoint -= 0.01 * norm; List leftElements = doc.GetElements(startPoint); List rightElements = doc.GetElements(endPoint); leftElements.RemoveAll(p => p.Id.IsEqual(element.Id) || !p.Category.IsEqual(category)); rightElements.RemoveAll(p => p.Id.IsEqual(element.Id) || !p.Category.IsEqual(category)); resultList = leftElements.Concat(rightElements).ToList(); break; default: resultList = element.GetIntersectElements(category, true); break; } #region 对墙进行二次处理 只保留定位线平行的墙 if (category == BuiltInCategory.OST_Walls) { Wall wall = element as Wall; resultList.RemoveAll(w => !((Wall)w).Location.GetCurve().IsParallel(wall.Location.GetCurve())); } if (category.Equals(BuiltInCategory.OST_StructuralFraming)) { FamilyInstance beam = element as FamilyInstance; Curve beamCurve = beam.GetLocationCurve(); resultList.RemoveAll(p => !((FamilyInstance)p).GetLocationCurve().IsParallel(beamCurve)); } #endregion if (resultList.Count <= 1) continue; #region 循环判断resultList的元素是否存在于listElementList,若存在则添加resultList中元素到对应序列中,若不存在则把resultList作为新项添加到listElementList中 if (listElementList.Exists(p => p.Exists(q => resultList.Exists(r => r.IsEqual(q))))) { foreach (List elList in listElementList) { if (resultList.Exists(p => elList.Exists(q => q.IsEqual(p)))) { elList.AddRange(resultList.FindAll(p => !elList.Exists(q => p.IsEqual(q))).ToArray()); break; } } } else listElementList.Add(resultList); #endregion } return listElementList; } public static DisplayUnitType GetDisplayUnitType(this Document doc) { try { UnitType unittype = UnitType.UT_Length; Units projectUnit = doc.GetUnits(); FormatOptions formatOption = projectUnit.GetFormatOptions(unittype); return formatOption.DisplayUnits; } catch { return DisplayUnitType.DUT_DECIMAL_FEET; } } /// /// 过滤类型对象 /// /// /// /// /// public static List FilterElements(this Document doc, View view = null) where T : class { FilteredElementCollector collector = null; if (view == null) { collector = new FilteredElementCollector(doc); } else { collector = new FilteredElementCollector(doc, view.Id); } return collector.OfClass(typeof(T)).ToList(); } /// /// 过滤类型对象 /// /// /// /// /// public static List FilterElements(this Document doc, Predicate condition) where T : Element { List listItems = doc.FilterElements(); List listRtn = new List(); foreach (T item in listItems) { if (condition(item)) listRtn.Add(item); } return listRtn; } /// /// 过滤类型对象 /// /// /// /// /// public static List FilterElements(this Document doc, ElementFilter filter) where T : Element { var collector = new FilteredElementCollector(doc); //collector = collector.OfClass(typeof(T)); collector = collector.WherePasses(filter); return collector.ToList(); } /// /// 类型过滤图元 /// /// /// /// public static List FilterElements(this Document doc, Type type) { var collector = new FilteredElementCollector(doc); return collector.OfClass(type).ToList(); } /// /// 过滤器过滤图元 /// /// /// /// public static List FilterElements(this Document doc, ElementFilter filter) { var collector = new FilteredElementCollector(doc); return collector.WherePasses(filter).ToList(); } /// /// 过滤器过滤图元 /// /// /// /// public static List FilterElements(this Document doc, IEnumerable elements, ElementFilter filter) { var collector = new FilteredElementCollector(doc, elements.Select(t => t.Id).ToList()); return collector.WherePasses(filter).ToList(); } /// /// 分类过滤实例图元 /// /// /// /// public static List FilterElements(this Document doc, BuiltInCategory bic) { List listRtn = null; var filter = new ElementCategoryFilter(bic); var collector = new FilteredElementCollector(doc); listRtn = collector.WherePasses(filter).WhereElementIsNotElementType().ToList(); return listRtn; } /// /// 分类过滤类型图元 /// /// /// /// public static List FilterElementTypes(this Document doc, BuiltInCategory bic) { List listRtn = null; var filter = new ElementCategoryFilter(bic); var collector = new FilteredElementCollector(doc); listRtn = collector.WherePasses(filter).WhereElementIsElementType().ToList(); return listRtn; } /// /// 获取类型 /// /// /// /// /// public static List FilterElementTypes(this Document doc, BuiltInCategory bic) { List listRtn = null; var filter = new ElementCategoryFilter(bic); var collector = new FilteredElementCollector(doc); listRtn = collector.WherePasses(filter).WhereElementIsElementType().ToList(); return listRtn; } public static List FilterInstances(this Document doc, IAllowElement allowElement, DrivenTypes drivenType) { List items = null; var collector = new FilteredElementCollector(doc); switch (drivenType) { case DrivenTypes.Curve: items = collector.WherePasses(new ElementIsCurveDrivenFilter(false)) .OfClass(typeof(FamilyInstance)).ToList(); break; case DrivenTypes.Point: default: break; } if (items != null) return items.Where(allowElement.IsAllow).ToList(); return null; } /// /// id返回图元 /// /// /// /// public static Element GetElement(this Document doc, int intId) { try { var id = new ElementId(intId); return doc.GetElement(id); } catch (Exception e) { return null; } } /// /// /// /// /// /// /// public static T GetElementT(this Document doc, ElementId id) where T : Element { return doc.GetElement(id) as T; } /// /// /// /// /// /// /// public static T GetElementT(this Document doc, string name) where T : Element { return doc.GetElement(name) as T; } /// /// 获取图元 /// /// /// /// public static List GetElements(this Document doc) where T : Element { return doc.FilterElements(); } /// /// 根据名称判断某类图元是否存在 2015-11-25 /// /// /// /// /// public static bool IsExistElement(this Document doc, string strName) where T : Element { return doc.GetElements().Exists(p => p.Name == strName); } /// /// 分类图元 /// /// /// /// /// public static List GetElements(this Document doc, BuiltInCategory bic) where T : Element { var filter = new ElementCategoryFilter(bic); return doc.FilterElements(filter); } /// /// 相交的图元,慢过滤 /// /// /// /// /// public static List GetElements(this Document doc, Element elem) where T : Element { var collector = new FilteredElementCollector(doc); var filter = new ElementIntersectsElementFilter(elem); return collector.WherePasses(filter).ToList(); } /// /// 获取图元 /// /// /// /// public static List GetElements(this Document doc, Type type) { return doc.FilterElements(type); } /// /// 通过类型获取图元 /// /// /// /// public static List GetElements(this Document doc, ElementType eleType) { List listRtn; BuiltInCategory cat = eleType.GetCategory(); //不是所有的图元都有Category if (cat != BuiltInCategory.INVALID) { listRtn = doc.FilterElements(cat); } else { listRtn = doc.GetAllElements(true).FindAll(p => p.GetElementType() != null && p.GetElementType().IsEqual(eleType)); } return listRtn; } /// /// 包含某一参数的图元 /// /// /// /// /// public static List GetElements(this Document doc, BuiltInParameter para) where T : Element { return doc.GetElements().FindAll(p => p.ExsitsParameter(para)); } /// /// 与当前相交的图元,快速过滤 /// /// /// /// public static List GetElements(this Document doc, Element elem, double tolerance = 0) { BoundingBoxXYZ box = elem.get_BoundingBox(null); return box == null ? new List() : GetElements(doc, box, tolerance); } /// /// 相交的图元 /// /// /// /// public static List GetElements(this Document doc, BoundingBoxXYZ box, double tolerance = 0) { var otl = new Outline(box.Min, box.Max); return doc.GetElements(otl, tolerance); } /// /// 根据 BoundingBox获取特定类别相交图元 /// /// /// /// 类别 /// 误差值 /// public static List GetElements(this Document doc, BoundingBoxXYZ box, BuiltInCategory category, double tolerance = 0) { Outline outline = new Outline(box.Min, box.Max); BoundingBoxIntersectsFilter boundFilter = tolerance.IsEqual(0) ? new BoundingBoxIntersectsFilter(outline) : new BoundingBoxIntersectsFilter(outline, tolerance); ElementCategoryFilter categoryFilter = new ElementCategoryFilter(category); LogicalAndFilter andFilter = new LogicalAndFilter(boundFilter, categoryFilter); return doc.GetElements(andFilter); } /// /// 根据 获取BoundingBox内特定类别图元(包含) /// /// /// /// 类别 /// public static List GetElements(this Document doc, BoundingBoxXYZ box, BuiltInCategory category) { Outline outline = new Outline(box.Min, box.Max); //BoundingBoxIntersectsFilter boundFilter = tolerance.IsEqual(0) // ? new BoundingBoxIntersectsFilter(outline) // : new BoundingBoxIntersectsFilter(outline, tolerance); ElementCategoryFilter categoryFilter = new ElementCategoryFilter(category); //return doc.GetElements(andFilter); // Create a BoundingBoxIsInside filter for Outline BoundingBoxIsInsideFilter filter = new BoundingBoxIsInsideFilter(outline); LogicalAndFilter andFilter = new LogicalAndFilter(filter, categoryFilter); // Apply the filter to the elements in the active document // This filter excludes all objects derived from View and objects derived from ElementType FilteredElementCollector collector = new FilteredElementCollector(doc); IList elements = collector.WherePasses(andFilter).ToElements(); // Find walls outside BoundingBox: use an inverted filter to match elements // Use shortcut command OfClass() to find walls only BoundingBoxIsInsideFilter outsideFilter = new BoundingBoxIsInsideFilter(outline, true); // inverted filter collector = new FilteredElementCollector(doc); IList outsideFounds = collector.OfClass(typeof(Wall)).WherePasses(outsideFilter).ToElements(); return elements.ToList(); } /// /// 根据 BoundingBox获取指定类形相交图元 /// /// /// /// 指定类型 /// /// public static List GetElements(this Document doc, BoundingBoxXYZ box, Type type, double tolerance = 0) { Outline outline = new Outline(box.Min, box.Max); BoundingBoxIntersectsFilter boundFilter = tolerance.IsEqual(0) ? new BoundingBoxIntersectsFilter(outline) : new BoundingBoxIntersectsFilter(outline, tolerance); return doc.GetElements(boundFilter).FindAll(p => p.GetType() == type); } /// /// 相交的图元 /// 通过此方法可以找到相连接图元,如两个首尾相接的墙 /// /// /// /// public static List GetElements(this Document doc, Outline otl, double tolerance = 0) { if (tolerance.IsEqual(0)) { var boundFilter = new BoundingBoxIntersectsFilter(otl); return doc.FilterElements(boundFilter); } else { var boundFilter = new BoundingBoxIntersectsFilter(otl, tolerance); return doc.FilterElements(boundFilter); } } /// /// 获取图元,快速过滤 /// /// /// /// /// /// public static List GetElements(this Document doc, Element elem, ElementFilter filter, double dSub = 0) { var box = elem.get_BoundingBox(null); if (box == null) return new List(); var vectSub = new XYZ(dSub, dSub, dSub); var otl = new Outline(box.Min.Add(vectSub), box.Max.Subtract(vectSub)); return doc.GetElements(otl, filter); } /// /// 获取图元,快速过滤 /// /// /// /// /// public static List GetElements(this Document doc, Outline otl, ElementFilter filter) { var boundFilter = new BoundingBoxIntersectsFilter(otl); var allFilter = new LogicalAndFilter(boundFilter, filter); return doc.FilterElements(allFilter); } /// /// 过滤器过滤图元 /// /// /// /// public static List GetElements(this Document doc, IEnumerable elements, ElementFilter filter) { return doc.FilterElements(elements, filter); } /// /// 过滤器过滤图元 /// /// /// /// public static List GetElements(this Document doc, ElementFilter filter) { return doc.FilterElements(filter); } public static List GetLevels(this Document doc) { List mLevels = null; mLevels = doc.FilterElements(); mLevels.Sort(new CommonComparer((x, y) => { return x.Elevation.CompareTo(y.Elevation); })); return mLevels; } /// /// 返回激活层之间的所有Element /// /// /// public static List GetElementsInActiveView(this Document doc) { var levelList = doc.GetLevels(); var levelData = levelList.FindIndex(m => m.Id == doc.ActiveView.GenLevel.Id); doc.GetElements(doc.ActiveView.GenLevel); Level topLevel = null; if (levelData < levelList.Count - 1) { topLevel = levelList[levelData + 1]; } List elements = new List(); if (topLevel != null) { elements = doc.GetElements(doc.ActiveView.GenLevel, topLevel); } return elements; } public static List GetElements(this Document doc, IEnumerable ids) { List elements = new List(); foreach (ElementId id in ids) { Element element = doc.GetElement(id); if (element != null) { elements.Add(element); } } return elements; } /// /// 框选楼板用 /// /// /// 切记,PickedBox的Z轴有可能不是当前平面Z轴 /// /// /// /// public static List GetElements(this Document doc, PickedBox pickedBox, ElementFilter filter, double dZOffset, double dZExtend = 0) { ElementFilter ef = null; double x1 = Math.Max(pickedBox.Max.X, pickedBox.Min.X); double y1 = Math.Max(pickedBox.Max.Y, pickedBox.Min.Y); double x2 = Math.Min(pickedBox.Max.X, pickedBox.Min.X); double y2 = Math.Min(pickedBox.Max.Y, pickedBox.Min.Y); double z = pickedBox.Min.Z + dZOffset.ToApi(); double dZExtendDown = 110d.ToApi(); //Z方向范围 double dZExtendUp = 10d.ToApi(); //Z方向范围 if (!dZExtend.IsZero(0)) { dZExtendDown = dZExtend.ToApi(); dZExtendUp = dZExtend.ToApi(); } XYZ ptMin = new XYZ(x2, y2, z - dZExtendDown); XYZ ptMax = new XYZ(x1, y1, z + dZExtendUp); Outline otl = new Outline(ptMin, ptMax); if (filter != null) { ef = new LogicalAndFilter(filter, new BoundingBoxIntersectsFilter(otl)); } else { ef = new BoundingBoxIntersectsFilter(otl); } return doc.FilterElements(ef); } /// /// 对应"在视图中可见的"对象 /// /// /// /// /// public static List GetElements(this Document doc, View view, ElementFilter filter = null) { FilteredElementCollector collector = new FilteredElementCollector(doc, view.Id); if (filter == null) { return collector.ToElements().ToList(); } else { return collector.WherePasses(filter).ToElements().ToList(); } } /// /// 返回视图中创建的对象,如类型标记等,可获取隐藏对象。 /// /// /// /// public static List GetElements(this Document doc, ElementId viewId) { FilteredElementCollector collector = new FilteredElementCollector(doc); return collector.OwnedByView(viewId).ToList(); } /// /// 主要是层间对象 /// /// /// /// /// public static List GetElements(this Document doc, Level baseLevel, Level topLevel) { Outline otl = doc.CreateOutline(baseLevel, topLevel, 10, -10); return doc.GetElements(otl); } /// /// 两标高之间的图元 /// /// /// 下标高 /// 上标高 /// 下偏移 /// 上偏移 /// public static List GetElements(this Document doc, Level baseLevel, Level topLevel, double baseOffset, double topOffset) { Outline otl = doc.CreateOutline(baseLevel, topLevel, baseOffset, topOffset); return doc.GetElements(otl); } /// /// 点获取图元 /// 获取包含指定点的所有图元 /// /// /// /// 误差值 /// /// ps:编译器只识别9位小数,而该方法默认识别13位小数,故需要指定误差值 public static List GetElements(this Document doc, XYZ pt, double tolerance = 0) { return doc.FilterElements(new BoundingBoxContainsPointFilter(pt, tolerance)); } /// /// 获取图元 /// /// /// /// /// public static List GetElements(this Document doc, XYZ pt, ElementFilter filter) { List listRtn = new List(); ElementFilter ef = new LogicalAndFilter(filter, new BoundingBoxContainsPointFilter(pt)); listRtn = doc.FilterElements(ef); return listRtn; } /// /// 获取文字类型 /// 由于符号用到 所以 从单行/多行文字中提出 /// /// /// 文字字体 /// 字高 /// 宽度系数 /// 返回文字类型 public static TextNoteType GetTextNodeType(this Document doc, string strFont, double dFontHeight, double dHwRatio, string leaderArrowheadName = "实心箭头 30 度") { List types = doc.FilterElements(); TextNoteType rtnType = null; string strTypename = string.Format("文字 {0} mm * {1} {2}", new object[] { dFontHeight, dHwRatio, strFont }); if (types.Count > 0) { foreach (TextNoteType textType in types) { if (textType.Name == strTypename) { rtnType = textType; break; } } if (rtnType == null) { rtnType = types[0].DuplicateT(strTypename); //宽度系数 rtnType.SetParameter(BuiltInParameter.TEXT_WIDTH_SCALE, dHwRatio); //文字大小 rtnType.SetParameter(BuiltInParameter.TEXT_SIZE, dFontHeight.ToApi()); //文字字体 rtnType.SetParameter(BuiltInParameter.TEXT_FONT, strFont); //背景-透明 rtnType.SetParameter(BuiltInParameter.TEXT_BACKGROUND, 1); //引线/边界偏移量 rtnType.SetParameter(BuiltInParameter.LEADER_OFFSET_SHEET, 0.0); //引线箭头 List listEleType = doc.FilterElements() .Where(d => d.Name.Equals(leaderArrowheadName)) .ToList(); if ((listEleType != null) && (listEleType.Count > 0)) { rtnType.SetParameter(BuiltInParameter.LEADER_ARROWHEAD, listEleType[0].Id); } } } return rtnType; } public static TextNoteType GetTextNodeType(this Document doc, string strTypeName) { TextNoteType textNodeType = doc.FindTextNodeType(strTypeName, true); return textNodeType; } public static TextNoteType FindTextNodeType(this Document doc, string strTypeName) { return doc.FindTextNodeType(strTypeName, false); } /// /// 文字类型 /// /// /// public static List GetTextNoteTypeSet(this Document doc) { return doc.FilterElements(); } public static TextNoteType FindTextNodeType(this Document doc, string strTypeName, bool notFindReturnDefault) { TextNoteType returnDefault = null; List textNodeTypes = doc.GetTextNoteTypeSet(); foreach (TextNoteType textNodeType in textNodeTypes) { if (textNodeType.Name == strTypeName) { return textNodeType; } if (returnDefault == null) returnDefault = textNodeType; } if (notFindReturnDefault) return returnDefault; return null; } /// /// 标注类型 /// /// /// public static List GetDimensionTypeSet(this Document doc) { return doc.FilterElements(); } /// /// 获取由用户自己配置的标注样式 /// 注:根据文档要求,项目中所有用到的标注样式都从该方法获取 /// /// /// //public static DimensionType GetDimensionType(this Document doc) //{ // return doc.GetDimensionType(null); //} /// /// 获取标注默认配置 /// /// private static string GetDimensionDefConfig() { /* * 根据文档<<编辑工具功能设定>>要求,标注使用以下默认值 根据谭工要求,重新设定默认值 * 两侧出头:2.5(mm) 两侧出头:1(mm) * 终端出头:2.5(mm) 终端出头:2(mm) * 引出线长:3.5(mm) 引出线长:3.5(mm) * 字线间距:1.5(mm) 字线间距:0.5(mm) * 粗线宽度:4(mm) 粗线宽度:6(mm) * 粗线长度:3(mm) 粗线长度:1.24(mm) * 标注字高:3(mm) 标注字高:3.5(mm) * 标注字体:SAGArevit 标注字体:Dotum * 标注颜色:无 标注颜色:绿 */ string strDefault = "Dotum"; // RevitUtils.GetSAGAFontName(); string defaultConfig = ",1.24,6,3.5,0.5,2,3.5," + strDefault + ",1,65280,"; return defaultConfig; } /// /// 获取一个标注的参数 /// /// /// public static string GetDimensionConfig(this DimensionType type) { double cxcd = type.GetParameterElement(BuiltInParameter.DIM_LEADER_ARROWHEAD) .GetParameterDoubleMm(BuiltInParameter.ARROW_SIZE); double cxkd = type.GetParameterInteger(BuiltInParameter.TICK_MARK_PEN); double bzzg = type.GetParameterDoubleMm(BuiltInParameter.TEXT_SIZE); double zxjj = type.GetParameterDoubleMm(BuiltInParameter.TEXT_DIST_TO_LINE); double zdct = type.GetParameterDoubleMm(BuiltInParameter.WITNS_LINE_EXTENSION); double ycxc = type.GetParameterDoubleMm(BuiltInParameter.DIM_WITNS_LINE_EXTENSION_BELOW); string strDefault = type.GetParameterString(BuiltInParameter.TEXT_FONT); double lcct = type.GetParameterDoubleMm(BuiltInParameter.DIM_LINE_EXTENSION); double color = type.GetParameterInteger(BuiltInParameter.LINE_COLOR); string result = string.Format(",{0},{1},{2},{3},{4},{5},{6},{7},{8}", cxcd, cxkd, bzzg, zxjj, zdct, ycxc, strDefault, lcct, color); return result; } /// /// 线创建标注 /// /// /// /// /// /// public static Dimension CreateDimension(this Document doc, Line line, View view, DimensionType dType = null) { List ptList = new List(); ptList.Add(line.StartPoint()); ptList.Add(line.EndPoint()); Dimension dim = doc.CreateDimension(line, ptList, view); if (dim != null && dType != null) { dim.DimensionType = dType; } return dim; } /// /// 线上点创建标注 /// /// /// /// /// /// /// public static Dimension CreateDimension(this Document doc, Line line, List ptList, View view, DimensionType dType = null) { Dimension result = null; ReferenceArray array = new ReferenceArray(); if (ptList != null && ptList.Count > 0) { //参照线方向 XYZ vector = line.Direction.VectorRotate(view.ViewDirection, Math.PI / 2); foreach (XYZ item in ptList) { Reference refer = doc.GetReferenceDetail(item, vector, view); if (refer != null) { array.Append(refer); } } if (array.Size > 1) { result = doc.Create.NewDimension(view, line, array); if (result != null && dType != null) { result.DimensionType = dType; } } } return result; } /// /// 通过矩离创建标注 /// /// /// /// /// /// /// public static Dimension CreateDimension(this Document doc, Line line, List listSpace, View view, DimensionType dType = null) { double dStart = 0; List listPt = new List(); for (int i = 0; i < listSpace.Count; i++) { double dSpace = listSpace[i]; listPt.Add(line.StartPoint() + line.Direction * dStart); dStart += dSpace; } listPt.Add(line.StartPoint() + line.Direction * dStart); return doc.CreateDimension(line, listPt, view, dType); } /// /// 两道尺寸标注 测试用 /// /// /// /// /// /// /// public static List CreateDimension(this Document doc, Line line, List listFirstSpace, List listSecondSpace, View view) { List listRtn = new List(); //参照线方向 XYZ vector = line.Direction.VectorRotate(view.ViewDirection, Math.PI / 2); double dStart = 0; List listPtFirst = new List(); for (int i = 0; i < listFirstSpace.Count; i++) { double dSpace = listFirstSpace[i].ToApi(); listPtFirst.Add(line.StartPoint() + line.Direction * dStart); dStart += dSpace; } listPtFirst.Add(line.StartPoint() + line.Direction * dStart); dStart = 0; List listPtSecond = new List(); for (int i = 0; i < listSecondSpace.Count; i++) { double dSpace = listSecondSpace[i].ToApi(); listPtSecond.Add(line.StartPoint() + line.Direction * dStart); dStart += dSpace; } listPtSecond.Add(line.StartPoint() + line.Direction * dStart); List listPt = new List(); listPt.AddRange(listPtFirst); foreach (var pt in listPtSecond) { if (!pt.ExsitsInlist(listPt)) { listPt.Add(pt); } } Dictionary dicRef = new Dictionary(); for (int i = 0; i < listPt.Count; i++) { XYZ item = listPt[i]; Reference refer = doc.GetReferenceDetail(item, vector, view); if (refer != null) { dicRef.Add(i, refer); } } ReferenceArray array = new ReferenceArray(); foreach (var pt in listPtFirst) { int index = listPt.FindIndex(p => p.IsEqual(pt)); array.Append(dicRef[index]); } if (array.Size > 1) { Dimension result = doc.Create.NewDimension(view, line, array); listRtn.Add(result); } //两个字高 double dOffset = (3.0 * 2 * view.Scale).ToApi(); // line = line.Offset(dOffset); array = new ReferenceArray(); foreach (var pt in listPtSecond) { int index = listPt.FindIndex(p => p.IsEqual(pt)); array.Append(dicRef[index]); } if (array.Size > 1) { Dimension result = doc.Create.NewDimension(view, line, array); listRtn.Add(result); } return listRtn; } /// /// 创建标注的短参照 /// /// /// /// /// /// public static Reference GetReferenceDetail(this Document doc, XYZ start, XYZ vector, View view = null) { Reference result = null; if (view == null) { view = doc.ActiveView; } Line line = vector.VectorToLine(start, 0.02 /*d.ToApi()*/); if (view.ViewType == ViewType.ThreeD) { ModelCurve mc = LineExtend.NewModelCurve(line); if (mc != null) { result = new Reference(mc); } } else { DetailCurve dc = doc.Create.NewDetailCurve(view, line); if (dc != null) { result = new Reference(dc); } } return result; } /// /// 获取标注配置 /// /// private static string GetDimensionConfig() { //文件路径 string filePath = AppBaseInfo.AppTempFilePath + "\\ConfigDimensionType.dll"; string config = null; #region 读取配置 if (File.Exists(filePath)) { //存在本地文件 读取本地文件配置 using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Read)) { using (StreamReader sr = new StreamReader(fs, Encoding.Default)) { config = sr.ReadLine(); sr.Close(); } fs.Close(); } } #endregion return config; } /// /// 获取用户设置的标注样式 /// 该方法可设置尺寸界线长度 /// /// /// /// //public static DimensionType GetDimensionType(this Document doc, double? length = null, string config = null) //{ // string defaultConfig = GetDimensionDefConfig(); // if (string.IsNullOrEmpty(config)) // config = GetDimensionConfig(); // bool isSave = true; // if (length != null && length.Value > 0) // { // isSave = false; // string[] array = config.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries); // if (array.Length > 5) // { // array[5] = length.Value.ToString(); // config = ConvertToConfig(array); // } // array = defaultConfig.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries); // if (array.Length > 5) // { // array[5] = length.Value.ToString(); // defaultConfig = ConvertToConfig(array); // } // } // DimensionType result = CreateDimensionType(doc, config, isSave); // if (result == null) // result = CreateDimensionType(doc, defaultConfig, isSave); // return result; //} private static string ConvertToConfig(string[] array) { string config = ","; foreach (string item in array) { config += item + ","; } return config; } public static DimensionType FindDimensionType(this Document doc, string strTypeName) { DimensionType result = null; List dimTypes = doc.GetDimensionTypeSet(); foreach (DimensionType dimType in dimTypes) { /* * 解决问题:在没有找到标注类型时,在不同模板中不能直接默认取第一个 * 应该取类型一致的 * DimensionStyleType弧长和角度标注有做的可能 */ if (result == null && dimType.StyleType == DimensionStyleType.Linear) result = dimType; if (!string.IsNullOrEmpty(dimType.Name) && dimType.Name.Replace(" ", "").Trim().Equals(strTypeName.Replace(" ", "").Trim())) { return dimType; } } return result; } public static bool CanMirrorElement(this Document doc, ElementId elemId) { return ElementTransformUtils.CanMirrorElement(doc, elemId); } public static bool CanMirrorElements(this Document doc, ICollection elemIds) { return ElementTransformUtils.CanMirrorElements(doc, elemIds); } public static ICollection CopyElement(this Document doc, ElementId elem, XYZ translation) { return ElementTransformUtils.CopyElement(doc, elem, translation); } public static ICollection CopyElements(this Document doc, ICollection elementsToCopy, XYZ translation) { return ElementTransformUtils.CopyElements(doc, elementsToCopy, translation); } public static void MirrorElement(this Document doc, ElementId elementToMirror, Plane plane) { ElementTransformUtils.MirrorElement(doc, elementToMirror, plane); } public static void MirrorElements(this Document doc, ICollection elementsToMirror, Plane plane) { ElementTransformUtils.MirrorElements(doc, elementsToMirror, plane, true); } public static void MoveElement(this Document doc, ElementId elementToMove, XYZ translation) { ElementTransformUtils.MoveElement(doc, elementToMove, translation); } public static void MoveElements(this Document doc, ICollection elem, XYZ translation) { ElementTransformUtils.MoveElements(doc, elem, translation); } public static void RotateElement(this Document doc, Element elem, XYZ pt, double angle) { Line axis = Line.CreateBound(pt, pt.AddZ(1)); doc.RotateElement(elem, axis, angle); } public static void RotateElement(this Document doc, Element elem, Line axis, double angle) { ElementTransformUtils.RotateElement(doc, elem.Id, axis, angle); } public static void RotateElement(this Document doc, ElementId elem, Line axis, double angle) { ElementTransformUtils.RotateElement(doc, elem, axis, angle); } public static void RotateElements(this Document doc, ICollection elementsToRotate, Line axis, double angle) { ElementTransformUtils.RotateElements(doc, elementsToRotate, axis, angle); } public static void RotateElements(this Document doc, ICollection elementsToRotate, Line axis, double angle) { List elementIdsToRotate = new List(); foreach (Element e in elementsToRotate) { elementIdsToRotate.Add(e.Id); } ElementTransformUtils.RotateElements(doc, elementIdsToRotate, axis, angle); } /// /// 创建明细表 /// /// 明细表名称 /// 明细表字段名集合 ///是否取共享参数 /// public static ViewSchedule CreateViewSchedule(this Document doc, string viewScheduleName, BuiltInCategory category, string[] filedArray, ElementId areaSchemaId = null) { List scheduleList = doc.GetElements(typeof(ViewSchedule)).ToList(); ViewSchedule schedule = scheduleList.Find(p => p.Name == viewScheduleName); if (schedule != null) { return schedule; } Transaction trans = new Transaction(doc, "CreateViewSchedule"); trans.Start(); try { if (areaSchemaId == null) schedule = ViewSchedule.CreateSchedule(doc, new ElementId(category), ElementId.InvalidElementId); else schedule = ViewSchedule.CreateSchedule(doc, new ElementId(category), areaSchemaId); #region 创建明细表表头 TableData tableData = schedule.GetTableData(); if (tableData != null) { TableSectionData sectionData = tableData.GetSectionData(0); if (sectionData != null && sectionData.NumberOfColumns == 0 && sectionData.NumberOfRows == 0) { //#if R16 sectionData.InsertColumn(0); //#else //sectionData.InsertColumn(0, true); //#endif sectionData.SetColumnWidth(0, tableData.Width); doc.Regenerate(); sectionData.InsertRow(0); sectionData.SetCellText(0, 0, viewScheduleName); } } #endregion schedule.Name = viewScheduleName; ScheduleDefinition definition = schedule.Definition; definition.ShowGrandTotal = true; definition.ShowGrandTotalTitle = true; List filedList = schedule.Definition.GetSchedulableFields().ToList(); foreach (string s in filedArray) { SchedulableField filed = filedList.Find(p => p.GetName(doc) == s); if (filed != null) { ScheduleField scheduleField = schedule.Definition.AddField(filed); if (s.Contains("SAGA")) scheduleField.ColumnHeading = s.Substring(3); if (scheduleField.CanTotal()) { scheduleField.SetHasTotals(); } } } trans.Commit(); return schedule; } catch { trans.RollBack(); } return null; } /// /// 删除扩展 /// /// /// public static void DeleteExt(this Document doc, Element element) { //修改原因:Delete(element.Id)不能删除其上的子对象 element.Delete(); } /// /// 计算文本标签的宽度 /// (需在事物中调用) /// /// /// /// /// /// // public static double ComputeTextNoteWidth(this Document doc, View view, string str, // TextNoteType type, double singleWidth = 0) // { // double d1 = 0; // if (singleWidth == 0) // singleWidth = doc.ComputeSingleWidth(view, str, type); // d1 = singleWidth; // if (str.Contains('\n')) // { // List list = new List(); // list.AddRange(str.Split('\n')); // str = list.OrderByDescending(s => s.Length).First(); // } // //一个汉字占两个字符位 // int k = Encoding.Default.GetByteCount(str); // //暂时未计算探索者钢筋符号的信息,探索者钢筋符号中一个符号占一个字符位,但是大小为两个字符位的大小 // //如果包含空格,每多一个空格,增加一个字符宽度 // char[] charArray = str.ToArray(); // int count = 0; // foreach (char item in charArray) // { // if (string.IsNullOrEmpty(item.ToString().Trim())) // { // count++; // } // } //#if R15 // count++;//15中的字符末尾会多出一个空格 // k++; //#endif // return d1*(k + count); // } ///// ///// 创建标注 ///// ///// ///// 所有详图线 ///// 标注起点(转换前坐标) ///// 标注终点(转换前坐标) ///// 标注点(转换前坐标) ///// 视图 //public static Dimension CreateDimension(this Document doc, List list, XYZ start, XYZ end, // XYZ dimPoint, View drawView, string showText = null, DimensionType type = null) //{ // Line line = Line.CreateBound(start, end); // XYZ foot = line.VerticalPoint(dimPoint); // XYZ vector = dimPoint.Subtract(foot).Normalize(); // if (vector.IsEqual(XYZ.Zero)) // { // vector = line.GetVUnboundLine(start).LineToBound().UnitVector().Normalize(); // } // line = line.OffsetPoint(dimPoint); // Reference startRef = start.GetReferenceByDetailList(list, vector, drawView); // Reference endRef = end.GetReferenceByDetailList(list, vector, drawView); // if (startRef != null && endRef != null) // { // ReferenceArray array = new ReferenceArray(); // array.Append(startRef); // array.Append(endRef); // Dimension dim = null; // if (type != null) // dim = doc.Create.NewDimension(drawView, line, array, type); // else // dim = doc.Create.NewDimension(drawView, line, array); // if (dim != null) // { // if (showText != null && !showText.Equals("<>")) // dim.ValueOverride = showText; // } // return dim; // } // return null; //} //public static Reference GetReferenceByDetailList(this XYZ point, List detailList, XYZ vector, // View drawView) //{ // if (detailList == null) // detailList = new List(); // Reference refLine = null; // XYZ end = point + vector*0.015 /*d.ToApi()*/; // Line line = Line.CreateBound(point, end); // DetailCurve dc = detailList.Find(p => p.GeometryCurve.IsOnCurve(line)); // if (dc != null) // refLine = new Reference(dc); // else //没有的补一根线 // { // CurveArray ca = new CurveArray(); // ca.Append(line); // List list = ca.DrawDetailLines(drawView); // if (list != null && list.Count > 0) // refLine = new Reference(list[0]); // } // return refLine; //} /// /// 获取一个标注的所有参照 /// (提出该方法理由:从标注中直接取出的参照在16版本不能直接使用) /// /// /// /// public static ReferenceArray GetReferences(this Dimension dim) { #if R16 ReferenceArray array = new ReferenceArray(); foreach (Reference item in dim.References) { Element elem = ExternalDataWrapper.Current.Doc.GetElement(item); if (elem != null) array.Append(new Reference(elem)); } #else ReferenceArray array = dim.References; #endif return array; } public static List GetSlabEdgeTypesEx(this Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(SlabEdgeType)); return collector.OfType().ToList(); } public static List RoomTagTypesEx(this Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_RoomTags); return collector.OfType().ToList(); } public static List GetElementsT(this Document doc, IEnumerable elementIds) where T : Element { List listElements = new List(); if (elementIds == null) return listElements; foreach (ElementId elementId in elementIds) { T tv = doc.GetElementT(elementId); if (tv != null) listElements.Add(tv); } return listElements; } } public class SAGAFamilyLoadOptions : IFamilyLoadOptions { public bool OnFamilyFound(bool familyInUse, out bool overwriteParameterValues) { overwriteParameterValues = true; return true; } public bool OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues) { source = FamilySource.Family; overwriteParameterValues = true; return true; } } public enum DrivenTypes { NotSupport = 0, Point, Curve, Face } }