Revit API通过相交过滤器找到与风管相交的对象。
相交过滤器的应用,比几何相交法简便。Excluding剔除url:http://greatverve.cnblogs.com/p/ElementIntersectsElementFilter.html
//找到与风管相交的对象,通过相交过滤器。
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class FindIntersectWallsByElement : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc, "ExComm");
trans.Start();
//pick the duct
Selection sel = app.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, "Please pick a duct");
Element duct = doc.GetElement(ref1);
FilteredElementCollector collector = new FilteredElementCollector(doc);
//相交过滤器
ElementIntersectsElementFilter elementFilter = new ElementIntersectsElementFilter(duct, false);
collector.WherePasses(elementFilter);
List<ElementId> excludes = new List<ElementId>();
excludes.Add(duct.Id);
collector.Excluding(excludes);//剔除自身
sel.Elements.Clear();
//Add these interseting element to the selection
foreach (Element elem in collector)
{
sel.Elements.Add(elem);
}
trans.Commit();
return Result.Succeeded;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class FindIntersectWallsByElement : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc, "ExComm");
trans.Start();
//pick the duct
Selection sel = app.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, "Please pick a duct");
Element duct = doc.GetElement(ref1);
FilteredElementCollector collector = new FilteredElementCollector(doc);
//相交过滤器
ElementIntersectsElementFilter elementFilter = new ElementIntersectsElementFilter(duct, false);
collector.WherePasses(elementFilter);
List<ElementId> excludes = new List<ElementId>();
excludes.Add(duct.Id);
collector.Excluding(excludes);//剔除自身
sel.Elements.Clear();
//Add these interseting element to the selection
foreach (Element elem in collector)
{
sel.Elements.Add(elem);
}
trans.Commit();
return Result.Succeeded;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。