Driving Revit from Outside

We are winding up here at Autodesk University, with a final panel session to

meet the AEC API experts

yesterday afternoon, and one on

advanced use of the Revit API

this morning.

One topic that keeps cropping up in infinite variations and was mentioned several times in my sessions here at AU is how to drive Revit reliably from an application.
The Revit API assumes that all interaction with the API functionality happens from within an external command.
In general, this requires user interaction to select a menu entry or click a toolbar button to trigger the external command execution.
In many cases, an application would like to make use of the API without requiring this explicit manual user interaction to initiate it.
One example of such a situation is a modeless dialogue displayed side by side with the Revit user interface.

It is actually possible to at least query the model from a modeless dialogue without explicitly starting a command.
It does help if you open a transaction before accessing the document.
Making modifications to a document definitely does not work, however, without being within in the context of an external command execution.
The good news is that it is possible to trigger the execution of an external command programmatically using Win32 API functions to simulate the required user input, such as a menu entry selection.
Here are some of the topics that are of interest in this context, related topics for me to remember and you to optionally ponder until we get around to discussing them in depth:

  • Determining the Revit window handle.
  • Initiating a Revit external command from an external application.
  • Driving Revit from a modeless dialogue.
  • Synchronisation issues, such as determining when a command has begun and terminated.
  • Executing a command that creates new elements and determining which ones they are.
  • Opening and activating a document in Revit.

Simply opening a new document in the background is not an issue, since the API provides the Application OpenDocumentFile method, but there is no Revit API call to activate it. There is, however, a known workaround. What do you think it is? Don’t worry; we will get to it one of these days.

This post starts off the exploration of these issues by addressing the first two points, determining the Revit window handle and triggering some Revit menu picks from an external command line application. It is so simple that I can list the code right here and now:


[DllImport( "USER32.DLL" )]
public static extern IntPtr FindWindow(
  string lpClassName, string lpWindowName );
[DllImport( "USER32.DLL" )]
public static extern bool SetForegroundWindow(
  IntPtr hWnd );
 
const string _window_class_name_zero
  = "Afx:00400000:8:00010011:00000000:007B05A1";
const string _window_class_name_project_open
  = "Afx:00400000:8:00010011:00000000:007B05A1";
 
static int Main( string[] args )
{
  IntPtr revitHandle
    = FindWindow( _window_class_name_project_open, null );
  if( IntPtr.Zero == revitHandle )
  {
    revitHandle = FindWindow( _window_class_name_zero, null );
  }
  if( IntPtr.Zero == revitHandle )
  {
    Console.WriteLine( "Unable to find Revit window."
      + " Is Revit Architecture up and running yet?" );
    return 1;
  }
  SetForegroundWindow( revitHandle );
  SendKeys.SendWait( "{F1}" );
  SetForegroundWindow( revitHandle );
  SendKeys.SendWait( "^{F10}{LEFT}{LEFT}{DOWN}{UP}{ENTER}" );
  return 0;
}

I am providing the complete Visual Studio solution implementing this
console application named SendCmd
here.

We use the two Win32 API functions FindWindow() to get a handle to an application window and SetForegroundWindow() to activate it.
In the call to the former, we need to specify either a window caption or a window class name.
Both of these can be obtained using the Visual Studio Spy++ tool, which is available under Start > Programs > Microsoft Visual Studio 2005 > Visual Studio Tools > Spy++.
The window class name varies from one Revit version to the next, and also between different flavours of Revit.
In addition, the class name is different depending on whether Revit has a project document open or not.
We would call the latter a zero document state.
Another difference between these two states is that no external tools can be activated in zero document state, which is another reason why it is useful to be able to differentiate between the two states.
The two class names for the open project and zero documents states specified in the code are valid for Revit Architecture 2009 Build 20080915_2100.

The code in the Main() function searches for a window belonging to a running instance of Revit, first with an open project, then, if that fails, with no project open.
If that fails as well, a message is printed, and the program terminates.
Otherwise, it ensures that the Revit window is brought to the foreground and sends two keystroke sequences to it:

  • "{F1}" to open the help file.
  • "^{F10}{LEFT}{LEFT}{DOWN}{UP}{ENTER}" to enter the menu system, navigate to a particular menu entry, and activate it.

The first sequence is a simple hit of the F1 function key to open the Revit help file.
The second sequence represents “Ctrl + F10, Left Arrow, Left Arrow, Down Arrow, Up Arrow, Enter”.
This activates the Revit menu and then navigates to and selects the menu entry Help > About… to display the about box.
Thus, running this program with an open instance of Revit will pop up the Revit help file and about dialogue.

We will probably revisit this question in more depth and from other points of view in future discussions.
To start it off, we have looked at the simple scenario of running a standalone command line executable and triggering a menu selection in a running instance of Revit.
A related possibility would be to send language dependent strings to activate menu items.
For instance, to execute the line command on a Spanish version of Revit Architecture, one could use the string “(%M)í”:

  • (%M) opens the “Modelling Menu”.
  • í is the Spanish menu shortcut for the Line command.

In Revit 2008, it was also possible to send the simple keystroke sequence “LI” for the shortcut that appears in the keyboardShortcuts.txt file, but that no longer seems to work in Revit 2009.

An issue in this scenario is that the SendWait() method does not wait for the user to finalise the command.
It is asynchronous. Once you have sent the keystroke sequence, you need to wait until the command has actually been activated by Revit before you can start interacting with it.
How can we determine when the command is active, and also when it has ended?

For more information on the use of SendKeys and the preparation in setting the active foreground window, you can look at the MSDN documentation on how to

simulate mouse and keyboard events
in code.
The escape codes used with SendWait() are explained in the section on

SendKeys.Send()
.
Using Ctrl + F10 to activate the menu bar, followed by arrow keys to navigate to the proper menu entry, make the key sequence language independent,
so it does not need to be modified to handle different language dependencies, e.g. for the English or Spanish menu shortcuts.

There are

other ways

of doing this as well. One developer mentioned that using SendMessage() requires more work to implement, but is considerably more reliable.
Also, in the minimal sample above, we are using a simple call to FindWindow() to determine the Revit handle.
This will not deal reliably with multiple sessions. In such a case, EnumWindow is sometimes a better way to go, or you can make use of the

process name

to identify the required instance and retrieve its window handle.


Comments

55 responses to “Driving Revit from Outside”

  1. Jeremy,
    The problem is not so much that OpenDocumentFile doesn’t support activating a project. It’s more that it doesn’t give you the control over how that project is opened as per the standard dialog. ie workset control. Doable but a lot lot more work.
    Are these discussions from AU going to be posted on ADN or the AU site Jeremy?

  2. Hi Guy,
    Thank you for the clarification! Please do submit requests for the functionality you require to ADN, Anthony Hauck once again pointed out how important and eagerly awaited all developer input is to guide future development. The discussions at AU were a little bit too unstructured to be published as is, they provided lots of ideas and inspiration but cannot be immediately converted into a blog posting, I’m afraid.
    Best regards, Jeremy.

  3. Guy Robinson Avatar
    Guy Robinson

    Hi Jeremy, Anthony is well aware of my wishes ;-) Have presented alternative approach to getting the handle here: http://redbolts.com/blog/post/2008/12/08/Zoom-your-BIM.aspx

  4. Jeremy, I wanted to ask you a question an AU, but every time I saw you, your head was buried in your laptop.
    I’ve never used Revit, and know nothing about its API, but I received numerous requests from AU attendees to make Revit dialogs resizable the way my QuikPik utility makes AutoCAD dialogs resizable. To do that, I need a way to load an unmanaged DLL into the Revit process. Does Revit support that? Is it just a matter of adding a registry entry to tell Revit to load my DLL (like AutoCAD’s demand loading system)?

  5. Hi Guy,
    Glad to hear it and thank you for the pointer to your post. Unfortunately there is something garbled in it, I cannot see all of the source code, the first section is collapsed and I am unable to uncollapse it somehow.
    Cheers, Jeremy.

  6. Hi Owen,
    Oh dear, I am awfully sorry that I missed the chance of discussing this with you at AU. I was rather overdue preparing my presentations :-) Nope, I do not know of any way to load an unmanaged DLL into the Revit process.
    Cheers, Jeremy.

  7. Does Autodesk have plans to update the API so that an external application can drive Revit without the need for Win32 API function calls?
    Regards,
    Grant

  8. Hi Grant,
    Long-term probably yes, but first of all we cannot make any binding statements whatsoever about future products, and secondly please don’t hold your breath.
    Cheers, Jeremy.

  9. Hakan WIkemar Avatar
    Hakan WIkemar

    Hi Jeremy!
    I hope all is well with you, last time I saw you I was working with Autodesk in Gothenburg and you were visiting, now I’m working with a reseller/CAD consultant. Any who, I have a similar issue, Im trying to call a second dll’s IExternalCommand…Execute from within the ExternalCommand of a main one. It seems to work perfectly reading all the right values and properties, calling up dialogs from within that dll, but I can’t seem to be able to write values to the database (i.e. edit a sharedParameter (I’m just passing along the CommandData, message and ElementSet. Do you know if this is at all possible?
    Cheers
    /Hakan Wikemar

  10. Hejsan Håkan,
    Nice to hear from you and hope you are enjoying the new job!
    So, if I understand you correctly, you have defined two external commands, e.g. A and B. You are registering external command A with Revit and executing it as normal. A is calling B and passing in all three arguments unmodified, the command data, message and element set. I see no reason why that should not work. I have done that myself in C#, and actually my rather convoluted F# example is doing the very same thing as well:
    http://thebuildingcoder.typepad.com/blog/2009/01/hello-f-via-c.html
    Note that Ralf Huvendiek’s direct solution for loading an F# module avoids my unnecessary intermediate step:
    http://thebuildingcoder.typepad.com/blog/2009/01/use-f-directly-in-revit.html
    Oh, on second thoughts, none of the samples I have made that call a second external command from a first one try to modify the database. Do you remain within the context of Revit calling the external command? I would have expected it to work, but have actually never tried it myself.
    Best regards, Jeremy.

  11. Hakan WIkemar Avatar
    Hakan WIkemar

    Hej Jeremy, Jag får bland annat koda applikationer till Revit så jag trivs mycket bra :).
    Yes the hello-f-via-c is exactly what I am attempting (well more like helloandmodifydatabase-vb-via-c). I’m trying to build my own UI to call other individual applications (with the bonus that they could be written in any language) that also could be loaded independantly. My code looks almost exactly like yours:
    MyTools.MyCommand aCommand = new MyTools.MyCommand();
    aCommand.Execute(commandData, ref message, elements);
    It works beutifully except I can’t get it to modify the database.
    I would expect it to work as I suspect that for example the REX explorer works like this.
    I tried to call the SDK Example Revit.SDK.Samples.DoorSwing.CS.InitializeCommand
    Using this method and the UI works but the properties does not get written :(.
    I must be doing something wrong, I’ll investigate further. Thanks again!
    Cheers
    /Hakan

  12. Hejsan Håkan,
    Glad you are enjoying it. I always thought it would work, but I do not know whether I ever actually tried to modify anything that way. One important thing before modifying a database is to have a transaction opened, but that happens automatically when an external command is executed.
    Cheers, Jeremy.

  13. Hakan WIkemar Avatar
    Hakan WIkemar

    Yey! I got it to work and the reason was of couse me. Somehow it seems like it found its way to a:
    return IExternalCommand.Result.Cancelled;
    on every run and i guess this cancels the automatic transaction, right?
    It’s allways something simple that takes forever to find that turns out to be the issue :)
    Thanks a million for your input
    Cheers
    /Hakan

  14. Dear Håkan,
    Wow, congratulations, I am very glad you found a solution and it was a pleasure supporting you in the search.
    Yes, exactly, returning IExternalCommand.Result.Cancelled cancels the automatic transaction that Revit starts for your external command invocation, c.f.
    http://thebuildingcoder.typepad.com/blog/2008/12/document-ismodified-property.html
    Cheers, Jeremy.

  15. Hi jeremy,
    Here, they ask me to have a new command which can do an export and a print of views in one command.
    [QUOTE]So, I’ve done it :
    private void SendKey()
    {
    IntPtr revitHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
    SetForegroundWindow(revitHandle);
    // appelle l’export
    SendKeys.SendWait(“(%F)EO”);
    // appelle le print
    SendKeys.SendWait(“(%F){I}”);
    return;
    }
    [/QUOTE]
    Can’t run the Print command!
    When I try to do an other command after (%F)EO, it works (for exemple, open, or else), but print command does not work….
    Do you have an idea?
    Cheers

  16. Hi Pierre-Nelson,
    Hmm, one idea might be to use the API to do the printing, via the print manager? That would give you full control.
    Have you tested invoking each of the two commands separately first? Have you tried reversing the order?
    Cheers, Jeremy.

  17. Hi jeremy,
    Thx for answering.
    Yes, I’ve already tested to run just print command and does not work.
    Anyway, no panic, I’ll try to print by the API.
    Cheers.

  18. Jeremy
    I am looking at the New Ribbon in Revit 2010. Would it be possible to re-order the items, (possibly create new items) on the Ribbon?

  19. Dear Jake,
    Thank you for this question. Especially for you, I’ll publish a little article on the topic of ribbons sometime soon :-)
    To answer your question directly, as far as I understand it:
    – All Revit add-ins are added to the Add-Ins tab and nowhere else. There is no way in 2010 for a Revit add-in to appear anywhere else in the ribbon.
    – All external commands are grouped into one single pull down menu provided by the External Tools button in the Add-Ins tab.
    – An external application can define its own panels inside the Add-Ins tab and populate them with items as it pleases. These items can include separators and standard and pull-down buttons. They can be arranged in a single or stacked layout with two or three rows.
    The ribbon sample creates the following items within the Add-Ins ribbon tab:
    – Two add-in application ribbon panels
    – A push button ‘Create Wall’
    – A three-layered stacked button
    – A pull-down button ‘Move Walls’
    – Tooltips
    – Separators
    I do not think these items can be reordered once they have been created, but obviously the application can define their order by creating them in the desired sequence.
    I hope this answers your question.
    Cheers, Jeremy.

  20. Hi Jeremy
    Thanks for the answer, but my question is not really about the Add-ins area in the Ribbon, more the Ribbon Control itself.
    At the moment I have an application that uses the Command IDs in Revit itself, and I use the following to call a command in the Revit Application:
    “PostMessage(iHwnd, WM_COMMAND, 33867, 0&)”
    This call starts the [Show ElementIds]function in Revit. I then use a series of API calls to type text in the text boxes and press the buttons etc.
    Because I can access the Menu in Revit2009, I can:
    1. Create a new pulldown menu
    2. Create a button on that pulldown menu and give it the commandID 33867, which, when I press it, it runs the Revit command.
    This allows me to create a ‘custom’ menu in Revit and add whatever I want onto it.
    NOW – Autodesk created a Revit Ribbon control to replace the menu, and although the menu is still there (it seems) just not shown, I have lost the ability to ‘hack’ the menu. (Or rather… hack I can, but can’t show it)
    I’d like to use the Windows API and create a Ribbon Tab, and add my ‘favourites’ to it, and show that on the Ribbon.
    OR even better – Add my ‘favourites’ to the Quick Access Toolbar. This seems fairly straight forward, I would imagine it to be working like this:
    Use the Windows API to add a new menu item to the QAT, give it the ID (that I know) and now it should be available in Revit.
    My problem?
    I know how to add a new menu item to a toolbar and to a menu in Revit
    I know how to remove existing menu items from the Revit menu
    I don’t know how to add anything to a ribbon in Revit.
    My goal No1:
    Add two non functional buttons to the QAT to seperate the Undo and Redo buttons (Why? Because I have a 30″ display monitor and the QAT buttons are a blur and I have to concentrate really intensely to click the right one)
    Goal No2:
    Add buttons to the QAT in the order that I want them
    Goal No3:
    Add ‘Other’ buttons to the QAT
    Goal No4:
    Resize the QAT to show 24×24 or even 32×32 size buttons

  21. Dear Jake,
    Thank you for the update, I understand your issue now. Wow. You have set yourself an impressive list of very interesting goals indeed, and I would be very interested to hear more about the experiences you make, especially if you succeed. I am sure many others would be very interested as well. Unfortunately, all of those topics are completely beyond the scope of the Revit API, as you are aware, and I am sorry to say that I don’t have any relevant suggestions to make to you. I hope some other interested parties will chip in, though.
    I also find the statements you make about being able to create your own custom menu in Revit 2009 interesting. I always believed this was possible and quite easy, but I never tried it out myself. I’m glad you succeeded and would have been interested to hear more about it. Water under the bridge, by now.
    One completely different approach that you might like to think about is creating some kind of modeless custom pane or toolbar that floats around and possibly interacts with the Revit ribbon and your add-in. That might be easier to implement that hacking the ribbon itself, which might be pretty closely wired in to Revit.
    Cheers, Jeremy.

  22. Jeremy
    I’ll keep you informed of my progress.
    Thanks
    Jake

  23. Thank you very much, and best of luck to you!

  24. Hi Jeremy,
    Hope you are fine..
    I am working with Autodesk Revit Architecture 2010.I am trying to invoke Revit External Tools Menu from outside using SendKeys.SendWait() command as mentioned in your blog.
    But i am not able to get upto External Tools sub menus (External Command MenuItem from Revit.ini)
    following is the sequence
    SendKeys.SendWait(“^{F10}{D}{E}{DOWN}{ENTER}”)
    Please see if you can help on this
    Thanks and Regards,
    Moiz

  25. Dear Moiz,
    Thank you, I am fine.
    The string you are trying to send also looks perfectly good to me.
    I tried to get my SendCmd application running with Revit 2010 and have not succeeded yet.
    One thing that definitely needs changing are the window class names. In my case, for Revit Architecture 2010 Build 20090317_2115, the window captions and class names for the zero document state and when a project is open seem to be
    “Autodesk Revit Architecture 2010 – [Recent Files] – [Recent Files]”
    “Autodesk Revit Architecture 2010 – [wall_footing.rvt – 3D View: {3D}] – [wall_footing.rvt – 3D View: {3D}]”
    “Afx:00400000:8:00010011:00000000:0090083F”
    “Afx:00400000:8:00010011:00000000:016707B7”
    Using this updated window class name, and sending the string that you provide does activate the Add-Ins tab and the External Commands panel but does not trigger the external command.
    Furthermore, even the tab and panel activation is not completely reliable … it sometime works and sometimes does not.
    I tried another approach as well to solve your issue, by defining a keyboard shortcut for the external command as described in
    http://thebuildingcoder.typepad.com/blog/2009/04/addin-keyboard-shortcut.html
    I am using the Revit SDK HelloWorld sample to test, so I added a shortcut
    “HW” ribbon:”Add_Ins-External-External Tools-Hello World (CS)”
    Then I tried to send the string “HW” to the Revit window. Strangely enough, Revit seems to be interpreting this as Shift + W and displaying the navigation wheel instead. When I type in “HW” manually, it works every time.
    What I also noticed is that the window class name changed from one session to the next. In a later session, when a document was opened, it was
    “Afx:00400000:8:00010011:00000000:00010E4F”
    In other words, the last part changed from “016707B7” to “00010E4F”.
    So one will probably have to change the call using FindWindow to something more flexible which tests for a partial window class name, and maybe the partial window caption as well, to identify the Revit window. Or use the process name instead, as I did in
    http://thebuildingcoder.typepad.com/blog/2009/02/revit-window-handle-and-modeless-dialogues.html
    I am sorry I cannot dive deeper still into this at the moment.
    I hope this helps you with your further research, and look forward to hearing about a solution, hopefully, from somebody.
    Cheers, Jeremy.

  26. Hi Jeremy,
    We are using Autodesk revit Architecture 2010
    We have used External Application as plugin to revit
    We are facing Problem in Save, SaveAs and Close API.It throws , “Save is temporarily disabled” exception
    Do you any clue on this ?
    Regards,
    Moiz

  27. Dear Moiz,
    Nope, sorry, never heard of that problem before.
    By the way, in your SendKeys.SendWait issue, are you just starting up Revit with a project file, running a single command, and then closing down Revit again immediately? If it is such a simple sequence, or similarly simple, then you can also achieve it by driving Revit through a journal file:
    http://thebuildingcoder.typepad.com/blog/2009/05/vb-samples-and-other-questions.html#1
    Cheers, Jeremy.

  28. Moiz
    I found that some commands are disabled in different views. I normally switch to {3D} view is these commands don’t work, and then execute the function. I guess you might have the same problem.

  29. Moiz to you too, dear Jake,
    That is a greeting I have never seen before, nor can I find any mention of it in Wikipedia. Did you invent it yourself? Or is it just a typo?
    Anyway, yes, I think this problem or maybe simply feature is common and pretty well understood. There are various situations that can cause commands in the ribbon to be greyed out or disabled:
    http://thebuildingcoder.typepad.com/blog/2009/06/rfa-version-grey-commands-family-context-and-rdb-link.html#2
    Have you encountered some situations that are not described there? Then maybe you might like to add a comment describing them to that post. Thank you!
    Cheers, Jeremy.

  30. Hi jeremy,
    Does SendKeys.SendWait works on Revit2009 API?
    Cheers!

  31. Actually, the SendKeys.SendWait works with for exemple {F1} but noway with “VG” for example.
    Do you have an idea?
    Cheers!

  32. Dear Pierre,
    The approach presented above to drive Revit from outside through SendKeys.SendWait does not have anything whatsoever to do with the Revit API, so you cannot really say it works with the Revit 2009 API. It does however work perfectly well and reliably with Revit 2009, as far as I know.
    I tried to convert my SendKeys console application to work with Revit 2010 and was unfortunately unable to do so, as you can see from my reply to Moiz further up.
    The only idea that I have is that Revit 2010 is managing several different windows and sub-windows, and that we may be sending the messages to the wrong one.
    When you say it does not work to send a key sequence such as “VG”, do you mean to Revit 2009 or 2010? I was under the impression that this worked in 2009. Is “VG” a keyboard shortcut?
    Oh, and rereading this thread now in sequence, I understand that Jake was speaking to Moiz, not greeting … oops, sorry about that!
    Cheers, Jeremy.

  33. Jeremy,
    First : thx for answering.
    Yes, VG is a shortCut.
    Actually, I’d like to send a command to my revit 2009.
    I’ve you ever try to send a command?
    Cheers

  34. Dear Pierre,
    Oh, it is for 2009. I thought it worked there, but I may have never actually done it with a self-defined shortcut key. You might have a look at this AUGI thread dealing with Revit and SendKeys and entitled ‘keyboardshortcuts’:
    http://forums.augi.com/showthread.php?p=765178
    Unfortunately, that thread may be even older still, for Revit 2008.
    Cheers, Jeremy.

  35. Thx for the link.
    I’m having a look on it.
    Keep in touch.
    Cheers

  36. Can’t get my Handle with this code :
    IntPtr revitHandle = FindWindow(_window_class_name_project_open, null);
    //
    // try alternative window class if no project is open in Revit:
    //
    if (IntPtr.Zero == revitHandle)
    {
    revitHandle = FindWindow(_window_class_name_zero, null);
    }
    I use Spyy++ or WinSpector to get my const string _window_class_name_zero “Afx:00400000:8:00010011:00000000:007B05A1”;
    but, it’s not the same…..
    I used by Process[] processes = Process.GetProcessesByName(“Revit”); but only works with sendKeys {F1}…..
    mhh…problem

  37. Jeremy,
    here is my code :
    WindowHandle _hWndRevit = null;
    if (null == _hWndRevit)
    {
    Process[] processes = Process.GetProcessesByName(“Revit”);
    //if (0 < processes.Length)
    //{
    // IntPtr h = processes[0].MainWindowHandle;
    // _hWndRevit = new WindowHandle(h);
    //}
    //
    Process process
    = Process.GetCurrentProcess();
    IntPtr h = process.MainWindowHandle;
    _hWndRevit = new WindowHandle(h);
    SetForegroundWindow(h);
    //SendKeys.SendWait(cmdToSend);
    SendKeys.SendWait(” “);
    SendKeys.SendWait(“+{F1}”);
    return;
    }
    I get an Handle but nothing happens on SendWait….

  38. Sorry for pollute your section comments….
    But, I’ve tried with a NotePad window and it works…..
    Mhh….strange…

  39. Nothing to see with 64 bits, it does not work with 32 bits….

  40. Dear Pierre,
    I’m very sorry to hear you are having such trouble with this. As said, I had the SendCmd console application working as described above to drive Revit 2009, but was unable to get it to work for 2010. In some other later posts, we discussed alternative methods to determine the Revit windows handle, but I don’t know which of them would be most effective, or whether it makes any difference.
    In any case, since discovering that it is harder to send keystrokes to Revit 2010 than to 2009, I am tending more towards recommending alternative approaches. One of these is using the journal file to drive Revit, which is also not officially supported. Another approach is one I will post on today: using the API to determine a certain state that requires an action; if this action is not available through the API, but is through the UI, then simply prompt the user to execute it.
    I hope you finally resolved you problem!
    Good luck and cheers, Jeremy.

  41. Thx Jeremy,
    Have you already try to use the SenCmd to send ShortCuts commands?
    In my case, it does-not work…
    I am in vista 64 bits and Revit 64 bits….maybe, that’s the problem….I’m looking at it…
    Cheers!

  42. Some news : if I do SendKeys on my Autocad 2009 64 bits : it works…..

  43. Hi jeremy
    Is it possible to invoke a command with the ID wich is saved in the file journal?
    I mean, for exemple : here is a line :
    Jrn.Command “KeyboardShortcut” , “Agrandit tout à la taille de la fenêtre , ID_ZOOM_FIT”
    Can we do something with ID_ZOOM_FIT?
    Cheers!

  44. Dear Pierre,
    The only thing I can think of to use that command id for ‘as is’ would be to plug it in to a journal file again to drive Revit with. The problem with journal files is that they cannot be executed in the middle of a running session, as far as I know, so you have to shut down Revit, run the journal file, including starting up Revit, executing a command or two and shutting down Revit again, and then you can restart again to continue your interactive session. So it does not seem all that useful to me under ordinary circumstances.
    You might be able to use the Visual Studio Spy tool or some other Windows API debugging utility to find out what Windows message is actually represented by a given journal file id such as ID_ZOOM_FIT, and try to send that same message to Revit similarly to the way you tried to send the keyboard input. You may or may not face the same problems there as you had above, though. Did you find a solution for the keyboard shortcuts yet?
    Cheers, Jeremy.

  45. Hi Jeremy,
    It works!
    Thx to you and Chuck.
    http://discussion.autodesk.com/forums/thread.jspa?messageID=6214765&#6214765
    Now, I must integrate more commands..
    Cheers!

  46. Dear Pierre,
    Wow, congratulations, you persevered and succeeded, fantastic!
    The link you specified does not work. There is an extra character at the end. This one does:
    http://discussion.autodesk.com/forums/thread.jspa?messageID=6214765
    Oh, I see, this is still for Revit 2009?
    I wonder whether anyone has succeeded in launching an external command programmatically in Revit 2010?
    Good luck integrating the additional commands!
    Cheers, Jeremy.

  47. Thx for correcting the link Jeremy.
    Yes, still for RAC2009.
    Here, we still waiting until we updrage to RAC2010.
    Cheers and thx a lot for all.

  48. Hey Jeremy,
    thanks for the article. Do you think I could use this method to relead the keynotes file given the fact that it can only be done throug the ui and doesn’t appear to be able to be released throgh the API? Thanks adam

  49. Dear Adam,
    Sure sounds like it to me. It might be easiest to try it out with a journal file or some Windows keyboard simulator first, though. You might have a look at the other posts mentioned in the discussion on exporting an IFC file:
    http://thebuildingcoder.typepad.com/blog/2009/05/vb-samples-and-other-questions.html#1
    Good luck with your project!
    Cheers, Jeremy.

  50. Rajeswara Rao Avatar
    Rajeswara Rao

    Dear Jeremy,
    Is it possible to open the Project Information Dialog using SendKeys.SendWait(“{F10}{N}{PI}”); in Revit 2011.
    Thanks,
    Rajesh

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading