Thoughts About the AutoCAD API (AutoCAD .net API)

 

Get your API working hard for you. Like worker bees.
Get your API working hard for you. Like worker bees.

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:

  1. The opening and closing and disposing of Objects.

And the main operations that come to mind are the following:

  1. Adding Items to the database.
  2. Removing Items from the database.
  3. Editing existing items from the database.
  4. Getting Items from the database.
  5. 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:

  1. Identify a resource.
  2. Operate on that resource.

We can go about this in a few ways:

  1. Using extension methods. This means that we have already identified the relevant resource and we act on it.
  2. Static Methods where then operate on those resource. (I use resource in the sense that Fielding uses it).
  • GetResource( parameters)
  • 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *