I use viewer.getObjectTree = function(onSuccessCallback, onErrorCallback)
to get the model object tree, then traverse from the root node down to all leaf nodes. Here is the code:
viewer.getObjectTree(function (objTree) {
objTree.enumNodeChildren(
objTree.getRootId(),
function (dbId) {
// Work with dbId
},
true
);
};
However, it works only for 3D model. 2D model does not jump into the callback events. How can I get all object Ids of a 2D layout/drawing?
I found the reason. 2D layout/drawing does not have its model object tree (just layers). It uses different data structure with 3D model. 3D uses an instance tree to get all nodes, but 2D uses a string of DbIds.
To navigate objects in 3D model, use
viewer.getObjectTree
andviewer.model.getData().instanceTree
.To navigate objects in 2D layout, use
viewer.model.getData()
. I can get a list of DbIds fromviewer.model.getData().stringDbIds