Text Size

I am back again from the Autodesk European Football Tournament 2011 in Verona, Italy, vividly described in more detail by Kean on his blog. We were both part of the combined Global Services (to which we of ADN belong) and Worldwide Marketing team:

Autodesk GS&M Team 2011

Back to the Revit API, we already looked at some aspects of text formatting such as textnote alignment and rotation. Here is a still more immediate and simpler issue:

Question: I created some text using the NewTextNote method. Now I would like to change its size or font like a normal user might do using Edit type > Text size. How can that be achieved programmatically?

Answer: The Text Size parameter can be set as follows:

  Reference r = uidoc.Selection.PickObject( 
    ObjectType.Element );
  TextElement text = doc.GetElement( r ) 
    as TextElement;
  TextElementType textType = text.Symbol;
  Parameter textSize = textType.get_Parameter( 
    "Text Size" );
  Transaction transaction 
    = new Transaction( doc );
  transaction.Start( "change text size" );
  // units are in feet, so this is 1/8"
  double newSize = ( 1.0 / 8.0 ) * ( 1.0 / 12.0 ); 
  textSize.Set( newSize );

Obviously, it would be better still to use the built-in parameter enumeration value to identify the text size parameter, rather than the language dependent user display parameter name.