程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Revit API找到風管穿過的牆(當前文檔和鏈接文檔)

Revit API找到風管穿過的牆(當前文檔和鏈接文檔)

編輯:C#入門知識

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;
        }
         ;
    }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved