A 3D model file can be a single file, or a composite file that links with other dependent files. The typical is Inventor assembly (with subassemblies, parts etc), AutoCAD DWG (with Xref), Revit (with linked files). Derivative API supports to translate single file or composite file.
In the past, the way to configure is using the endpoint of Set Reference. The other blog tells more. It requires the developer to configure the relationship of each child one by one. It was tedious.
With new version Derivative API endpoint, it does not need to set relationship manually anymore. The workflow is now:
- Package all files in one zip.
- Upload the zip file to bucket
- Start translation by the endpoint of Derivative
POST https://developer.api.autodesk.com/modelderivative/v2/designdata/job
In the parameters, set input.compressedUrn = true and input.rootFilename = the root file name.
The Derivative service will detect the relationship and build the hierarchy automatically.
This is a test harness.
https://github.com/xiaodongliang/Forge-Test-Harness-Node.js
And the demo Inventor, AutoCAD, Revit files are available at
https://github.com/xiaodongliang/Forge-Test-Harness-Node.js/tree/master/demo_files
The relevant codes are:
Lmv.prototype.translate =function (urn,iszip,rootfile) {
var self =this ;
//default is to export a single file to svf
var desc ={
"input": {
"urn": new Buffer (urn).toString ('base64')// urn of zip file
},
"output": {
"formats": [
{
"type": "svf",
"views": [
"3d"
]
}
]
}
};
if(iszip)
{
//if it is a composite file
desc.input['compressedUrn'] = true;
//which one is the root file
desc.input['rootFilename'] = rootfile;
}
console.log(desc);
//https://developer.api.autodesk.com/modelderivative/v2/designdata/job
unirest.post (config.endPoints.translate)
.headers ({
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': ('Bearer ' + Lmv.getToken ()),
'x-ads-force': true
})
.send (desc)
.end (function (response) {
try {
if ( response.statusCode != 200 && response.statusCode != 201 )
throw response ;
try {
self.emit ('success', { 'urn': desc.input.urn, 'response': response.body }) ;
} catch ( err ) {
}
} catch ( err ) {
self.emit ('fail', err) ;
}
})
;
return (this) ;
} ;
Comments