多项功能优化

This commit is contained in:
GG Z
2024-12-22 10:26:12 +08:00
parent 77655c9ef5
commit 83b846f15f
66 changed files with 5424 additions and 2927 deletions

View File

@@ -70,24 +70,6 @@ public static class CollectorAssist
: FilteredElementCollector.IsViewValidForElementIteration(view.Document, view.Id)
? new FilteredElementCollector(view.Document, view.Id)
: throw new ArgumentException($"视图{view.Id}不可应用收集器");
public static FilteredElementCollector OfModelCollector(this Document doc)
{
if (doc == null)
{
throw new ArgumentNullException(nameof(doc), "文档为空");
}
var li = doc.OfCollector()
.WhereElementIsNotElementType()
.Where(
e => e is TopographySurface ||
(e.CanHaveTypeAssigned() &&
e.HasPhases() &&
e.Category is { Parent: null, CategoryType: CategoryType.Model } &&
e is not Panel &&
e is not Mullion &&
e is not RevitLinkInstance)).Select(e => e.Id).ToList();
return new FilteredElementCollector(doc, li);
}
/// <summary>
/// 文档的元素收集器
/// </summary>
@@ -135,18 +117,19 @@ public static class CollectorAssist
/// </summary>
/// <param name="collector">收集器</param>
/// <returns>过滤元素收集器</returns>
public static FilteredElementCollector OfInstance(this FilteredElementCollector collector) =>
public static FilteredElementCollector OfInstances(this FilteredElementCollector collector) =>
collector.WhereElementIsNotElementType();
/// <summary>
/// 过滤项目文件的模型元素
/// </summary>
/// <returns>元素集合</returns>
public static IEnumerable<Element> OfModelElements(this FilteredElementCollector collector) =>
collector
public static FilteredElementCollector OfModelCollector(this Document doc)
{
if (doc == null)
{
throw new ArgumentNullException(nameof(doc), "文档为空");
}
var li = doc.OfCollector()
.WhereElementIsNotElementType()
.Where(
e => e is TopographySurface ||
e is DirectShape ||
(e.CanHaveTypeAssigned()
&& e.IsValidObject
&& e.HasPhases()
@@ -154,6 +137,46 @@ public static class CollectorAssist
&& e.Category is { Parent: null, CategoryType: CategoryType.Model }
&& e is not Panel
&& e is not Mullion
&& e is not RevitLinkInstance)).Select(e => e.Id).ToList();
return new FilteredElementCollector(doc, li);
}
/// <summary>
/// 过滤项目文件最顶层的模型元素
/// </summary>
/// <returns>元素集合</returns>
public static IEnumerable<Element> OfParentModelElements(this Document doc) =>
doc.OfCollector()
.WhereElementIsNotElementType()
.Where(
e => e is TopographySurface ||
e is DirectShape ||
(e.CanHaveTypeAssigned()
&& e.IsValidObject
&& e.HasPhases()
&& e.get_BoundingBox(null) != null
&& e.Category is { CategoryType: CategoryType.Model, AllowsBoundParameters: true }
&& (e is HostObject || e.Category.Parent == null)
&& e is not Panel
&& e is not Mullion
&& e is not RevitLinkInstance)
);
/// <summary>
/// 过滤项目文件的所有模型元素
/// </summary>
/// <returns>元素集合</returns>
public static IEnumerable<Element> OfAllModelElements(this Document doc) =>
doc.OfCollector()
.WhereElementIsNotElementType()
.Where(
e => e is TopographySurface ||
e is DirectShape ||
(e.CanHaveTypeAssigned()
&& e.IsValidObject
&& e.HasPhases()
&& e.ViewSpecific == false
&& e.Category is { CategoryType: CategoryType.Model, AllowsBoundParameters: true }
&& e.get_BoundingBox(null) != null
&& e is not RevitLinkInstance)
);
}