牆飾條對應的類是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>
- 首先,pick一個牆作爲宿主,
- 使用過濾器過濾出所有的WallSweep的類型,獲取第一個
- 通過構造函數創建對象WallSweepInfo作爲參數之後,我們還可以繼續通過它的屬性來修改設置,例如調用wallSweepInfo.Distance = 2來設置牆飾條距離牆底邊的距離。
- 最後調用WallSweep.Create來創建牆飾條