10 Jul 2017

Forge SVF Extractor in Node.js

Default blog image

Extracting SVF format to download viewer resources locally seems to be a pretty popular topic among Forge developers. Cyrille's extractor has been around for a while now: https://extract.autodesk.io

You can look up its source code at https://github.com/cyrillef/extract.autodesk.io, more specifically the part of the server code that is performing the extraction is available there: bubble.js

However when I tried to integrate that in my own application, I found it difficult to read and to decouple from some other dependencies in that project.

It took me a couple of days to work out the code below, so I hope you will find it useful: It's a clean rewrite of bubble.js in ES6, using promises and async code with no internal dependency to the project.  

Here is an example of use:

// name of model to download
const name = 'MyForgeModel'

// URN of model to download
const urn = 'dXGhsujdj .... '

// Get Forge service
const forgeSvc = ServiceManager.getService(

// getToken async function
const getToken = () => forgeSvc.get2LeggedToken()

// Get Extractor service
const extractorSvc = ServiceManager.getService(

// target path to download SVF
const dir = path.resolve(__dirname, `${name}`)

// perform download
const files = await extractorSvc.download(
  getToken, urn, dir)

// target zipfile
const zipfile = dir + '.zip'

// zip all files
await extractorSvc.createZip(
  dir, zipfile, name, files)

// remove downloaded resources directory

You can also test that live in the gallery section of my sample at https://forge-rcdb.autodesk.io/gallery.

Upload your model and hit "Download SVF"

Download SVF on the forge-rcdb Gallery


Related Article