1 Apr 2019

Calibrate the Measure tool for other units

When the original file contains no information about the unit of measurement used (I find this in case of STL files) then the Measure tool in the Viewer defaults to meter / m. In case of saving to STL from Inventor, the internal length unit of Inventor will be used, which is cm. So when looking at my 1 inch cube it will be saved with lengths of 2.54 (meaning 2.54 cm) and the Measure tool will show this:

Measurement in meters

Actually, I've already changed the precision from the default 1 to 2, so that it's clearer what the exact measurement is. It's easy to do. You just need to get access to the Measure tool extension, and then can access various properties:

var ext = viewer.getExtension("Autodesk.Measure")
ext.sharedMeasureConfig.precision = 2

Note: if you want to play with these settings on Fusion Team, A360BIM 360 Docs or some other Viewer instance, then you can do that from the Debug Console by referring to the Viewer instance as NOP_VIEWER - see Do simple Viewer API tests quickly

I can also change the unit which is shown from meters to inches:

ext.sharedMeasureConfig.units = "in"

Measurement in inches

That is still not correct, since we started off with the wrong measurement of 2.54m instead of 2.54cm. So we also need to calibrate the Measure tool. The correct measurement is 100 times smaller than what is currently shown so we need to multiply it by 0.01:

ext.calibrateByScale('in', 0.01)

Correct measurement in inches

That's correct at last ?

Now let's look at another model where the 1 inch cube model was saved to STL with measurement of 1.00 (instead of 2.54 like Inventor does it). First it will show up like this:

Measurement in meters

To get from meter to inches, we have to change the unit to inches and also need to calibrate the measurement by multiplying the current value by 0.0254:

ext.sharedMeasureConfig.units = "in"
ext.calibrateByScale('in', 0.0254)

The result:

Measurement in inches

If you want to make the above changes right after the model loading then make sure you wait for the loading of the Measure extension:

const onExtensionLoaded = (e) => {
 
  if (e.extensionId === 'Autodesk.Measure') {
 
    // customize the extension
 
    // no need to listen to this event anymore
    viewer.removeEventListener(
      Autodesk.Viewing.EXTENSION_LOADED_EVENT,
      onExtensionLoaded)
  }
}
 
viewer.addEventListener(
  Autodesk.Viewing.EXTENSION_LOADED_EVENT,
  onExtensionLoaded)
 
viewer.start()

 

Related Article