0

I am trying to show a context menu using Autodesk.Viewing.Viewer3D (Headless Viewer).

I can get the context menu to show up easily when using Autodesk.Viewing.Private.GuiViewer3D as my viewer type but i don't want to use this viewer type as it has a toolbar and i don't want it to appear for this viewer. I can't use the css approach suggested here as I also want the toolbar in a different viewer in the same application.

My attempt to initialise a context menu using Autodesk.Viewing.Viewer3D (Headless Viewer) look like the following:

var contextMenu = new Autodesk.Viewing.UI.ObjectContextMenu(viewer);
        viewer.setContextMenu(contextMenu);
        viewer.registerContextMenuCallback('CustomContextMenuItems', function (menu, status) {
            if (status.hasSelected) {
                if(menu === null){menu=[];}
                while (menu.length > 0) {
                    menu.pop();
                }

                menu.push({
                    title: 'Do Something',
                    target: function () {
                        console.log("Doing something")
                    }
                });

            } 
        });
Neil_M
  • 462
  • 5
  • 17

1 Answers1

1

The context menu is intended to be used with GuiViewer3D. It's most likely relying on some of its HTML or CSS setup, which is why it's causing issues with Viewer3D. If you need this level of customization of the GUI, I'd suggest to implement a separate, simple context menu instead of bending the built-in one.

Petr Broz
  • 8,891
  • 2
  • 15
  • 24
  • Hi Petr, Any guides or examples for creating a simple context menu? Cheers – Neil_M Jan 26 '21 at 11:31
  • 1
    Hi Neil, I'm sure there are some tutorials for this online, for example: https://www.bypeople.com/html-css-js-context-menu-snippet or https://www.geeksforgeeks.org/how-to-add-a-custom-right-click-menu-to-a-webpage. – Petr Broz Jan 26 '21 at 11:57