Subscribing to UI Automation Events

Rudolf Honke of acadGraph CADstudio GmbH recently presented his results of exploring the Revit ribbon internals using UISpy and driving Revit using UI Automation.

He sent an additional note to point out that this rapidly leads to many other very interesting possibilities, such as the following:

Subscribing to UI Automation events could easily enable an application to be notified whenever a user...

The events could be handled using a stand-alone application or a Revit add-in, registering the listener in the Revit external application OnStartup method...

Thinking about using it with the OnStartup method, I remember the fact that some parts of the Revit UI may not be generated completely at this time. In this method, you usually create your buttons, so the ribbon bar may be in rebuilding process. Also, the ribbon bar could be invisible or disabled if there is no opened project file.

Some time ago, I developed some functions to check the ribbon bar state before pressing any tab header or button. One of these functions maximizes the ribbon bar if it is minimized.

By the way, if you just want to be notified if the app window is resized or moved, you could also use a BackgroundWorker which checks the Window.Size ten times a second. Using old (but fast) Windows API methods via P/Invoke, this "polling" can be done with up to 50 Hz or more – ups, another theme for posting...

Hey, you could combine the notifyMeIfRoomIsToBeCreated listener with an OnDocumentOpened event, so the 'Create Room' button must be accessible (but you would have to check whether it is a family document)...

Anyway, just think of the possibilities this can offer!

A number of these features have actually been requested in the past, and nobody provided the UI Automation expertise to answer them ... until now.

Once again, many thanks to Rudolf for his many ideas and these valuable pointers!