本文主要是介绍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>
- 首先,pick一个墙作为宿主,
- 使用过滤器过滤出所有的WallSweep的类型,获取第一个
- 通过构造函数创建对象WallSweepInfo作为参数之后,我们还可以继续通过它的属性来修改设置,例如调用wallSweepInfo.Distance = 2来设置墙饰条距离墙底边的距离。
- 最后调用WallSweep.Create来创建墙饰条
这篇关于RevitAPI: 如何使用API创建墙饰条的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!