在链接模型中使用ISelectionFilter,
关键代码:
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
IList<Reference> refs = uidoc.Selection.PickObjects(ObjectType.LinkedElement, new LinkSelectionFilter());
TaskDialog.Show("数量:", refs.Count().ToString());
public class LinkSelectionFilter : ISelectionFilter
{
RevitLinkInstance rvtIns = null;
public bool AllowElement(Element elem)
{
if (elem is RevitLinkInstance)
{
rvtIns = elem as RevitLinkInstance;
return true;
}
return false;
}
public bool AllowReference(Reference reference, XYZ position)
{
Document doc = rvtIns.GetLinkDocument();
Element elm = doc.GetElement(reference.LinkedElementId);
if (elm is Pipe)
return true;
return false;
}
}
博主会经常更新一些技术文章,请大家多多关注,
源码下载请加qq群480950299