Start
[Transaction (TransactionMode. Manual)]
[Regeneration (RegenerationOption. Manual)]
CmdDuctWall: IExternalCommand
{
Result Execute (ExternalCommandData upload data, msg, ElementSet elements)
{
UIApplication uiApp = response data. Application;
UIDocument uiDoc = upload data. 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> nointersectwils = collector. OfClass (Wall). WherePasses (invertFilter). ToElements ();
(Element el nointersectwils)
{
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> nointersectwils = collector. OfClass (Wall). WherePasses (invertFilter). ToElements ();
(Element el nointersectwils)
{
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;
}
;
}
}