This macro rotates elements 90 degrees.
public void RotateElements()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = this.ActiveUIDocument.Document;
// Get the element selection of current document
Selection selection = uidoc.Selection;
//store element id's
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
try
{
foreach (ElementId id in selectedIds)
{
Element e = doc.GetElement(id);
BoundingBoxXYZ box = e.get_BoundingBox(doc.ActiveView);
if (null == box)
{
throw new Exception("Selected element doesn't contain a bounding box.");
}
XYZ p1 = new XYZ((box.Min.X + box.Max.X)/2, (box.Min.Y + box.Max.Y)/2, 0);
XYZ p2 = new XYZ((box.Min.X + box.Max.X)/2, (box.Min.Y + box.Max.Y)/2, 10);
using (Transaction trans = new Transaction(doc, "rotate"))
{
try
{
trans.Start();
Line axis = Line.CreateBound(p1, p2);
ElementTransformUtils.RotateElement(doc, id, axis, Math.PI/2);
trans.Commit();
ICollection<ElementId> noneselected = new List<ElementId>();
uidoc.Selection.SetElementIds(noneselected);
uidoc.Selection.Dispose();
}
catch
{
}
}
}
}