Thursday, February 28, 2008

Revit 2009 API: VSTA: Here Comes the Neighborhood

Historical Commentary (skip unless you're bored!)


It's strange to see, looking back, how the API grows in tandem with each product.


In the AutoCAD world, there was LISP pretty darn close to the beginning (I wasn't there - so I can't rattle off the exact version number it appeared like some of my compatriots can). And look AutoCAD now - there's LISP, VBA, ARX and AutoCAD.NET (and that's an over simplification as well as leaving out some of the more obscure APIs).


In Autodesk Inventor, the API (C++ and COM/VBA) came out around Inventor 5.0 (roughly?) - and has gone from under-powered to very powerful (dropping the C++ support along the way).


Revit went from no API to a Microsoft.NET API... A sort of "walled-garden" which somehow still seemed to exclude the masses of people who might be interested in automation.



Changes Ahead?


Well - all that is about it change - sort of. Revit 2009 introduces Microsoft VSTA - that's Visual Studio Tools for Applications - the next generation follow-on to VBA (Visual Basic for Applications).




Autodesk talks a lot about "democratizing technology" - and nothing has democratized programming like VBA (and LISP). It really enabled technically savvy people to experiment with programming in a friendly environment, which was tightly tied to the CAD system. VSTA should do the same thing - although it's got its differences.


But weren't there already free ways to...?


For a while, there was a price obstacle - if you wanted to develop for Revit, most people thought you needed to fork out $800-$1200 USD for Microsoft Visual Studio. While there were technically other low-cost options, it was a conceptual barrier as much as anything.


In 2005, Microsoft introduced the free "Express Edition" of Visual Studio, which enabled users to develop software without the upfront costs (with some limitations - like limited or no ability to debug things at runtime - an invaluable capability).


I would still argue, however, that there were significant hurdles there - whether it was getting Visual Studio loaded, or the arcane way that Revit external applications are included into Revit via a REVIT.INI file. VSTA will remove many of the logistical obstacles.


It's Like VBA!


VSTA (once installed - it's one of the "Additional Products" available on the Revit DVD) - enables you to write and run "Macros". You develop inside of the VSTA IDE (Integrated Development Environment) - a nice, light version of Visual Studio which provides Intellisense (where you just need to type the first letter or two and it offers you all the choices for what you were trying to do). Like VBA, you're able to step through or set breakpoints in your projects to debug them.


Also like VBA, the macros can be stored either externally or within a document. The document approach lets the code travel with your Revit model! There are some neat things that you can do with that (so long as you're not worried about your code getting away from you).




It's Not Like VBA!



Here's where things get different...


The language is not exactly like Visual Basic / VBA. You write your macros using your choice of either Visual Basic.NET or C# (pronounced C-Sharp).


While Visual Basic.NET is incrementally more challenging than VBA - the good news is that there are many books, courses, and online content to help you. The great part about including C# as well is that there is also a wealth of online content (as well as Revit SDK samples) in C# - and these samples can typically be pasted in with only minor modifications - so VSTA is not a "second-class citizen" as VBA sometimes was.


The Content is the Same...


One key thing to understand - it's all the same Revit API. With only minor differences, the API that is available in VSTA is exactly what is available to traditional Microsoft.NET developers for Revit applications - so there's very little holding you back.


Here Comes the Neighborhood


When anything gets "democratized" like this - there's an occasional sense of unease amongst the previous members of the exclusive club - that it's not quite as special now that everyone can do it. I personally am fighting this off - on the theory that this will accelerate the Revit API development going forward. The more users who are interested and aware of what the Revit API can do, the more attention Autodesk will pay to extending their capabilities.


Where to Get Started?


There are several areas to learn about to begin your quest:


- VSTA itself


- Visual Basic.NET or C# Language


- Revit API development (general)


VSTA - there have been some AU sessions on VSTA in the past, which you can access at AU Online if you attended those AUs. You can also visit the Microsoft VSTA developer center (although take note that Revit 2009 ships with VSTA 1.0 (which corresponds to Visual Studio 2005) - Microsoft is currently touting the forthcoming VSTA 2.0 / Visual Studio 2008).


Visual Basic.NET - There are probably hundreds of books and tens of thousands of online articles and other content... You have to pick what works for you.


Revit API development - You can download the Revit SDK from here. (although the 2009 link is not posted as of this writing). This will include samples (both traditional, as well as some VSTA). Finally, Autodesk Developer Network has published one of its DeveloperTV episodes on the same site to give you a brief overview of Revit development.


Online/In-Person classes - Avatech Solutions (who I work for) is considering providing online and in-person classes for people who want to learn to program Revit using VSTA. If you're interested in something like this, contact us at ( devfeedback (at) avat.com ).


In closing


To all you VBA developers or otherwise talented tinkerers - welcome to the world of Revit development!


-Matt







11 comments:

Jon Stamps said...

Thank you!
I haven't done any programming for years, and I couldn't find where to start looking at VSTA. You've pointed me in the right direction.

Unknown said...

Thank you Matt for the great update! any news as to when the 2009 SDK will be available?

Unknown said...

Thank you Matt for the great update! any news as to when the 2009 SDK will be available?

Matt Mason said...

Iffat,

Aren't you an ADN member?
It's available today on ADN (the beta version, of course).

-Matt

Rod said...

Good news for the masses, though I dare say that there are going to be alot of scratching heads from VBA macro writers, C#/VB.Net is a big step forward, you have to forget alot that you thought you new about programming... she's Object Orientated now ;)

Hopefully this will see the functionality in the API increase exponentially, particularly in the 'macro' sense, where the ideal is to make things quicker and easier, ie shortcuts in menus, things like that, whereas at the moment the API seems more aimed at extending revits functionality, not making it easier to use.. (though its possible to do both)

Jose Guia said...

Does anyone know if this makes AutoDesk the first to use VSTA outside of the Microsoft realm?

JoseG
Youv'e been KICKED - a good thing.

Anonymous said...

Good news for potentially expanding the functionality and ease of use in the API.

Revit Add-ins and Apps said...

Regarding the Q about Revit being the first to use VSTA. The answer is Yes and No. It is the first in its space (design software) but there are a few other products that are niche products that have used it in the manufacturing automation and data analysis space. To the best of my knowledge there are still less than 10 shrink wrapped products using it at this point though.

Revit Add-ins and Apps said...

Regarding the Q about Revit being the first to use VSTA. The answer is Yes and No. It is the first in its space (design software) but there are a few other products that are niche products that have used it in the manufacturing automation and data analysis space. To the best of my knowledge there are still less than 10 shrink wrapped products using it at this point though.

Unknown said...

I just have downloaded the trial version of Revit Struct. 2009 . When I tried to start Macro Manager screen, it did not appear . Rather the sub menus grayed out . What may be the reason ? When I restart Revit , it becomes active but again become grayed out when I tried as earlier.

Is it because I am using the trial version ?

Matt Mason said...

subir,
Did you install the VSTA component? During the setup program you install it separately under "Utilities" (or whatever the last option is on the first page- it's not part of the Revit product installation).

-Matt