The ElementTransformUtils class provides two static methods to rotate one or several elements in the project.
Table 20: Rotate Methods
Member |
Description |
RotateElement(Document, ElementId, Line, double) |
Rotate an element in the document by a specified number of radians around a given axis. |
RotateElements(Document, ICollection<ElementId>, Line, double) |
Rotate several elements by IDs in the project by a specified number of radians around a given axis. |
In these methods, the angle of rotation is in radians. The positive radian means rotating counterclockwise around the specified axis, while the negative radian means clockwise, as the following pictures illustrates.
Figure 31: Counterclockwise rotation
Figure 32: Clockwise rotation
Note that pinned elements cannot be rotated.
Code Region 10-5: Using RotateElement() |
public void RotateColumn(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.Element element) { XYZ point1 = new XYZ(10, 20, 0); XYZ point2 = new XYZ(10, 20, 30); // The axis should be a bound line. Line axis = Line.CreateBound(point1, point2); ElementTransformUtils.RotateElement(document, element.Id, axis, Math.PI / 3.0); } |
If the element Location can be downcast to a LocationCurve or a LocationPoint, you can rotate the curve or the point directly.
Code Region 10-6: Rotating based on location curve |
bool LocationRotate(Autodesk.Revit.ApplicationServices.Application application, Autodesk.Revit.DB.Element element) { bool rotated = false; // Rotate the element via its location curve. LocationCurve curve = element.Location as LocationCurve; if (null != curve) { Curve line = curve.Curve; XYZ aa = line.GetEndPoint(0); XYZ cc = new XYZ(aa.X, aa.Y, aa.Z + 10); Line axis = Line.CreateBound(aa, cc); rotated = curve.Rotate(axis, Math.PI / 2.0); } return rotated; } |
Code Region 10-7: Rotating based on location point |
bool LocationRotate(Autodesk.Revit.ApplicationServices.Application application, Autodesk.Revit.Element element) { bool rotated = false; LocationPoint location = element.Location as LocationPoint; if (null != location) { XYZ aa = location.Point; XYZ cc = new XYZ(aa.X, aa.Y, aa.Z + 10); Line axis = Line.CreateBound(aa, cc); rotated = location.Rotate(axis, Math.PI / 2.0); } return rotated; } |