Getting Measurement to display with user specified start & end point from code?

  • Objective: I’m currently trying to add custom measurement calculations to be displayed on the top model. And I noticed the built-in MeasurementExtension tool can achieve this goal for clicking.

After reading through the class, I believe fromMeasurementData method can be used to do this from the viewer side.

  • Issue: Currently this method of measurement isn’t working and throws “TypeError: Cannot set property customDepthMaterial of # which has only a getter”

  • Example: Current Use is load in scene and specify origin and end point and call the created extension using:

       // Try if extension is enabled
          if (measurement) {
            measurement?.fromMeasurementData(origin, result.point);
          }

Hi @Leul_Tesfaye

fromMeasurementData is a placeholder that was supposed to support restoring persistent measurements, but since measurements are currently not persisted, this was never used. As such it has no real and working implementation.

You can however programmatically create measurements in various ways. Here is a live example with a working fromMeasurementData implementation

There is PR in review with a bunch of additions and improvements towards the measurement tools that’s going to drop soon. It will contain basic programmatic measurements support like the one in the live example out of the box. Until then you can safely use the extended implementation from the live example.

Cheers

2 Likes

Awesome! Thank you so much for the live demo.

1 Like