Search code examples
autodesk-forgeautodesk

how to pass the model name in Viewer.fitToView()


We have uploaded multiple BIM models in our web application and we have used Forge Aggregate View to display the all the uploaded BIM models as a merged format. Also we have used Object ID to zoom the object in Forge Viewer. But in Forge Aggregate View we have displayed multiple files. Each file contains the same object id which is point out the different equipments. For Example: File 1 contains object id "2204" (Object name: A) file 2 contains same object id "2204" (Object name: B) I would like to zoom Object A (File 1) in Forge Viewer. So we pass the Object ID 2204 to the Forge Viewer. But the Object B (File 2) has been zoomed in Forge Viewer instead of Object A (File 1).

how to pass the model name in Viewer.fitToView() and Viewer.select() methods.

Is there any way to pass model name directly as a parameter?


Solution

  • Viewer methods like fitToView or select typically accept an additional parameter specifying the model on which the specific action should be executed. Instead of a model name, however, you need to provide an actual instance of the Model class. To obtain the reference to one of the loaded models, you can use the viewer.getVisibleModels() method (which returns Model[]), and pick the model you want to act on, for example, like so:

    const models = viewer.getVisibleModels();
    viewer.fitToView([2204], models[0]);