Cyclone 3DR Script
from Technodigit, part of Hexagon. Copyright 1997-2022.
 
Loading...
Searching...
No Matches
Reporting

How can I create my own report through script

Introduction

This documentation explains how to create your own PDF reports through scripting.

A complete script is available here. This script follows the path recommended below explaining how to create a report.

The recommended path is as follow:

  • Create the data that have to be integrated in the report (views, labels...)
  • Create the template using the editor that will be used to report the data
  • Create the report and export to PDF


SReportData: the chapter content

The structure that will contain all the data to be integrated in reports is the class SReportData.

This structure is exactly the same as the one created in 3DReshaper application by some commands creating inspection results.

It therefore contains information such as:

  • A ViewSet
  • One (or more) table of labels
  • Some texts (for example, one could store the scan location here and update the reports with the right location every time)
  • Some numbers (for example, one could store here the number of points in a scan)
  • Some lengths, areas, volumes... in different units

Except from the viewset, every information in the SReportData must be named with a unique name. As an example, it is not possible to store two tables of labels named as "Inspection Table".

Creating a SReportData

There are two ways to create a SReport data structure:

  • From scratch, using the SReport.New() function
  • From a function in script delivering one as an output

A good example of function delivering a SReportData as an output is SPoly.Compare(). In this case, the SReport already contains:

  • A view of the inspected mesh
  • The names of the reference and inspected objects (cloud or mesh)
  • A title (a text)

With a SReportData created this way, one could directly go to the SReport generation described below as the software will recognize it as an inspection coming from the inspection routine and will apply the default template.

Updating the view

In order to define precisely the view that should be reported, one can explicitly hide or show some components, change the view direction and finally call the function dedicated to update the view.

Code sample updating the view:

SetViewDir(AXIS_X)
ZoomAll()
myReportData.UpdateMainViewSet()

Adding labels

It is very common that reports contains tables of labels (deviations, distances between points...).

A SReportData can contain several tables of labels: for example deviation labels and distance labels.

Code sample adding labels

myReportData.AddLabels("Deviations",DeviationLabels)
myReportData.AddLabels("Distances",DistanceLabels)

Templates: the chapter layout

In order to use in an automated way a customized template, it is necessary to create it beforehand!

The template has to be created using the editor with a document containing the exact same data added to the document by script.

Once the data have been organized accordingly in a template, the template has to be saved to .mlt format. This file is saved on the computer and can then be shared or moved next to the script.

The images below show:

  • The default template provided by the software applying to the Compare function.
    This default template includes:
    • A default view with no labels
    • A section above the view including the chapter name, the name of the reference object and of the measured object
    • A section below the view dedicated to show deviation labels created by hand in the software (not created here and therefore empty)
  • The customized template:
    It includes:
    • A title
    • A 2D view
    • A table with most internal and external deviations
    • A 3D view of the deviations

SReport: the complete report

The final step is to add each SReportData as a chapter to a report, with, for each of them, the corresponding template.

Footer and header, as well as generic report options (page format, number of decimals...) can also be defined at this step, before being exported to PDF.

How to create the SReport object:

theReport = SReport.New();

How to set report options, such as the format, the margins, etc.

var reportOpt = {
PaperFormat : SReport.A4,
MarginTop : 5,
MarginBottom : 0,
Orientation : 1,
HeaderPolicy : 1,
FooterPolicy : 0,
LengthDecimals : 3 };

theReport.SetReportOptions(reportOpt);

How to add chapters to the report:

var res = theReport.AddChapter(AllData.reportChapter1, CurrentScriptPath() + '/CustomInspectionReport.mlt');
if (res.ErrorCode != 0)
throw new Error( 'Failed to add chapter 1' );

res = theReport.AddChapter(AllData.reportChapter2, CurrentScriptPath() + '/Landscape_4Views.mlt');
if (res.ErrorCode != 0)
throw new Error( 'Failed to add chapter 2' );

How to export a PDF file from the SReport object:

res = theReport.ExportReportPDF(CurrentScriptPath() + '/InspectionReports.pdf');
if (res.ErrorCode != 0)
throw new Error( 'Failed to create the PDF file' );