Revit API提供根據射線來尋找經過的元素。方法是固定模式,沒什麼好說。
關鍵代碼:[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
FindSupporting : IExternalCommand
{
Result Execute(ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction trans = Transaction(doc, );
trans.Start();
Selection sel = app.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, );
Duct duct = doc.GetElement(ref1) Duct;
LocationCurve lc = duct.Location LocationCurve;
Curve curve = lc.Curve;
XYZ ptStart = curve.get_EndPoint();
XYZ ptEnd = curve.get_EndPoint();
XYZ offset = XYZ(, , ); ptStart = ptStart - offset;
ptEnd = ptEnd - offset;
View3D view3d = ;
view3d = doc.ActiveView View3D;
(view3d == )
{
TaskDialog.Show(, );
Result.Failed;
}
beamLen = curve.Length;
IList<ReferenceWithContext> references = doc.FindReferencesWithContextByDirection(ptStart, (ptEnd - ptStart), view3d);
sel.Elements.Clear();
tolerate = ;
(ReferenceWithContext reference references)
{
Reference ref2 = reference.GetReference(); ElementId id = ref2.ElementId;
Element elem = doc.get_Element(id);
(elem Wall)
{
(reference.Proximity < (beamLen + tolerate)) {
sel.Elements.Add(elem);
}
}
}
trans.Commit();
Result.Succeeded;
}
}url:http://greatverve.cnblogs.com/p/FindReferencesWithContextByDirection.html