MultiReferenceAnnotation Example

Miguel Angel Alanis asked on the Autodesk Revit API discussion forum for an example of making use of the new MultiReferenceAnnotation.

I put together this blog post to make sure the solution is easily found.

First, a note on something more imminent:

Portathon Day 1

Today is the first day of the Portathon!

Wish us all luck and much success, please.

Looking forward to seeing you there!

MultiReferenceAnnotation Creation Sample Code

Back to the main topic:

Question: Is it possible to get an example to create a multi-rebar annotation?

I searched the Revit SDK and found I have to use the MultiReferenceAnnotation class, but I can't build an example with the current information.

I use the Autodesk.Revit.Creation.Document.Create.NewTag method to create a normal rebar tag, and I notice the independent tag has a property named MultiReferenceAnnotationId.

Answer: Please note the MultiReferenceAnnotation.Create method taking a MultiReferenceAnnotationOptions argument.

The minimum options are probably the type and ElementsToDimension.

Here is an excerpt from an internal test suite. It refers to a couple of hardcoded element ids. Use the documentation to figure out their use:

  var view = GetElement<View>( 124186 );
 
  var rebarList = GetElements<Element>(
    doc, new[] { 280427 } ).ToList();
 
  Assert.IsTrue( rebarList.Count > 0,
    "There are no rebars in the document!" );
 
  IList<ElementId> elementIds
    = new List<ElementId>();
 
  foreach( Element rebar in rebarList )
  {
    elementIds.Add( rebar.Id );
  }
 
  MultiReferenceAnnotationType type
    = GetElement<MultiReferenceAnnotationType>(
      doc, 260544 );
 
  Assert.IsNotNull( type,
    "the MultiReferenceAnnotationType does not exist!" );
 
  MultiReferenceAnnotationOptions options
    = new MultiReferenceAnnotationOptions( type );
 
  options.TagHeadPosition = new XYZ( 0, 100, 0 );
  options.DimensionLineOrigin = new XYZ( 5, 5, 1 );
  options.DimensionLineDirection = new XYZ( 0, 1, 0 );
  options.DimensionPlaneNormal = view.ViewDirection;
  options.SetElementsToDimension( elementIds );
 
  using( Transaction tran = new Transaction( doc ) )
  {
    tran.Start( "Create_Rebar_Vertical" );
 
    var mra = MultiReferenceAnnotation.Create(
      doc, view.Id, options );
 
    var dimension = GetElement<Dimension>(
      doc, mra.DimensionId );
 
    tran.Commit();
  }

Many thanks to Miguel Angel for raising this issue.

Case Newsletter

By the way, I really enjoy the case newsletter and the fun items it points to, for instance this mental eyeballing exercise and lawn chair magic video.

Besides the fun stuff, it presents a lot of useful architectural programming news as well.