4  Design Automation

Need to convert a DWG to PDF without spinning up an AutoCAD licence? Design Automation is AutoDesk’s answer to cloud-based CAD scripting. You submit a work item, AutoDesk runs it on their infrastructure, and the output lands in a destination URL you specify.

This chapter focuses on the most common use case: DWG → PDF.

flowchart LR
  A[DWG file\nat source URL] --> B[makePdf\nsubmit work item]
  B --> C{checkPdf}
  C -- pending / inprogress --> C
  C -- success --> D[PDF file\nat destination URL]

4.1 Convert a DWG to PDF

makePdf() submits the conversion job. The token needs the code:all scope. This is specific to Design Automation and different from the data scopes used elsewhere.

Warning

Both source and destination must be publicly accessible URLs. Private Google Drive links, localhost paths, and short-lived signed S3 URLs won’t work. The AutoDesk cloud workers need to be able to reach them directly. Use a public host or a pre-signed URL with plenty of time left on it.

resp <- getToken(
  id     = Sys.getenv("client_id"),
  secret = Sys.getenv("client_secret"),
  scope  = "code:all"
)
myToken <- resp$content$access_token
mySource      <- "http://download.autodesk.com/us/samplefiles/acad/visualization_-_aerial.dwg"
myDestination <- "https://drive.google.com/folderview?id=0BygncDVHf60mTDZVNDltLThLNmM&usp=sharing"

resp         <- makePdf(source = mySource, destination = myDestination, token = myToken)
myWorkItemId <- resp$content$id
resp$content
#> $id
#> [1] "f47ac10b-58cc-4372-a567-0e02b2c3d479"
#>
#> $status
#> [1] "pending"
#>
#> $stats$timeQueued
#> [1] "2026-04-23T10:15:30.412Z"

4.2 Poll for Completion

Use the work item id to check status. A simple DWG typically takes 15–30 seconds; complex drawings with many layers or external references take longer.

repeat {
  resp <- checkPdf(id = myWorkItemId, token = myToken)
  cat("Status:", resp$content$status, "\n")
  if (resp$content$status == "success") break
  Sys.sleep(5)
}
#> Status: pending
#> Status: inprogress
#> Status: success

The full timing breakdown when it’s done:

resp$content
#> $id
#> [1] "f47ac10b-58cc-4372-a567-0e02b2c3d479"
#>
#> $status
#> [1] "success"
#>
#> $stats$timeQueued
#> [1] "2026-04-23T10:15:30.412Z"
#>
#> $stats$timeDownloadStarted
#> [1] "2026-04-23T10:15:31.804Z"
#>
#> $stats$timeInstructionsStarted
#> [1] "2026-04-23T10:15:34.217Z"
#>
#> $stats$timeFinished
#> [1] "2026-04-23T10:15:48.993Z"

Once status is "success", the PDF is waiting at your destination URL.

4.3 Batch Conversion

Converting a folder of DWGs is just a loop:

dwg_urls  <- c(
  "https://files.example.com/floor_plan.dwg",
  "https://files.example.com/site_plan.dwg",
  "https://files.example.com/elevations.dwg"
)
dest_base <- "https://output.example.com/pdfs/"

job_ids <- vapply(dwg_urls, function(url) {
  fname <- sub(".*/", "", url)
  resp  <- makePdf(source      = url,
                   destination = paste0(dest_base, sub("\\.dwg$", ".pdf", fname)),
                   token       = myToken)
  resp$content$id
}, character(1))

# Poll until all jobs complete
repeat {
  statuses <- vapply(job_ids, function(id) {
    checkPdf(id = id, token = myToken)$content$status
  }, character(1))
  cat(format(Sys.time(), "%H:%M:%S"), "—", paste(statuses, collapse = " | "), "\n")
  if (all(statuses == "success")) break
  Sys.sleep(10)
}
#> 10:20:05 — pending | pending | inprogress
#> 10:20:15 — success | inprogress | inprogress
#> 10:20:25 — success | success | success