First of all, you'll need to define the logic to filter these elements.
From the images you've shared, the hierarchy tree of your model seems to be organized in a way that you're interested in the nodes in the 5th level from the root node.
So, if that's the case, you could use something like the snippet below to find the nodes' paths and then filter it to retrieve the 5th-level nodes' dbids:
var findfifthNodes = function (model) {
return new Promise(function (resolve, reject) {
model.getObjectTree(function (tree) {
let nodes = {};
tree.enumNodeChildren(tree.getRootId(), function (dbid) {
let nodepath = [dbid];
if(!!nodes[tree.getNodeParentId(dbid)]){
nodepath = nodepath.concat(nodes[tree.getNodeParentId(dbid)]);
}
nodes[dbid] = nodepath;
}, true /* recursively enumerate children's children as well */);
let fifthNodes = Object.values(nodes).filter(p => p.length == 5).map(a => a[0]);
resolve(fifthNodes);
}, reject);
});
}
You can also add your own custom tree view that might be more suitable to your workflow.
To achieve that, please refer to https://aps.autodesk.com/blog/custom-tree-views