start
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
cmdDuctWall : IExternalCommand
{
Result Execute(ExternalCommandData cmdData, msg, ElementSet elements)
{
UIApplication uiApp = cmdData.Application;
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Selection sel = uiDoc.Selection;
Transaction ts = Transaction(uiDoc.Document, );
ts.Start();
FilteredElementCollector collector = FilteredElementCollector(doc);
collector.OfClass((Instance)).OfCategory(BuiltInCategory.OST_RvtLinks);
List<> listPath = GetLinkFilePaths(doc);
Duct duct = doc.GetElement(sel.PickObject(ObjectType.Element, )) Duct;
(Element elDoc collector)
{
Instance ins = elDoc Instance;
(ins != )
{
Transform transForm = ins.GetTransform();
strKey = elDoc.Name.Substring(, elDoc.Name.IndexOf());
strPath = GetLinkPath(listPath, strKey);
Document docLink = uiApp.Application.OpenDocumentFile(strPath);
List<Wall> listWall = FindDuctWall(doc, duct, docLink, ins.GetTransform().Origin);
TaskDialog.Show(, listWall.Count.ToString());
List<Wall> listWall1 = FindDuctWall(doc, duct);
TaskDialog.Show(, listWall1.Count.ToString());
}
}
ts.Commit();
Result.Succeeded;
}
List<Wall> FindDuctWall(Document doc, Duct duct)
{
List<Wall> listWall = List<Wall>();
BoundingBoxXYZ bb = duct.get_BoundingBox(doc.ActiveView);
Outline outline = Outline(bb.Min, bb.Max);
FilteredElementCollector collector = FilteredElementCollector(doc);
BoundingBoxIntersectsFilter invertFilter = BoundingBoxIntersectsFilter(outline, );
IList<Element> noIntersectWalls = collector.OfClass((Wall)).WherePasses(invertFilter).ToElements();
(Element el noIntersectWalls)
{
Wall wall = el Wall;
(wall != )
listWall.Add(wall);
}
listWall;
}
List<Wall> FindDuctWall(Document doc, Duct duct, Document docLink, XYZ xyz)
{
List<Wall> listWall = List<Wall>();
BoundingBoxXYZ bb = duct.get_BoundingBox(doc.ActiveView);
Outline outline = Outline(bb.Min - xyz, bb.Max - xyz);
FilteredElementCollector collector = FilteredElementCollector(docLink);
BoundingBoxIntersectsFilter invertFilter = BoundingBoxIntersectsFilter(outline, );
IList<Element> noIntersectWalls = collector.OfClass((Wall)).WherePasses(invertFilter).ToElements();
(Element el noIntersectWalls)
{
Wall wall = el Wall;
(wall != )
listWall.Add(wall);
}
listWall;
}
List<> GetLinkFilePaths(Document doc)
{
List<> listPath = List<>();
(ElementId elId ExternalFileUtils.GetAllExternalFileReferences(doc))
{
(doc.get_Element(elId).IsExternalFileReference())
{
ExternalFileReference fileRef = doc.get_Element(elId).GetExternalFileReference();
(ExternalFileReferenceType.RevitLink == fileRef.ExternalFileReferenceType)
listPath.Add(ModelPathUtils.ConvertModelPathToUserVisiblePath(fileRef.GetAbsolutePath()));
}
}
listPath;
}
GetLinkPath(List<> listPath, strKey)
{
( strPath listPath)
{
(strPath.Contains(strKey))
strPath;
}
;
}
}