21 Sep 2018

Enumerate dbIds on 2D views

Default blog image

Some 2D views of documents will not have the InstanceTree, if you try to enumerate leaf nodes you will get F2D files do not have an InstanceTree error.

The alternative is to use the fragmentId to dbId mapping, the following code shows the idea for Viewer v6:

var frags = _viewer.model.getFragmentList().fragments.fragId2dbId;
frags.forEach(function(frag){
  frag.forEach(function(dbId){
    if (dbId<0) return;
    // do something with the dbId
  });
});

One interesting application is to use .setThemingColor, which requires the dbId.

Related Article

Posted By

Augusto Goncalves

Developer Advocate at Autodesk since 2008, working with both desktop and web/cloud apps using top technologies, like C#, JavaScript, NodeJS and any other that can solve problems and improve workflows. See my samples on Github and follow me on Twitter for updates.