By Aaron Lu
Wall Sweep's API class is WallSweep, but there is no method like NewWallSweep under Document.Create object, so how to create it via API?
The answer is using static method Create of WallSweep:
public static WallSweep Create(Wall wall, ElementId wallSweepType, WallSweepInfo wallSweepInfo);
Code example:
var 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().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) { }
- First, pick a wall as the host
- then filter out all the wallsweep type and choose the first one
- create the argument object WallSweepInfo by calling the constructor of WallSweepInfo, note that we can continue to customize it by setting its properties, e.g. in this example, by calling 'wallSweepInfo.Distance = 2' to set the distance of the wall sweep to the bottom of the hosted wall
- Finally, call WallSweep.Create function to create the wall sweep