Thoughts About the AutoCAD API (AutoCAD .net API)
(Get your API working for you. Let it work hard like a bee, While you sit back and relax. There’s no need for you to get involved in the nitty gritty).
I got thinking about the AutoCAD APIs (ObjectARX/.NET) – they’re virtually the same – the .NET API is basically a wrapper to the ObjectARX API (with some differences). If you want the full power of low level calls then you gotta go with ObjectARX. But then using .NET comes with a very powerful benefit – a host of libraries and code readily available to utilize. If you’re talking UI then WPF is waiting for you if you go down the .NET path, but not so with ObjectARX.
Anyways, when you think about the API there are a few issues that you gotta manage:
- The opening and closing and disposing of Objects.
And the main operations that come to mind are the following:
-
Adding Items to the database.
-
Removing Items from the database.
-
Editing existing items from the database.
-
Getting Items from the database.
-
If this happens do that (Events) which ties into all of the above.
Is it just me or does smack of a RESTful API? Well not quite, because we can store state in variables, both within the drawing, and in variables within our classes (temporary).
These are the steps:
-
Identify a resource.
-
Operate on that resource.
We can go about this in a few ways:
- Using extension methods. This means that we have already identified the relevant resource and we act on it.
- Static Methods where then operate on those resource. (I use resource in the sense that Fielding uses it).
-
Resource.GetResource( parameters)
-
Resource.Action(parameters)
We shouldn’t have to worry about all the lower level stuff.
Perhaps a better wrapping API can be written incorporating this. I know Mr Wolfgang Tertinek has wrote about it extensively in his blog. It’s a good approach, but perhaps common tasks e.g. changing a layer of an object can be incorporated in this model. Ideally this should be written simply with core level logic without direct use of a particular dll.
- .e.g something like this: SelectionFilter.Create(layer: “test”, types: [BlockReference, Mtext]) – without going into the specifics of setting type filters etc. A DSL much like Active Record for handling these types of queries.