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 an element using the ElementTransformUtils.MirrorElement method.
Here is the code:
public void SelectAndMirrorElement()
{
Reference pickedObj = CachedUiApp.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Please select an element to mirror.");
if (pickedObj != null && pickedObj.ElementId != ElementId.InvalidElementId)
{
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, "SelectAndMirrorElement"))
{
trans.Start();
ElementTransformUtils.MirrorElement(CachedDoc, pickedObj.ElementId, plane);
trans.Commit();
}
}
}
If the SelectAndMirrorElement method is placed into an external command created automatically by the RevitAddinWizard, we are ready to go.
Inside Revit, if we have a wall element and some attachments such as a door and two windows like the following:
After the command is triggered, the above wall is selected, and two points are picked, the wall along with its 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 PickObject() method needs to filter some elements specifically such as walls only, the Selection Filter wizard can save a lot of time.
Recent Comments