Revit API 2012 provides a new utility class ElementTransformUtils which has some utilty methods that can be used to rotate, move, copy and mirror elements. In this article, let us see how to select and mirror elements using the ElementTransformUtils.MirrorElements method.
Here is the code:
#region Select And Mirror Elements
public void SelectAndMirrorElements()
{
IList<Reference> pickedObjs = CachedUiApp.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, "Please select elements to mirror.");
if (pickedObjs != null && pickedObjs.Count > 0)
{
XYZ pt1 = CachedUiApp.ActiveUIDocument.Selection.PickPoint("Pick the first point of the mirror line");
XYZ pt2 = CachedUiApp.ActiveUIDocument.Selection.PickPoint("Pick the second point of the mirror line");
Plane plane = new Plane(pt2.Subtract(pt1), new XYZ(0, 0, 1), pt1);
using (Transaction trans = new Transaction(CachedDoc, "SelectAndMirrorElements"))
{
trans.Start();
ElementTransformUtils.MirrorElements(CachedDoc, (from Reference r in pickedObjs
select r.ElementId).ToList(), plane);
trans.Commit();
}
}
}
#endregion
If the SelectAndMirrorElements method is placed into an external command created automatically by the RevitAddinWizard, we are ready to go.
Inside Revit, if we have two walls and some attachments such as a door and two windows, after the command is triggered, the above walls are selected, and two points are picked, the walls along with their attachments will be mirrored to the new location:
Revit Addin Wizard (RevitAddinWizard) provides a Selection Filter wizard which can help implement the ISelectionFilter interface automatically. In case the PickObjects() method needs to filter some elements specifically such as walls only, the Selection Filter wizard can save a lot of time.
Recent Comments