How to Retrieve Forge Viewer objectTree?

前端 未结 2 558
梦毁少年i
梦毁少年i 2021-01-21 16:04

My goal is to highlight a room by adding new geometry to the viewer based on lines I have created in revit like they do here Link

but i can not figure out how to access

相关标签:
2条回答
  • 2021-01-21 16:51

    Shiya Luo was correct the viewer had not yet finished loading the geometry

    in my extentions Load function I added two event listeners and made sure they both fired before trying to access the instanceTree

     viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
        finishedGEOMETRY_LOADED_EVENT = true;
        if(finishedGEOMETRY_LOADED_EVENT && finishedOBJECT_TREE_CREATED_EVENT ){
            afterModelLoadEvents(viewer);
        }
     });
    viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {
        finishedOBJECT_TREE_CREATED_EVENT = true;
        if(finishedGEOMETRY_LOADED_EVENT && finishedOBJECT_TREE_CREATED_EVENT ){
            afterModelLoadEvents(viewer);           
        }
     });
    
    0 讨论(0)
  • 2021-01-21 17:03

    As of version 2.9 this is still working. Here's my console:

    Here's a couple of things you can try:

    1. Is viewer undefined? Are you in the correct scope when grabbing the viewer?
    2. The document have to be loaded before you can grab the instance tree. When the document is loaded, an event called Autodesk.Viewing.GEOMETRY_LOADED_EVENT will be fired, then you can start manipulating the instance tree.

    Simply do this:

    viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
    var instanceTree = viewer.model.getData().instanceTree;
    });
    

    For more structured code, follow this guide to add an extension.

    There's a more detailed blog post on which event to listen for. It's still using the old way to get instance tree, though.

    0 讨论(0)
提交回复
热议问题