Reputation: 156
I want to remove Show Properties item from context menu which was added V.7.38 and hold other options in the menu.
Although I'm able to remove older options like Isolate or Hide selected, I'm not able to remove Show Properties from menu.
viewer.registerContextMenuCallback('id', function (menu, st) {
//remove the item from menu
})
This code sample works for older options. Is there any other way to remove newly added options like Show properties
?
Thanks
Upvotes: 0
Views: 362
Reputation: 9942
Removing a specific menu entry is a bit tricky today, because of these two reasons:
Different viewer extensions might register their own menu callback before or after your callback.
When the viewer iterates through all menu callbacks to be executed, it does so simply using for (const callbackId in viewer.contextMenuCallbacks) { ... }
(where contextMenuCallbacks
is a JavaScript object), which means that the order of execution is not deterministic.
In case of the "Show properties" menu entry, this one is added by a context menu callback called propertiesmanager
, added by the built-in viewer extension called Autodesk.PropertiesManager
. With that said, there are a couple of options to remove the menu entry, for example:
propertiesmanager
menu callback using viewer.unregisterContextMenuCallback('propertiesmanager')
propertiesmanager
callback and that it can therefore remove the "Show properties" during runtime; I was able to achieve this by registering my own menu callback after the Autodesk.Viewing.GEOMETRY_LOADED_EVENT
, but again, I cannot guarantee that this will always work as the enumeration of object keys (in point 2 above) is not deterministic.Autodesk.PropertiesManager
extension, for example, by modifying its _onContextMenu
method that handles the menu callback; this is quite hacky though...Upvotes: 1