How can we rotate the an annotation symbol (as shown below) around an axis (horizontal) that is shown.
In this specific case, the annotation symbol - or any other element that is view specific like details, annotations, text notes, etc, cannot be rotated out of the plane of the view. In the above mentioned case, if we use the given horizontal line (X axis) as the axis of rotation, it will rotate the annotation out of the plane of its placed view, which is the view plan, in this case. And doing this, will throw an error stating “Cannot rotate the element into this position”.
We can rotate the annotation about the Z axis, which is the correct approach for rotating this annotation symbol. For the rotation, we can either use the AnnotationSymbol.Location.Rotate() or ElementTransformUtils.RotateElement() method. The code snippet included shows the approach:
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
Reference annReference =
uiApp.ActiveUIDocument.Selection.PickObject(
Autodesk.Revit.UI.Selection.ObjectType.Element,
"Select AnnotationSymbol");
Element annSymb = doc.GetElement(annReference);
using (Transaction trans = new Transaction(doc, "rotate"))
{
trans.Start();
XYZ center = (annSymb.Location as LocationPoint).Point;
Line line =
uiApp.Application.Create.NewLineBound(
center,
center + XYZ.BasisZ);
AnnotationSymbol symb = annSymb as AnnotationSymbol;
if (null != symb)
{
//symb.Location.Rotate(line, Math.PI / 2.0);
ElementTransformUtils.RotateElement(
doc,
symb.Id,
line,
Math.PI / 2.0);
}
trans.Commit();
}
return Result.Succeeded;
}
}
}