disable double click to zoom in autodesk viewer online - autodesk-forge

When selecting many elements in the Autodesk's online viewer, I double click accidentally and the model zooms to the element. I have to zoom and pan to the view I'm comfortable with again and it is very annoying. Is there a way to disable this functionality in the online viewer?
I found similar questions for the desktop apps (https://forums.autodesk.com/t5/autocad-forum/turn-off-wheel-double-click-zoom-extents/td-p/53144) but not the online viewer.

There is a fairly straightforward workaround for that: create a custom tool and absorb the double-click event. See that article for a start Creating "Tools" for the View & Data API.
To absorb an event implement the corresponding handler and return true:
this.handleDoubleClick = function(event, button) {
// ... do your stuff if needed ...
// event handled
return true;
};

Related

Is there a way to enable partial selection using the BoxSelection extension in the viewer

We are using a custom extension to handle window selection in the forge viewer following the steps from this blog post: https://forge.autodesk.com/blog/custom-window-selection-forge-viewer-part-iii.
We're able to set 'partial selection' mode on that extension. Is there a way to do this with the new BoxSelection extension that was added in v7.32?
A new option is added with Autodesk.BoxSelection extension:
useGeometricIntersection
Due to the other issue, this option is not on by default, you can switch it by the code below. After it is loaded again, Left to right mouse drag is containment, Right to left mouse drag is intersection.
async function enableGeomtricBoxSelection() {
// unload the extension, which was loaded with geometric selection turned off
viewer.unloadExtension('Autodesk.BoxSelection');
// reload the extension with geometric selection turned on
ext = await viewer.loadExtension('Autodesk.BoxSelection', {
useGeometricIntersection: true
});
// Display the toolbar button (optional) in the toolbar. You can invoke box
// selection by holding cmd(mac) / ctrl(windows) + mouse drag
ext.addToolbarButton(true);
}
enableGeomtricBoxSelection();

click event is not working in forge viewer

We have implemented the Autodesk Forge Viewer in our web application. We have displayed the Navisworks file in Forge Viewer.
On clicking the particular element/object in forge viewer, we need to get the Object ID of selected element.
We will use this Object ID for multiple purpose (like zooming, etc) in our application.
For this we have used the below selection changed event in our page but the below event is not working.
EventsTutorial.prototype.onSelectionEvent = function(event){
var currSelection = this.viewer.getSelection();
var domElem = document.getElementById('MySelectionValue');
domElem.innerText = currSelection.length;
};
Kindly help us to resolve this issue.
It seems you didn't register your function as a listener to the viewer. So I guess your function onSelectionEvent is never called.
You probably want to register a listener to either the SELECTION_CHANGED_EVENT(docs) or the AGGREGATE_SELECTION_CHANGED_EVENT(docs).
this.viewer.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT, (args) => {
// do something
});

how to zoom asset in forge viewer

we have implemented the forge viewer in our web application. When clicking the asset in forge viewer, we need to make our entire page should be loaded.
any click event is available when object is selected in viewer?
please provide the function name or code, we need to hit any function when asset selecting.
you can use below even, you can write this event after you create instance of viewer
viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectionChanged);
function onSelectionChanged()
{
perform your operation;
}
for zooming the asset you can use
viewer.fitToView([arrayofdbid],viewer.model);
if you want to highlight selection, you can use,
viewer.select([array of dbid]);

Mouse click vs viewer.select function selection behave differently in Autodesk Forge multi models viewer

I have been working on multi-model from the last couple of weeks and found that selection of a model object using mouse click vs viewer select function behave differently.
I have two models one architectural and another mechanical. When I select a wall or room on the architectural model using mouse click, Object select with overlay without having any problem but when I try using viewer select function with same object, it hides behind the wall and overlay doesn't work. It is only happening with the architectural model and working fine with the mechanical model.
Please suggest me if I am doing something wrong with multi-model.
To programmatically select components when working with multiple models use viewer.select(dbid, model):
let model = viewer.impl.modelQueue().getModels()[index] or viewer.impl.findModel(modelId);
viewer.select(dbid, model)
And to get selected dbids use viewer.getAggregateSelection (see doc here) the event to subscribe to AGGREGATE_SELECTION_CHANGED_EVENT (doc here) to track selection changes:
If the issue persists can you send some screenshots and your models (links via a sharing service like weTransfer/Dropbox) for further investigation over to forge.help#autodesk.com?

ZoomWindow extension breaks without GUI?

Using v2.13 of the viewer, the ZoomWindow extension relies on having the default GUI enabled. Is there a way around this? The load method is:
proto.load = function() {
var viewer = this.viewer;
var toolbar = viewer.getToolbar(true);
//var toolbar = viewer.getToolbar ? viewer.getToolbar(true) : undefined;
// Init & Register tool
this.tool = new namespace.ZoomWindowTool(viewer);
viewer.toolController.registerTool(this.tool);
// Add the ui to the viewer.
this.createUI(toolbar);
return true;
};
which fails because getToolbar is undefined.
It seems from the commented out line that this has been considered, but not implemented.
What is the best way to implement a work around - should I copy the entire extension with a new name, or can I replace the load method at runtime?
Edit: was looking to use the headless viewer, but it seems easiest just to hide the UI with css.
It's not clear to me if you are using the GuiViewer3D or want to use the Viewer3D, the viewer without Autodesk custom UI. If you use GuiViewer3D, you can simply wait for the toolbar to be loaded before loading the ZoomWindow extension, which requires the toolbar controls to be created in order to add a button to it.
viewer.addEventListener(Autodesk.Viewing.TOOLBAR_CREATED_EVENT, function () {
viewer.loadExtension('Autodesk.Viewing.ZoomWindow')
})
Here is a blogpost I wrote a while ago about using events in the viewer. It is not up-to-date with the current version but remains valid:
http://adndevblog.typepad.com/cloud_and_mobile/2015/10/event-watcher-extension-for-view-data.html
Now as Zhong mentioned, if you want to use the headless viewer with no UI and still use the extension, you may have to copy and customize it as you suggested. But an easier workaround could be to use GuiViewer3D and simply hide the existing toolbar with css, so the the js code remains valid. Set display:none on div id="guiviewer3d-toolbar", for example, or on the adsk-control class.
Hope that helps