Plannedscape Postings


AutoCAD and APIs (Part 3)
Taking A Look

Posted by Charlie Recksieck on 2020-11-05
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 2

* * *

Whether you're following along yourself in Visual Studio to look at the AutoCAD APIs yourself, or just following along to look at my screen captures and comments, we're finally at the point in this series where we're looking around.

Let's Look

Here’s what a little snapshot of Autocad code looks like (in Visual Studio, .NET)

You’ll notice right away, the convenient color coding that Visual Studio provides. Not only that, it self corrects ... take a look at this line if I have a typo:

Visual Studio Makes It Easy

If you spotted that I left out the letter "o" in DocumentManager, give yourself a cookie. I clipped out my line with blue underlining telling me where I went wrong, but also the Visual Studio real-time Error List window below it, where it tells me exactly what’s going to prevent a build or proper code.

The modern development environment really coddles us programmers these days. Which is a good thing.

A Basic AutoCAD API Reference In Code

Once we get the proper object as a reference, it guides us through a lot! Look here:

I just typed Autodesk then a period:

... then chose AutoCAD from a list:

.. the pick ApplicationService:

.. then pick DocumentManager:

.. then pick Document Manager and look at just some of the options you see in that small alphabetical section of methods, events and properties available for the DocumentManager object:

It’s really pretty phenomenal. Without knowing what I’m doing in code, Visual Studio and .NET (and the definition of the Autocad API that we’re using at that point, since we’re under Autodesk.AutoCAD.ApplicationServices), the code is guiding me to what I want to do.

Simple Ideas You Can Do

Apologies if this installment was too simplistic, but I’m trying to show you (albeit in a static document here) how easy this stuff can be.

But I just want to leave you with this. Picture absolutely any command or process that ANY Autodesk product does. Every one of those commands, or even partial processes within those commands) is something that you can do with code. We just have to find you the right APIs, bring it into your project, type the right word to find that "object" ... but after that, it’s all intuitive.

Think about this. You can customize anything you want in Autocad. Moving documents. Changing properties. Any graphical editing like insertion, editing, deleting of blocks, lines or features. Reading any value from any database on your network. Looking up any property of any file on your computer or your network. Truly anything. Dream it up and we can do it through code ... whether you take to coding yourself, or you just dream it up and pay somebody to do it for you. It’s all do-able. The first step truly is just realizing you can do it.

So, ask yourself, what do you wish you could do in Autocad that you can’t right now? Answer that question and that’s all you need to get started.