Franjkovic Ivan
Franjkovic Ivan

Reputation: 17

How to add custom menu to Autodesk Forge Viewer?

Helo I'm using Viewer Example form here: https://forge.autodesk.com/en/docs/viewer/v5/tutorials/basic-viewer/ (Step 1) and now I need:

1. add custom menu on right click
2. get info's for clicked object, like Area, Volume, Length (if 3D) or length if 2D.

How to do that, please?

I try to copy whole "class MyContextMenu extends ... " code from https://forge.autodesk.com/blog/customize-viewer-context-menu but it does not worked.

Thank you.

Upvotes: 0

Views: 700

Answers (1)

Petr Broz
Petr Broz

Reputation: 9909

Here's a simple example of adding custom menu items to the context menu: http://jsfiddle.net/s47vy5u3/2. You'll just need to include your Forge app's access token and some viewable URN. The menu customization code itself looks like this:

function customizeMenu() {
    const viewer = NOP_VIEWER;
    viewer.registerContextMenuCallback('MyCustomMenuItems', function(menu, status) {
    menu.push({
      title: 'My custom menu item',
      target: () => {
        // Add your menu item's code here
      }
    });
  });
}

Upvotes: 1

Related Questions