Last week David Falck, over at the Autodesk Labs team, provided me with an API key to have a play with the API to Project Draw. This post documents what I did, and how it all worked.
Note: I'm not actually doing any coding whatsoever in this post: I used the handy API test page provided by the Autodesk Labs team, and so didn't need to write a single line of code.
So, first of all, you'll need an API key. Here's the one I got from the Draw team:
th1SIsnOTreAlLyMyapIkeyOfCourSE
Just kidding. I've changed the above key for the purpose of this post: if you want a key, get your own. :-P
Seriously, though: just email [email protected], and they will generate and send you your very own key.
OK, once you have a key, you can navigate to the test page and start playing around. I started by copying my key (the real one, of course) into the startSession test rig, and I then hit Initiate:
The Project Draw API is exposed via REST, as opposed to SOAP (another popular - if more heavyweight, from a client perspective - mechanism for exposing Web Services), which means you pass everything the service needs to identify the session etc., in each call made to Project Draw. So you will need to use your API key along with the session ID provided in the response received for the API call we just made for each further use of the Project Draw API.
The other way to start a Project Draw session is via the setXML web method, but we'll come to that later. For now we don't have any XML to provide, so we're going to open the blank session and create some geometry from scratch.
Copy the URL provided in the response to your clipboard and paste it into a new browser window. You should get a nice, new Project Draw page upon which to draw some geometry:
I drew some simple geometry using the Project Draw interface and saved it using File -> Save. This is an important step: if you don't save to the server, then clearly any calls to access the session's geometry via the Web Service will not retrieve anything very interesting.
Here's my model - please note that I just threw some filled objects onto the canvas, and had no intention of drawing a symbol with religious or nationalistic overtones (there's something vaguely masonic about the image, I have to admit, but it's nothing I drew consciously, honestly... which should be obvious from the colours I used, if nothing else :-)
Once we've saved our geometry, we can head back to the API test page and see what we can do with it.
Firstly, we can retrieve the XML representation of this geometry, by calling the getXML web method:
You can copy & paste the returned XML fragment into a text file, if you wish. The XML returned for my feeble artistic efforts can be accessed here.
Secondly, we can retrieve a rasterized view of our design, in PNG format:
This provides us with a nice, high-quality raster of our design:
Now that we've extracted our XML content and generated a pretty image from it, we can (and indeed must) delete the session:
Now that we have some XML content - which we could have generated/transformed/manipulated programmatically in some way - we can use it to create a new session, via the setXML web method:
That's it for today's quick tour of the Project Draw API. As you should be able to see from this procedure - and from the XML representation of the design I created - it's altogether possible to populate and manipulate content in the Project Draw service programmatically, and - as the API is simply HTTP - you're able to do so from the programming language of your choice (something we did not touch on at all today).
A final, quick note: if there's something more you'd like to see exposed in the Project Draw API, don't be shy - let us know. The Autodesk Labs team is really keen to get external feedback on this technology.