We first introduced a JavaScript API into AutoCAD as a “preview” in the 2014 release. Take a look at this post for more details on this implementation. In the 2015 release the API has matured in a number of key ways, making it really ready for primetime usage.
Firstly it’s been made much more robust: rather than having a single instance of the browser executable hosting the various bits of JavaScript code running inside AutoCAD, we now use separate instances of the browser – which in turn hosts the Chromium Embedded Framework (CEF) – for each application. Which means that if one gets brought down, for whatever reason, you don’t need to reboot AutoCAD for Design Feed (for instance) to start working again. This kind of process isolation is important but complimented by a fair amount of stability-related work in the JavaScript API, making it much less likely you’ll get a browser crash in the first place.
It’s also much easier to debug JavaScript in AutoCAD 2015. Rather than having to enable debugging using a Registry key, you can now bring up the Developer Tools window from any HTML-defined palette or dialog inside AutoCAD by pressing the F12 key. Here’s what you see when you hit F12 in the New Tab page, for instance:
Before looking at the enhancements at an API level, let’s look at some links.
Firstly, the URL for the AutoCAD 2015 JavaScript API is: http://app.autocad360.com/jsapi/v2/Autodesk.AutoCAD.js
That’s the reference you’ll need to add in a <script> element in your HTML page.
If using XML to transfer data to AutoCAD via the API – such as when using transient graphics – you’ll probably want to take a look at the XML schema for this data.
Otherwise, in terms of documentation, here’s the landing page for the JavaScript API documentation and a handy Getting Started guide.
Now for a quick look at the various API enhancements.
As considerable work was done in the core of AutoCAD during this release as part of the fiber removal project, we also needed to update the JavaScript API. You are now able to call Acad.Editor.executeCommand() and executeCommandAsync() from JavaScript. The editor also provides a doEvents() function in case you need to process events (typically to repaint the screen) after calling commands synchronously from your JavaScript code.
This version of the API also includes access to information via the Bindable Object Layer (BOL). You can access information that’s provided via the BOL – such as layers, linetypes, hatch patterns, etc. – using Acad.DataItemCollectionManager.getKnownCollection(). You can also use the manager object to get notified when a collection has items added, removed or changed.
As well as accessing data via the BOL, it’s now possible to get read-only access to AutoCAD properties via JavaScript. I’ll have to look into creating a modeless, HTML property palette, at some point, to better understand the capabilities of this particular mechanism.
That’s it for today’s brief look at the updated JavaScript API in AutoCAD 2015. I’m looking forward to playing with this some more – it feels like the API is coming of age, in this release, with the future promise of bringing the ability to have apps that work in both AutoCAD and AutoCAD 360 (we’re not there yet, though, in case you were wondering about that side of things).
Tomorrow I’ll be heading off to the UK on vacation, visiting friends and family until the Easter weekend. I’ll try to queue up a blog post or two to keep things moving, but please don’t expect a response to any comments or emails for the next 10 days or so.