1

I am working with AutoDesk Forge Viewer (2D) in Javascript with Offline svf file. I have converted the .dwg file to svf file.

How can I get Model Object Metadata properties in Javascript like we get using the api "https://developer.api.autodesk.com/modelderivative/v2/designdata/{urn}/metadata/{guid}/properties" ?

I tried using viewer.model.getProperties(dbId,function,funtion), but this only gives me details of particular to that dbId but i want the list of properties.

Please help me with this.

Gaurav
  • 122
  • 1
  • 2
  • 11

1 Answers1

4

firstly, the other blog talks about how Model Derivative extracts properties. In theory, if you get 'aka json (json.gz)' or 'sqlLite (sdb/db)', you would be able to extract yourself by other tools. How properties.db is used in Forge Viewer?.

I believe you have known http://extract.autodesk.io/ as you said you have downloaded SVF. http://extract.autodesk.io/ provides you with the logic to download translated data, including json.gz and sqlLite db.

While if you prefer to dump all properties within browser by Forge Viewer, the only way I can think is as below:

 function getAllDbIds(viewer) {
   var instanceTree = viewer.model.getData().instanceTree;

   var allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex);

  return allDbIdsStr.map(function(id) { return parseInt(id)});
}

var AllDbIds = getAllDbIds(myViewer);
myViewer.model.getBulkProperties(AllDbIds, null,
   function(elements){
    console.log(elements);//this includes all properties of a node.
 })

Actually, I combined two blogs: https://forge.autodesk.com/cloud_and_mobile/2016/10/get-all-database-ids-in-the-model.html

https://forge.autodesk.com/blog/getbulkproperties-method

Xiaodong Liang
  • 2,051
  • 2
  • 9
  • 14
  • Thanks this helped me. One more thing wanted to ask, Is there any way in Javascript to get the hierarchical object data like we get in api "https://developer.api.autodesk.com/modelderivative/v2/designdata/{urn}/metadata/{guid}". kindly help me on this. – Gaurav Jun 08 '18 at 07:38
  • @Gaurav, InstanceTree of the model contains method to enumerate the tree. This a blog for your reference: https://forge.autodesk.com/blog/enumerating-leaf-nodes-viewer – Xiaodong Liang Jun 11 '18 at 02:49