RevitAPI: 如何使用API创建墙饰条

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/lushibi/article/details/48476885

墙饰条对应的类是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来创建墙饰条

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页