Convert a DWG to a PDF Files

In this tutorial, you will create a WorkItem to call a pre-existing PlotToPDF
Activity, which plots a DWG file to PDF. Autodesk 360 Cloud serves the source DWG file, and the resulting PDF is stored in a publicly accessible Google Drive folder.
Before You Begin
- If you don’t already have one, make sure to register an app. (See the Create an App tutorial for more explicit guidance.)
- Acquire a 2-Legged OAuth token using the POST authenticate OAuth endpoint. (See the Get a 2-Legged Token tutorial for more explicit guidance.)
- Get the direct download URL of your object from your cloud storage provider (e.g., Autodesk 360 Cloud, Amazon S3, Azure Blob, Dropbox).
- Get an access token from your cloud storage provider to enable you to upload the PDF. This tutorial will use Google Drive:
- Browse to Google Playground.
- From the Select and Authorize API box, select Drive API V3 > googleapis.com/auth/drive, googleapis.com/auth/drive.file, and googleapis.com/auth/drive.metadata, and click Authorize APIs.
- Select a Google account, if necessary. You are redirected to a consent screen with an Authorization code.
- Click Exchange authorization code for tokens. Note the access token.
- Configure the request for the API call:
- HTTP Method:
POST
- Header name:
Authorization
- Header value:
Bearer <access token>
- Request URI:
https://www.googleapis.com/drive/v3/files
- Enter body request:
{"name":"result","mimeType":"application/pdf"}
- HTTP Method:
- Click Send the request, and note the id in the response.
Step 1: Create a WorkItem
The WorkItem is where the source and destination are specified for the input and output files, respectively, and it references the desired Activity to be executed.
Use the POST WorkItems endpoint to create the WorkItem.
In OutputArgument
replace id
and access_token
with the id and access token generated from Google OAuth.
Request
When you run this code, replace the Authorization
header token value with your access token.
curl -v 'https://developer.api.autodesk.com/autocad.io/us-east/v2/WorkItems'
-X 'POST'
-H 'Content-Type: application/json'
-H 'Authorization: Bearer Js43z2DJnsYuaAxI4R2iT84b3UPy'
-d '
{
"Arguments":{
"InputArguments":[
{
"Resource": "http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_imperial.dwg",
"Name": "HostDwg"
}
],
"OutputArguments":[
{
"Name": "Result",
"HttpVerb": "PUT",
"Resource": "https://www.googleapis.com/upload/drive/v2/files/<id>?uploadType=media",
"StorageProvider": "Generic",
"Headers":[
{
"Name":"Authorization",
"Value":"Bearer <access_token>"
}
]
}
]
},
"ActivityId": "PlotToPDF",
"Id": ""
}'
Note that line breaks have been added to the cURL command above for ease of reading. Make sure to remove them before executing any code in your terminal.
Response
The JSON payload in the response body will look something like this:
{
"@odata.context": "https://developer.api.autodesk.com/autocad.io/us-east/v2/$metadata#WorkItems/$entity",
"ActivityId": "PlotToPDF",
"Arguments": {
"InputArguments": [
{
"Resource": "http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_imperial.dwg",
"Name": "HostDwg",
"Headers": [],
"ResourceKind": null,
"StorageProvider": "Generic",
"HttpVerb": null
}
],
"OutputArguments": [
{
"Resource": "https://www.googleapis.com/upload/drive/v2/files/0B_ip8nvTgiUBNE14Z2g4VDJOeFk?uploadType=media",
"Name": "Result",
"Headers": [
{
"Name": "Authorization",
"Value": "Bearer ya29.GluxBKHE-UbAkXzdAxYA6mREylPGuEhBAKY8UZe5RhgCU-kkC5XU73z9QJTy2hjBqzNpl3vi5RgVLa0pqotjkXuHrn7fLy7ps2m2QUpNA9TypeyzoNthQYwoHUv0"
}
],
"ResourceKind": null,
"StorageProvider": "Generic",
"HttpVerb": "PUT"
}
]
},
"Status": "Pending",
"StatusDetails": {
"Report": null
},
"AvailabilityZone": null,
"TimeQueued": "2016-05-13T06:43:56.8384021Z",
"TimeInputTransferStarted": null,
"TimeScriptStarted": null,
"TimeScriptEnded": null,
"TimeOutputTransferEnded": null,
"BytesTranferredIn": null,
"BytesTranferredOut": null,
"Timestamp": "0001-01-01T00:00:00Z",
"Id": "7bb3f2f795784017bc2c76d73fc25e62"
}
Step 2: Poll for WorkItem Completion
The current status of a single WorkItem can be queried with the GET WorkItems(‘:id’) endpoint. It is also possible to check the status of all WorkItems with the GET WorkItems endpoint.
Request
When you run this code, replace the Authorization
header token value with your access token.
curl -v 'https://developer.api.autodesk.com/autocad.io/us-east/v2/WorkItems'
-X GET
-H 'Content-Type: application/json'
-H 'Authorization: Bearer 7bb3f2f795784017bc2c76d73fc25e62'
-d '
{
"Arguments": {
"InputArguments": [
{
"Resource": "http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_imperial.dwg",
"Name": "HostDwg"
}
],
"OutputArguments": [
{
"Name": "Result",
"HttpVerb": "PUT",
"Resource": "https://www.googleapis.com/upload/drive/v2/files/0B_ip8nvTgiUBNE14Z2g4VDJOeFk?uploadType=media",
"StorageProvider": "Generic",
"Headers": [
{
"Name": "Authorization",
"Value": "Bearer ya29.GluxBKHE-UbAkXzdAxYA6mREylPGuEhBAKY8UZe5RhgCUkkC5XU73z9QJTy2hj"
}
]
}
]
},
"ActivityId": "PlotToPDF",
"Id": ""
}'
Response
The JSON payload in the response body will look something like this:
{
"@odata.context": "https://developer.api.autodesk.com/autocad.io/us-east/v2/$metadata#WorkItems/$entity",
"ActivityId": "PlotToPDF",
"Arguments": {
"InputArguments": [
{
"Resource": "http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_imperial.dwg",
"Name": "HostDwg",
"Headers": [],
"ResourceKind": null,
"StorageProvider": "Generic",
"HttpVerb": null
}
],
"OutputArguments": [
{
"Resource": "https://www.googleapis.com/upload/drive/v2/files/0B_ip8nvTgiUBNWRBTUYwXzIwLXc?uploadType=media",
"Name": "Result",
"Headers": [
{
"Name": "Authorization",
"Value": "Bearer ya29.GluvBLwsA-WJtCMRu470FHbpg1cP533BLgkTyi89p6KPlTULjmPfksmEjnU9yMZYZFIwCwQZiH_WkKYi-MgQcQPSNR_UpOP95pujMzv5kVo1OXZOyFEOPbAma9fc"
}
],
"ResourceKind": null,
"StorageProvider": "Generic",
"HttpVerb": "PUT"
}
]
},
"Status": "Succeeded",
"StatusDetails": {
"Report": null
},
"AvailabilityZone": null,
"TimeQueued": "2016-06-13T06:43:56.8384021Z",
"TimeInputTransferStarted": null,
"TimeScriptStarted": null,
"TimeScriptEnded": null,
"TimeOutputTransferEnded": null,
"BytesTranferredIn": null,
"BytesTranferredOut": null,
"Timestamp": "2016-06-20T18:09:52.16Z",
"Id": "7bb3f2f795784017bc2c76d73fc25e62"
}