0

I am currently writing an extension app for the Autodesk Forge Viewer, and I need to be able to create a measurement from existing points.

To elaborate, I have been able to save the XYZ coordinate data for each point of a measurement to a JSON which is then stored locally.

For example, if you create an angle measurement, it will save the coordinate data for each of the three points needed to make the angle measurement.

The part I am now stuck at is that I am struggling to be able to recreate this measurement when the viewer is reloaded. I can get the coordinate points into measure.js, but there seems to be no easy way to instantiate a new measurement from these points, seemingly because the measurement is created from SnapResults that are returned from click events.

Is there any way I can achieve this functionality? I need the new measurement to appear as it was when it was created, with labels and with editable points, but using only the coordinate points to create it. Any help from the Forge team would be greatly appreciated.

Piyush Bansal
  • 1,635
  • 4
  • 16
  • 39
Alex Leach
  • 118
  • 7

1 Answers1

0

While not exactly supported, There is a modified version of the area measurement tool with source-code and details on how to save and restore measurements.

Blog and video: https://forge.autodesk.com/blog/area-planning-tool-forge-viewer-and-mysql

Live demo: https://wallabyway.github.io/area-markup/ (note: click measurement tool before you start)

source code - GitHub: https://github.com/wallabyway/area-markup

Let me know if this has what you are looking for. enter image description here

michael beale
  • 1,014
  • 1
  • 6
  • 5
  • Thanks for your response Michael. This definitely seems to be what I am looking for, however, using the loadJson function I am getting a similar error to what I was getting when attempting to create measurement picks myself: Uncaught TypeError: Autodesk.Viewing.Extensions.Measure.SnapResult is not a constructor This occurs on the following line: var p = _currentMeasurement.setPick(json.id, new Autodesk.Viewing.Extensions.Measure.SnapResult()) I am not sure why this is occuring or how to fix it, since I am using an unedited, new version of viewer3D.js – Alex Leach Sep 24 '18 at 21:58
  • Okay, so upon further analysis, this does seem to be version related. Switching to version 3.3.5 allows me to use SnapResult as a constructor, however, other parts of my extension break as a result of using an older version. Is there any way I can construct a SnapResult in version 6+? – Alex Leach Sep 24 '18 at 23:24
  • Ah. Ok. I need to upgrade the code to version 6. Can you add an issue to the GitHub issues. Thanks. I don't want to forget. – michael beale Sep 25 '18 at 17:49
  • Have added the issue. Hope you can find a way to do this in v6 as I am still struggling to find a way. – Alex Leach Sep 26 '18 at 22:12