Plannedscape Postings


AutoCAD and APIs (Part 2)
Getting You Started

Posted by Charlie Recksieck on 2020-10-29
Author's Note: This is from a series of blog posts I previously wrote for Spatial Business Systems at their request on their forums for the "Automated Utility Design" community - comprised mainly of people in the electric utility industry in IT, engineering and design departments. The program (which is a great automated tool for design at power companies) runs on AutoCAD. We here at Plannedscape and me personally have coded complex extra features and integrations for AUD and AutoCAD over the years, using APIs.

This is really for a niche audience of people who want to extend AutoCAD with custom code. If it isn’t for you, we’ll see you again on posts after November 10th.

In previous posts of "What’s An API?" (Part 1, Part 2, Part 3 and Part 4 I wrote a 4-part primer for non-programmers and new programmers about what an API is. Feel free to visit that if you're up for learning more about that. This new series of articles is more specifically targeted to people developing and implementing code using AutoCAD's APIs.

Click here to read Part 1

* * *

No software developer ever writes everything from the ground up. Every step of the way, we all work on top of what Microsoft developed as an operating system, we use what the people who wrote our programming language did, those of us reading this use public code Autodesk has written. Often times you Google an idea for a function and somebody on a web page just gives you sophisticated, relevant code that you can use. These are all APIs.

I want to slow down on this concept because it's important. Bringing in APIs to your project exponentially increases the amount of useful commands you'll be able to use in code.

Once you open up the hood in Visual Studio to create a project, learn how to bring in a product’s .DLL file (e.g. from Autocad Map or AUD) and type their "namespace" at the top of your code then you can do incredible things just by typing a relevant word, a period then make choices from Visual Studio autocompleting. You might think a "real" programmer or developer is always typing 100 words a minute in a frenzy. Not true. Once I’ve looked up the proper API and "method", from that I’m often picking the right coding word from a drop-down list. If all is going well, the mouse can be mightier than the keyboard.

Getting Started

Where are you with coding in Autocad and even AUD. Have you tried it? (If not, don’t be scared.) I’m not saying you’ll become a full-time coder or even need to. In some cases, clients that I’ve worked with just needed to become proficient enough to spot where I need to make a change for them, or to be able to follow the bouncing ball of the code to see what’s going on, maybe change a number or name of an Autocad layer name string.

Mainly I want to show you what’s possible in these APIs. And I also want to show you what’s particularly in AutoCAD’s APIs. AutoCADis an incredible product and does so much for you automatically, once configured. But what about those times where you wonder, "Wouldn’t it be nice in AutoCADif I could ..." This is the one thing I think Autodesk is a little guilty of with AutoCAD: they have given you an incredibly gift with their APIs (take note, not officially supported APIs) and not really told you much about them. Hopefully that’s something we can all discuss.

R.I.P. - VBA For Autocad

Some of you may have tinkered with or develop custom code in VBA for Autocad. I’m sure you’re aware that VBA is no longer in a default installation (read: and while it can still be installed, there is fear that it is dying out. Please feel free to discuss your VBA thoughts in the comments section here, along with anything else for that matter.

Autodesk API & Custom Code - Just Do It (Visual Studio Version)

The biggest obstacle to learning technology is fear. Well, there really is nothing to fear except for fear itself ... and messing up your system!

Let’s be clear, as long as things are backed up, you are not going to break everything. Say it slowly. Say it with me. Say it out loud. "I am not going to break everything." Whew. Seriously, let me open up the curtain and do what I think is my job here: I want to get you excited about what YOU can do as a coder. Yes, I want expectations to be reasonable, and I’m not advocating paying software companies tons of money for custom code just because it’s "cool." But you need to start getting a sense of what actually is within your power RIGHT NOW.

All I want to show you in this introduction is just a glimpse behind the curtain in Autocad APIs.

Next week, I want to show you some screen captures from Autocad development in Visual Studio. This is .NET code. Meanwhile, if you want to jump in, the next section shows you what you'll need.

Where Are Your AutoCAD DLLs?

To get an idea of where the Autocad DLLs are, and you have AutoCAD installed on your computer I suggest searching on your hard drive for a typical DLL file, like "acadres.dll" I suggest this because different install packages can put them at slightly different locations, IT departments have their own file schema or you might have intentionally put it in a non-standard location. That said, it's usually under Program Files and Autodesk.

Look at the folders and folders of DLLs there for AutoCAD. Each one of these is its own treasure trove of commands you can use.

What You'll Need: Visual Studio

You'll want to install Microsoft's "Visual Studio". If you're a programmer and don't have Visual Studio, that used to be surprising, but less so these days with convenient lightweight tools to write in R or Python and even more "low code" solutions.

But if you don't already have it, I recommend downloading Visual Studio "Community" edition (what used to be known as "Visual Studio Express"): here.

If you're still with me this far, then you're all set for us to get started in looking around AutoCAD's APIs. That's the goal. See ya next week.

Click here to read Part 3