public class DuctAccessoryFilter : ISelectionFilter
{
public bool AllowElement(Element elem)
{
BuiltInCategory builtInCategory = (BuiltInCategory)elem.Category.Id.IntegerValue;
if (builtInCategory == BuiltInCategory.OST_DuctAccessory)
{
return true;
}
return false;
}
public bool AllowReference(Reference reference, XYZ position)
{
return false;
}
}
然后再调用时候这样使用就可以了
ISelectionFilter ductAccessory = new DuctAccessoryFilter();
Reference eRef = uiDoc.Selection.PickObject(ObjectType.Element,ductAccessory, "请选择要标注的阀件");
Element elem = doc.GetElement(eRef);
仅仅数行就达到了想要的结果
以上文字转载在 审十空间