April 11, 2012
By: Andrew G. Roe
VBA remains an option, but its days seem numbered. Check out the other choices available for customizing AutoCAD.
AutoCAD’s open architecture has long been one of its most attractive qualities. The freedom to customize menus, add custom commands, and develop add-on programs that run in AutoCAD has motivated many users to go under the hood and make a few tweaks.
With AutoCAD 2013 now on the streets, AutoCAD’s programming options remain robust, although the landscape continues to evolve. Autodesk has indicated for several years that Visual Basic for Applications (VBA), a programming environment introduced in the late 1990s, will eventually be discontinued. VBA still has a pulse at the moment, but it appears to be on life support as Autodesk promotes Visual Studio.NET as the preferred development platform instead.
The .NET environment – which is more versatile and complex than VBA – has grown in popularity in recent years, but has left some less experienced programmers out in the cold. Meanwhile, the growth of mobile devices and cloud computing has introduced new considerations for CAD users and programmers. To better understand this changing landscape, let’s take a look at various customization options, starting with the simpler methods and working your way up to more complex alternatives.
First of all, AutoCAD offers a lot of customization options for non-programmers. Custom menus and commands have been possible since the early days, before AutoCAD versions were labeled by year. Using the AutoCAD Ribbon Customization Tools, as well as working behind the scenes, you can customize the user interface, define external commands that call other programs from the AutoCAD command prompt, create aliases for AutoCAD command shortcuts and create scripts to batch-process groups of commands.
AutoCAD 2009 introduced a macro recorder that lets you automate frequently repeated tasks without typing any code. On the Manage tab of the ribbon, just click the Record button to capture AutoCAD actions, the Stop button to end recording the macro, and the Play button to run the macro.
AutoCAD Action Recorder allows users to automate repetitive tasks.
Unlike Microsoft Office Macro Recorder, AutoCAD Action Recorder does not produce editable Visual Basic code, but does allow some adjustments to recorded steps and prompts the user to enter.
Introduced in AutoCAD Release 14, VBA allowed users to develop event programs within AutoCAD sessions using a convenient Integrated Development Environment (IDE).
Microsoft and Autodesk are phasing out VBA, shown here, in favor of .NET.
VBA quickly gained popularity, as even novice programmers discovered that they could write programs with graphical user interfaces (GUIs) and logical branches. Access to AutoCAD’s object model provided easy ways to create and modify entities, extract data from drawings, and adjust parameters and properties of drawings. Using ActiveX automation, programmers can also write stand-alone VB applications to drive AutoCAD and exchange information with other VBA-compatible products such as Microsoft Word, Excel, and Access.
VBA remained a popular development platform for several years, but Microsoft stopped distributing VBA licenses in 2007, favoring its .NET framework for flexibility in development, deployment, and web services.
Autodesk removed VBA from the standard AutoCAD interface in AutoCAD 2010, but continued to unofficially support VBA with a downloadable VBA activator for the 2010-2013 versions. The plug-in has allowed many developers to continue using VBA routines, albeit with some difficulty: because VBA is a 32-bit application, it runs as a separate 32-bit process on 64-bit AutoCAD, which results in slow behavior and even crash of VBA routines. The days of VBA are clearly numbered for AutoCAD users.
Visual Studio .NET and VSTA
Much to the chagrin of some VBA fans, the future of AutoCAD programming lies in Visual Studio.NET, a true object-oriented programming environment that allows development in multiple languages, including VB and C #. â.NET is more of a programmer’s programming environment,â said Stephen Preston, senior director for the Americas of developer technical services at Autodesk.
With the extra power comes a steeper learning curve. Instead of working in AutoCAD’s VBA environment, applications are developed externally in the .NET environment. Additional programming knowledge is required to manage system settings, references, and other resources. But once the basics are mastered, the potential for developing professional applications is greater. âWe encourage people to take the plunge,â said Kean Walmsley, software architect for Autodesk’s AutoCAD product line. The complete Visual Studio.NET product is a separate purchase costing several hundred dollars, but Microsoft’s Visual Basic Express can be downloaded for free and provides much of the same functionality that AutoCAD programmers need.
Several years ago, Microsoft also introduced an in-vehicle version of Visual Studio called Visual Studio for Applications (VSTA), but it appears to have a limited future. Initially intended to replace VBA, VSTA never really gained momentum and Microsoft is pretty tight-lipped about its future. Autodesk has integrated VSTA into recent versions of Revit, but removed it from the 2013 version.
Based on the LISP language developed in the 1950s, AutoLISP has been a favorite among AutoCAD programmers since the mid-1980s. With somewhat cryptic syntax relying heavily on parentheses, AutoLISP may initially confuse novice programmers, but Proponents claim that it offers easier interaction with AutoCAD than with VBA or .NET. You can type an AutoLISP statement in the AutoCAD command line and see the results directly. To make AutoLISP easier to use, Autodesk introduced Visual LISP (VLISP) in R14, with an IDE similar to VBA, as well as a compiler, debugger, and other tools.
Visual LISP is easier to use than AutoLISP and has an integrated development environment similar to VBA.
For advanced programmers, ObjectARX (AutoCAD Runtime Extension) provides a compiled language environment that allows you to load and run projects in the same address space as AutoCAD. This allows programs to run more efficiently. ObjectARX is typically used by third-party developers creating commercial AutoCAD add-ons and requires knowledge of C / C ++ programming languages. In other words, it is not for beginners.
Mobile and cloud options
The growth of mobile computing and the cloud is adding a new twist to AutoCAD programming. With products like AutoCAD WS allowing users to access drawings with mobile devices, programmers are keen to develop custom applications that enhance this process. Autodesk introduced APIs (Application Programming Interfaces) that allow users to connect external storage services that support WebDAV (Web Distributed Authoring and Versioning), an extension of the Hypertext Transfer Protocol for exchanging data with web servers.
More APIs are in development, so stay tuned. Preston advises potential mobile programmers to learn C # because it is more like languages ââused for mobile platforms, such as Java for Android devices and Objective-C for Apple’s iOS.
Which direction to take?
With all of these options available, a common question is: what programming approach should I take? It seems inevitable that Autodesk will end up unplugging VBA, so only go that route if you are maintaining older apps. Even so, you might want to start migrating VBA routines to .NET. AutoLISP, once considered dying art, looks to have a place in the AutoCAD arena in the near future, thanks to the convenience of the VLISP IDE and a dedicated user base. If you are familiar with AutoLISP, you can stick to the current routines, but think twice before starting any major new development.
In most cases, the .NET environment seems to offer the most potential for new applications. See the AutoCAD .NET Developer’s Guide or AutoCAD’s online help resources to get started. In the next part of this series, we’ll explore some programming examples to help you familiarize yourself with the different options.