Revit API 獲取某牆上洞口的尺寸和位置


 [Transaction(TransactionMode.Manual)]

[Regeneration(RegenerationOption.Manual)]
public class cmd20120604 : IExternalCommand
{
    public Result Execute(ExternalCommandData cmdData, ref string messages, ElementSet elements)
    {
        UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
        Autodesk.Revit.ApplicationServices.Application app = cmdData.Application.Application;
        Selection sel = uiDoc.Selection;

        FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
        collector.OfClass(typeof(Opening)).OfCategory(BuiltInCategory.OST_SWallRectOpening);

        //wallId 618627
        var wallOpenings = from c in collector where ((Opening)c).Host.Id == new ElementId(618627) select c;

        foreach (Element el in wallOpenings.ToList())
        {
            Opening opening = el as Opening;
            if (opening.IsRectBoundary)
            {
                //opening.BoundaryRect;
                //opening.BoundaryCurves;
            }
        }

        WinFormTools.MsgBox(wallOpenings.Count().ToString());

        return Result.Succeeded;
    }
}

 

問題:

通過Document.Create.NewOpening(wall, xyz1, xyz2); 可在牆上開洞。
假如下次執行同樣的操作revit自身會報錯,沒有可剪切的牆體。
請問:怎樣判斷那個位置已經開洞?

答:

1. 你可以用Opening類為條件,過濾出Opening對象,再根據Linq 查詢,找出在一個給定牆上的Opening對象。 使用條件: Opening.Host == givenWallId.

這樣就可以獲得牆上所有的洞口。

2. 然后可以從Opening.IsRectBoundary 判斷洞口是否為矩形。矩形洞口的兩個對角點坐標可以從Opening.BoundingRect 獲得。也可以獲得矩形的四個邊Opening.BoundaryCurves.

3. 既然獲得洞口尺寸和位置,你就可以判斷你的目標洞口與原有洞口的關系。

url:http://greatverve.cnblogs.com/p/revit-api-get-hole.html 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM