更新
This commit is contained in:
221
Revit-API/ElementFilter.md
Normal file
221
Revit-API/ElementFilter.md
Normal file
@@ -0,0 +1,221 @@
|
||||
## Filter
|
||||
|
||||
### ElementIsElementTypeFilter
|
||||
|
||||
- 获得所有ElementType对象的过滤器
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 获得所有ElementType对象的过滤器
|
||||
ElementIsElementTypeFilter filter = new ElementIsElementTypeFilter();
|
||||
col.WherePasses(filter);
|
||||
// 获得名字为幕墙的ElementType 使用的是LINQ表达式
|
||||
var types = from element in col
|
||||
where element.Name == "幕墙"
|
||||
select element;
|
||||
ElementType type = types.First() as ElementType;
|
||||
TaskDialog.Show("test", type.Name);
|
||||
|
||||
### FilteredElementCollector
|
||||
|
||||
- 获得所有OwnerViewId 为传入视图ID的Element
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 获得所有OwnerViewId 为传入视图ID的Element
|
||||
ElementOwnerViewFilter filter = new ElementOwnerViewFilter(doc.ActiveView.Id);
|
||||
col.WherePasses(filter);
|
||||
foreach(Element element in col)
|
||||
{
|
||||
TaskDialog.Show("test", element.Name);
|
||||
}
|
||||
|
||||
### ElementIsCurveDrivenFilter
|
||||
|
||||
- 获得所有Location 为LocationCurve的Element
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 获得所有Location 为LocationCurve的Element
|
||||
ElementIsCurveDrivenFilter filter = new ElementIsCurveDrivenFilter();
|
||||
col.WherePasses(filter);
|
||||
foreach(Element element in col)
|
||||
{
|
||||
TaskDialog.Show("test", element.Name);
|
||||
}
|
||||
|
||||
### ElementStructuralTypeFilter
|
||||
|
||||
- 给定枚举参数StructuralType, 根据传入的参数获得对应的结构类型Element
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 给定枚举参数StructuralType, 根据传入的参数获得对应的结构类型Element
|
||||
ElementStructuralTypeFilter filter = new ElementStructuralTypeFilter(StructuralType.Column);
|
||||
col.WherePasses(filter);
|
||||
foreach(Element element in col)
|
||||
{
|
||||
TaskDialog.Show("test", element.Name);
|
||||
}
|
||||
|
||||
### ElementWorksetFilter
|
||||
|
||||
- 获得所有该工作集的对象
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
Selection sel = commandData.Application.ActiveUIDocument.Selection;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
|
||||
if (doc.IsWorkshared)
|
||||
{
|
||||
// 选择一个Eelment
|
||||
Reference r = sel.PickObject(ObjectType.Element);
|
||||
Transaction tr = new Transaction(doc, "test");
|
||||
tr.Start();
|
||||
// 创建工作集
|
||||
Workset workset = Workset.Create(doc, "feast");
|
||||
// 将选择的Element对象添加到创建的工作集当中
|
||||
Element element = doc.GetElement(r);
|
||||
element.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).Set(workset.Id.IntegerValue);
|
||||
tr.Commit();
|
||||
// 获得所有该工作集的对象
|
||||
ElementWorksetFilter filter = new ElementWorksetFilter(workset.Id);
|
||||
col.WherePasses(filter);
|
||||
foreach(Element e in col)
|
||||
{
|
||||
TaskDialog.Show("test", element.Name);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskDialog.Show("test", "未开始工作共享");
|
||||
}
|
||||
|
||||
### FamilySymbolFilter
|
||||
|
||||
- 该过滤器获得传入Family的所有symbol
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
Selection sel = commandData.Application.ActiveUIDocument.Selection;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
col.OfClass(typeof(Family));
|
||||
// 获得默认的第一个Family作为FamilySymbolFilter的参数,该过滤器获得传入Family的所有symbol
|
||||
FamilySymbolFilter filter = new FamilySymbolFilter(col.FirstElementId());
|
||||
foreach(Element element in col)
|
||||
{
|
||||
TaskDialog.Show("test", element.Name);
|
||||
}
|
||||
|
||||
### ExclusionFilter
|
||||
|
||||
- 传入参数为ElementID的容器,过滤器会选择除了传入的ElementId以外的所有Element
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
Selection sel = commandData.Application.ActiveUIDocument.Selection;
|
||||
Reference r = sel.PickObject(ObjectType.Element);
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 传入参数为ElementID的容器,过滤器会选择除了传入的ElementId以外的所有Element
|
||||
ExclusionFilter filter = new ExclusionFilter(new List<ElementId>() { doc.GetElement(r).Id});
|
||||
//因为Element很多,我加了个Class过滤器,只输出FamilyInstance作为对象,所以选择时也请选择FamilyInstance
|
||||
col.WherePasses(filter).OfClass(typeof(FamilyInstance));
|
||||
foreach(Element e in col)
|
||||
{
|
||||
TaskDialog.Show("test", e.Name);
|
||||
}
|
||||
|
||||
### BoundingBoxIntersectsFilter
|
||||
|
||||
- 传入参数为OutLine, 获取BoundingBox与给定轮廓相交的Element
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 过滤器功能为获取OutLine中的Element,所以手动在OutLine中创建一段风管
|
||||
Transaction tr = new Transaction(doc, "test");
|
||||
tr.Start();
|
||||
doc.Create.NewDuct(new XYZ(5, 0, 5), new XYZ(5, 5, 5), doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.DuctType)) as DuctType);
|
||||
tr.Commit();
|
||||
// 传入参数为OutLine, 获取BoundingBox与给定轮廓相交的Element
|
||||
// 每一个Element都会有一个BoundingBox可通过LookUp查看
|
||||
BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(new Outline(new XYZ(0, 0, 0), new XYZ(10, 10, 10)));
|
||||
col.WherePasses(filter);
|
||||
foreach(Element e in col)
|
||||
{
|
||||
TaskDialog.Show("test", e.Name);
|
||||
}
|
||||
|
||||
### BoundingBoxIsInsideFilter
|
||||
|
||||
- 传入参数为OutLine, 获取BoundingBox在给定轮廓内的Element
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 过滤器功能为获取OutLine中的Element,所以手动在OutLine中创建一段风管
|
||||
Transaction tr = new Transaction(doc, "test");
|
||||
tr.Start();
|
||||
doc.Create.NewDuct(new XYZ(5, 0, 5), new XYZ(5, 5, 5), doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.DuctType)) as DuctType);
|
||||
tr.Commit();
|
||||
// 传入参数为OutLine, 获取BoundingBox在给定轮廓内的Element
|
||||
// 每一个Element都会有一个BoundingBox可通过LookUp查看
|
||||
BoundingBoxIsInsideFilter filter = new BoundingBoxIsInsideFilter(new Outline(new XYZ(0, 0, 0), new XYZ(10, 10, 10)));
|
||||
col.WherePasses(filter);
|
||||
foreach(Element e in col)
|
||||
{
|
||||
TaskDialog.Show("test", e.Name);
|
||||
}
|
||||
|
||||
### BoundingBoxContainsPointFilter
|
||||
|
||||
- 传入参数为XYZ, 获取BoundingBox包含给定XYZ的元素
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 过滤器功能为获取BoundingBox包含给定XYZ的元素,所以手动在XYZ上创建一段风管
|
||||
Transaction tr = new Transaction(doc, "test");
|
||||
tr.Start();
|
||||
doc.Create.NewDuct(new XYZ(5, 0, 5), new XYZ(5, 5, 5), doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.DuctType)) as DuctType);
|
||||
tr.Commit();
|
||||
// 传入参数为XYZ, 获取BoundingBox包含给定XYZ的元素
|
||||
// 每一个Element都会有一个BoundingBox可通过LookUp查看
|
||||
BoundingBoxContainsPointFilter filter = new BoundingBoxContainsPointFilter(new XYZ(5,5,5));
|
||||
col.WherePasses(filter);
|
||||
foreach(Element e in col)
|
||||
{
|
||||
TaskDialog.Show("test", e.Name);
|
||||
}
|
||||
|
||||
### FamilyInstanceFilter
|
||||
|
||||
- 获得所有给定FamilySymbol的FamilyInstance, 例子中的id为FamilySymbol的ID
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 获得所有给定FamilySymbol的FamilyInstance, 例子中的id为FamilySymbol的ID
|
||||
int id = 2480730;
|
||||
FamilySymbol symbol = doc.GetElement(new ElementId(id)) as FamilySymbol;
|
||||
FamilyInstanceFilter filter = new FamilyInstanceFilter(doc, symbol.Id);
|
||||
col.WherePasses(filter);
|
||||
foreach(Element e in col)
|
||||
{
|
||||
TaskDialog.Show("test", e.Name);
|
||||
}
|
||||
|
||||
### ElementLevelFilter
|
||||
|
||||
- 获得所有LevelId为指定Id的Element
|
||||
|
||||
- Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
FilteredElementCollector col = new FilteredElementCollector(doc);
|
||||
// 获得所有LevelId为指定Id的Element
|
||||
ElementLevelFilter filter = new ElementLevelFilter(doc.ActiveView.GenLevel.Id);
|
||||
col.WherePasses(filter);
|
||||
foreach(Element element in col)
|
||||
{
|
||||
TaskDialog.Show("test", element.Name);
|
||||
}
|
||||
|
||||
### ElementParameterFilter
|
||||
|
||||
- 根据指定的属性值过滤Element, API文档有例子
|
||||
|
||||
### *******
|
||||
Reference in New Issue
Block a user