Search code examples
autodesk-forgeautodeskautodesk-bim360

Autodesk Forge PDF Viewer and Measuring


I am working on an app that needs to calculate measures like areas and length etc. Lucky today by using Autodesk Forge viewer we can do that. I had looked into this blog post [enter link description here][1] and as well to the docs [enter link description here][2] [1]: https://aps.autodesk.com/blog/fast-pdf-viewingmarkup-inside-forge-viewer [2]: https://aps.autodesk.com/en/docs/viewer/v7/reference/Extensions/MeasureExtension/

I am looking for a way to insert the measure values into my database, where I can view it again when I want or reload the page (not lose it) similarly with Markup with callouts and text.

Lastly, I am wondering about how much does it costs to translate the pdfs files using Forge?

thanks


Solution

  • You can retrieve the array with objects related with the measurements done with the line:

    NOP_VIEWER.getExtension('Autodesk.Measure').measureTool.getMeasurementList()
    

    You can store the result in your DB, together with viewstate and additional info such as urn and viewable guide.

    To restore it, you can first activate the tool

    NOP_VIEWER.getExtension('Autodesk.Measure').activate()
    

    Then set the measurement list using the values you read from the DB

    NOP_VIEWER.getExtension('Autodesk.Measure').measureTool.setMeasurements(listMeasurements)
    

    Where listMeasurements will be something like:

    var listMeasurements = [
    {
      angle: "0.0 °",
      arc: "0.0 mm",
      area: "0.0 mm²",
      deltaX: "1569.7 mm",
      deltaY: "6463.7 mm",
      deltaZ: "162.0 mm",
      distance: "6653.6 mm",
      from: "Vertex",
      location: "X: 0.0 mm\nY: 0.0 mm\nZ: 0.0 mm",
      picks: [
       {intersection: {x:43.5168342590332,y:-60.37924575805664,z: 8.858267784118652}, modelId: 2, viewportIndex2d: null, snapNode: 2587},
       {intersection: {x: 38.367037573210276,y: -39.17272345572108,z: 8.32677173614502}, modelId: 2, viewportIndex2d: null, snapNode: 3521}
      ],
      precision: 1,
      text: "",
      to: "Vertex",
      type: "Distance",
      unitType: "mm"
     }
    ]
    

    Now, you can deactivate it with one line of code

    NOP_VIEWER.getExtension('Autodesk.Measure').deactivate()
    
    • Instead of using NOP_VIEWER, refer to your viewer instance through the variable defined in your code