Posts tagged API
Well, kinda. It uses a webInterface which is basically a .net wrapper for Internet Explorer. This bit of code was made by joseguia over at RevitForum.org and I am eternally thankful for it! Here’s a quick tutorial on how to set it up. The advantage of this is that it is actually a Revit window, so it is one step closer to actually working instead of having Internet Explorer open (although technically you still have IE open by running this macro).
- In Revit, go to the Manage Ribbon > Macro Panel > Manage Macros
- Click Application tab at the top. This ensures you have the Macro anytime you open Revit.
- On the right of the Macro Manager, under Create, click Module.
- Name this new module appropriately, I named it RevitChat, and choose VB.NET for the language. Give it a good description like a responsible programmer.
- You could just edit this and call it a day, but I’ll have another tutorial later this week for another chat room that you can do the same thing with! So instead, select the Module you just created and then choose Create > Macro on the right. This time you are creating one little program for our Module.
- Name this something like the following, and be sure you have “Macro In:” set to the module you just created.
- Clicking OK will launch the VSTA interface. DON’T PANIC! It gets easier from here.
- Add a Window Form. (Project > Windows Form)
- Name it frmRevitTotDChat, click Add.
- From the Toolbox on the left, add a Toolbox > All Windows Forms > Web Browser. (If the toolbox isn’t showing, click View > Toolbox) Do this by simply dragging the Web Browser into the form you just made. You know it has added if you see a scroll bar in your form now and a white background instead of a grey background.
- Double click the Title bar that says “frmRevitTotDChat” and the code view will open. Make you code look like this:
Public Class frmRevitTotDChat
Private Sub frmRevitTotDChat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Go to the ThisApplication.vb tab and find the line that start with “Public Sub RevitTotDChat()” and make it look like this:
Public Sub RevitChat()
Dim myFrm As New frmRevitChat
- Run the Macro, Hit Stop, Close VSTA.
- Double click your new macro. See you in chat!
Now, there are a couple of issues with this. Any command key (ie: shift, tab, delete, etc) that you have set up as a Shortcut Key will not work in the text input but instead will try to start the revit command it is tied to. This includes Ctrl+C and Ctrl+V for copy pasting, but you can still use right click copy/paste method. Enjoy!
Yes, I have begun my venture into the world of Revit API programming, so you’ll probably start to see a few TotDs that deal with working with the Revit API. Today’s is one for those of you that are cheap (or unemployed like myself) and want to use the free Visual Studio Express edition as your code authoring environment but still want to do live debugging.
The issue here is that Miscrosoft lovingly excluded the StartAction option in the debugging properties for your project. Well, fortunately, they also made it possible to include a StartAction for those of us that know a little something about Google searches and XML 🙂
Including Revit as a Debug Application for debugging in Visual Studio Express:
- Notice that there is no StartAction option in the debugging tab in Visual Studio Express.
- Close Visual Studio Express
- Open the .csproj.user (or vbproj.user) file in Notepad.
- Add the lines (shown below) needed so that your final file looks like this:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<StartProgram>C:\Program Files\Autodesk Revit Architecture 2010\Program\Revit.exe</StartProgram>
- Save the user settings file, reopen your project and debug. Revit should now open for debugging!
I know, I kinda blind sided you guys with this one. But it is pertinent to Revit, maybe just not to you! Thanks again for stopping by, have a great day and I will see you next time for another Revit TotD!