Amit Mandal
Amit Mandal

Reputation: 115

Getting undefined instance tree for DWFX file

We are trying to get all node elements of DWFX file but we are getting undefined instance tree for DWFX file. We have used below code to get each element id.

// Try to get instance tree for DWFX file
    var model = this.viewer.model;
    var modelData = model.getData();
    var it = modelData.instanceTree;  // get instance tree


    We have used another way to get element node id for DWFX file. (In that case, we are getting only panel label id for DWFX file) But that logic is not working for all DWFX files.

// Try to get all ids for DWFX file
    var model = this.viewer.model;
    var modelData = model.getData();
    var allIds = modelData.stringDbIds;  // get all ids 


    Please us know If I am using wrong approach to get all elements for DWFX file.

Upvotes: 1

Views: 297

Answers (1)

Felipe
Felipe

Reputation: 4375

You need to wait for Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT event to make sure the instanceTree is available in your loaded model:

viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {
    var model = this.viewer.model;
    var modelData = model.getData();
    var it = modelData.instanceTree;  
    console.log(it)
})

In some cases you may have to wait also for Autodesk.Viewing.GEOMETRY_LOADED_EVENT event if you intend to access geometry of the components. Here is an article that may be relevant: Asynchronous viewer events notification

Upvotes: 1

Related Questions