August 2014

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            








« Turtle fractals in AutoCAD using .NET - Part 3 | Main | Conditional selection of AutoCAD entities using .NET »

June 30, 2008

Getting to know the Project Draw API

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 labs.draw@autodesk.com, 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:

Project Draw API - startSession

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:

Project Draw - new session

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 :-)

Project Draw - session with geometry

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:

Project Draw API - getXML

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:

Project Draw API - getRaster

This provides us with a nice, high-quality raster of our design:

Project Draw - rasterized geometry

Now that we've extracted our XML content and generated a pretty image from it, we can (and indeed must) delete the session:

Project Draw API - deleteSession

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:

Project Draw - setXML

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.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83452464869e200e5538553158834

Listed below are links to weblogs that reference Getting to know the Project Draw API:

» Through the Interfacce: Getting to know the Project Draw API from It is Alive in the Lab
Our old pal, Senior Manager of Worldwide DevTech, Kean Walmsley, has an article about Project Draw on his Through the Interface blog: Getting to know the Project Draw API Recall that Project Draw 0.7.5 featured a new API call to [Read More]

blog comments powered by Disqus

Feed/Share

10 Random Posts