RevitAPI: 如何使用API創建牆飾條

牆飾條對應的類是WallSweep,很明顯在Document.Create下面沒有NewWallSweep這樣的函數,那麼如何創建呢?


答案就是使用WallSweep的靜態函數Create:

public static WallSweep Create(Wall wall, ElementId wallSweepType, WallSweepInfo wallSweepInfo);


示例代碼:

doc = commandData.Application.ActiveUIDocument.Document;
var uiSel = commandData.Application.ActiveUIDocument.Selection;

try
{
    var reference = uiSel.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Pick wall");
    var wall = doc.GetElement(reference) as Wall;
    ElementType wallSweepType = new FilteredElementCollector(doc)
        .OfCategory(BuiltInCategory.OST_Cornices)
        .WhereElementIsElementType()
        .Cast<elementtype>().FirstOrDefault();
    if (wallSweepType != null)
    {
        var wallSweepInfo = new WallSweepInfo(WallSweepType.Sweep, false);
        wallSweepInfo.Distance = 2;
        using (Transaction transaction = new Transaction(doc))
        {
            transaction.Start("create wall sweep");
            WallSweep.Create(wall, wallSweepType.Id, wallSweepInfo);
            transaction.Commit();
        }
    }
    else
    {
        TaskDialog.Show("ERROR", "no wall sweep type is found");
    }
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
}</elementtype>
  1. 首先,pick一個牆作爲宿主,
  2. 使用過濾器過濾出所有的WallSweep的類型,獲取第一個
  3. 通過構造函數創建對象WallSweepInfo作爲參數之後,我們還可以繼續通過它的屬性來修改設置,例如調用wallSweepInfo.Distance = 2來設置牆飾條距離牆底邊的距離。
  4. 最後調用WallSweep.Create來創建牆飾條

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章