Rotating AnnotationSymbols using the Revit API

By Saikat Bhattacharya

How can we rotate the an annotation symbol (as shown below) around an axis (horizontal) that is shown.

image

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;

 

   &#160
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;

    }

  }        

}

 


Comments

3 responses to “Rotating AnnotationSymbols using the Revit API”

  1. Hi Saikat,
    just an addition:
    As far as I know, there could be situations where AnnotationSymbols need to be rotated immediately after creating them.
    Depending on the orientation of the view a AnnotationSymbol is placed in, it may occurr that it is displayed upside-down.
    So one must make sure its orientation is correct after inserting, by rotating them.
    Best regards,
    Rudolf

  2. Sounds logical. Thanks for sharing your findings.

  3. Does any know if a you can tap into the previewing of tagging placement to use with a custom tagging command that creates a perfect flat/short landing on the leader.
    We already have an program that creates the tag on two clicks & then modifies the landing accordingly based on text length & orientation/direction from object, but we can’t see it until/preview until after the second click/placement.
    A very short video of what I am asking about.
    https://youtube.com/shorts/GjAp4COuaUQ?feature=share

Leave a Reply to JOHN D MOLLYHORNCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading