Search code examples
javascriptautodesk-forgeautodesk-viewerautodesk-model-derivative

How to get Model object metadata properties in Javascript AutoDesk


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.


Solution

  • 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