Reputation: 5342
How to save and load measurements with the built-in measure tool (the Autodesk.measure
extension) for Autodesk Forge Viewer?
There seems to be no explicit APIs to accomplish this with the default extension?
Upvotes: 0
Views: 542
Reputation: 9377
I currently have a request to do something in that direction, but apparently, in version 7 the viewer project is using ES6 modules, which makes it impossible to override the MeasureTool
like is presented in this great project built using version 2.
After messing around for a whole morning trying to break ES6 modules system to override something in the MeasurementExtension
to get the data, how surprised I became when during a debugging session I find out more than 40 not-yet-documented methods in the extension object. Just log them to the console:
const extension = viewer.getExtension('Autodesk.Measure');
console.log(extension.__proto__);
You'll be interested in these methods:
extension.getMeasurementList() // => grab the list of selected measurements
extension.setMeasurementList() // => set the list of selected measurements
The only gotcha here is that you must activate the extension first in order to use it:
extension.setActive(true);
extension.setMeasurementList()
extension.setActive(false);
There are also some available events that you can listen to. You can list them to check them out:
console.log(Autodesk.Viewing.MeasureCommon.Events)
I hope this can help whosoever needs it.
Upvotes: 1
Reputation: 5342
There's an unofficial, extended version of the measure tool that supports the JSONify and reloading of measurement data: https://github.com/wallabyway/area-markup/blob/master/docs/Measure/MeasureTool.js
let measurementData = measureTool.getJson();
...
measureTool.loadJson(measurementData);
Official support for this feature is still being reviewed and will be announced in due course.
Note: Although not entirely third party (built by ADN team), this extension is still unofficial and hence not officially supported by Autodesk, and is subject to change and might become incompatible with later versions of Viewer w/o prior notice.
Upvotes: 0