RevitLookup and TextNote Alignment

To take a break from all the exciting Revit 2011 oriented news and dash off a quick post while continuing my preparations for the Revit programming introduction workshop here in Warsaw, I thought I would simply present a recent case handled by my colleague Saikat Bhattacharya.
While doing so, however, I ran into yet another 2011 related issue concerning RevitLookup, previously known as RvtMgdDbg, which I thought I should mention before diving into the details of the case.

RevitLookup

Both I and many others have repeatedly extolled the virtues of
RvtMgdDbg,
the Revit database exploration and snooping tool.
The in-depth description above is based on the version for Revit 2009.
A
version for Revit 2010 is
also available.
One issue with this tool in the past has been that although it is an invaluable and irreplaceable debugging and exploration tool, it has been developed and managed by a separate team.
That has now happily changed.
From Revit 2011 onwards, this tool has been taken over by the team that manages the Revit SDK and is thus included there.
Since the Revit SDK is included in the Revit setup files, RevitLookup is now available with every installation of Revit.
At the same time, the old name RvtMgdDbg was deemed unpronounceable and it has therefore been renamed to RevitLookup.
With that small but important and happy bit of information out of the way, let us look at an example of using it.

TextNote Alignment

Question: I am trying to copy a TextNote from one Revit document to another.
I need to access the TextAlignment value in order to pass it to the Create.NewTextNote method in the target document.
Using RevitLookup, I can see that the TextNote object has a HORIZ_ALIGN parameter which defines the horizontal alignment, but I cannot find a corresponding parameter for the vertical alignment within the TextNote or the TextNoteType object.
Which object contains the vertical alignment information, so I can combine both the horizontal and vertical alignment for the call to the Create.NewTextNote method?
Here is a screenshot of RevitLookup displaying the HORIZ_ALIGN parameter:

HORIZ_ALIGN parameter

Answer: Your screen snapshot above shows RevitLookup exploring the officially available parameters on the TextNote object.
Many Revit elements have more parameters attached to them than the ones displayed in the official parameters collection.
The additional ones can be displayed by iterating over all possible values of the built-in parameters enumeration and trying to obtain a corresponding parameter for each.
This iteration is performed by RevitLookup if you click the ‘Built-in Enums Snoop’ button.
Doing that, you will discover that the text note vertical alignment information is stored in the built-in parameter TEXT_ALIGN_VERT, which is also located on the TextNote object.
Here is a screen snapshot showing how to access the value in RevitLookup:

TEXT_ALIGN_VERT parameter

To explore the meanings of the integer values stored in the TEXT_ALIGN_VERT parameter, I created three different text notes with varying vertical alignments using the API and looked at each of them in RevitLookup.
That showed that the internal values for the built-in parameter for the different vertical alignments correspond to the following TextAlignFlags:


TextAlignFlags.TEF_ALIGN_TOP = 512
TextAlignFlags.TEF_ALIGN_MIDDLE = 1024
TextAlignFlags.TEF_ALIGN_BOTTOM = 2048

You can thus extract the integer value of the TEXT_ALIGN_VERT parameter on the TextNote object and use it to recreate an equivalent new object with the same vertical alignment via the NewTextNote method.


Comments

5 responses to “RevitLookup and TextNote Alignment”

  1. Krispy5 Avatar
    Krispy5

    Hi Jeremy,
    When using the RevitLookup tool I am trying to use the “Snoop Application…” tool to get to the categories in the active document, however when I click on the “Documents” field i get an error.

  2. Krispy5 Avatar
    Krispy5

    Sorry, that was a bit vague, the specific exception is:
    Autodesk.Revit.Exceptions.ModificationOutsideTransactionException: Attempt to modify the model outside of transaction.

  3. Dear Krispy,
    Thank you for the note, I have passed it on.
    Since you have the source code, you should also be able to fix it yourself, you know.
    Just determine exactly where the exception is thrown and wrap the offending line of code in an exception handler. Ignore the exception, and you can continue snooping.
    Cheers, Jeremy.

  4. Krispy5 Avatar
    Krispy5

    Thanks Jeremy,
    Turned out to be a few problems:
    The initial problem was caused by the call to doc.PlanTopologies in the CollectorExtDoc.cs file (line 156), this call requires a Transaction and the command was in Manual Transaction mode. I changed the command to Automatic mode (in the TextCmds.cs file).
    After fixing that problem, another occured; the lines directly below the previous problem line create an element set and adds this to the snoop data, this was casuing exceptions so i wrapped this in a try block.
    Finally, another exception occured further down the same file where it is attempting to snoop the electrical settings. This was already wrapped in a try/catch block but was still throwing an exception, i change the type of exception it was try to catch from ‘SystemException’ to just ‘Exception’ and this seemed to fix the problem (not sure why).
    So i now have it running and am able to get to the Categories as I originally planned.
    Hope this helps someone.

  5. Dear Krispy,
    Congratulations on solving the problem, and very many thanks for explaining how to do so!
    I submitted a problem report to the team responsible for this tool, so they will be taking a look at it as well.
    I will add your explanation to the report and I am sure they will find that useful.
    Thanks again and enjoy your snooping!
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading