Search code examples
autodesk-forgeautodesk-viewer

Updating view with setViewCube in v7


How do i update the view using setViewCube in v7? I was using the following code in v6, but it doesn't work in v7.

viewer.setViewCube('[top/front]');

In the migration guide v6 to v7 it says, I should call it through the extension:

extension.setViewCube(display);

How do I get the extension object from where to call it from?


Solution

  • As the migration document mentions: The ViewCube apis have been moved out of Viewer3D instance and into the Autodesk.ViewCubeUi extension. So you will need to get the extension by

    viewcuiext = viewer.getExtension('Autodesk.ViewCubeUi')
    viewcuiext.setViewCube(display);
    

    this assumes the extension has been loaded, otherwise, call

       viewer.loadExtension('Autodesk.ViewCubeUi')
              .then(res=>console.log('the extension has been loaded: ' + res))
    

    loadExtension is a promise call, so ensure it has been loaded successfully.

    Please let us know if there is any question.