Cyclone 3DR Script
from Technodigit, part of Hexagon. Copyright 1997-2023.
Loading...
Searching...
No Matches
Scripting report

Introduction

This documentation explains how to create your own PDF reports through scripting.
The recommended workflow is as follow:

  1. Create the data that have to be integrated in the report (views, labels...)
  2. Create the template using the editor that will be used to report the data
  3. Create the report and export to PDF
Note
A complete script is available in the GitHub script repository.
It illustrates the recommended workflow described in this page.
Also, all code sample from this page relates to this script.

SReportData: the chapter content

The structure that will contain all the data to be integrated in reports is the class SReportData.
It is exactly the same as the one created in the application by some commands creating inspection results.

It therefore contains information such as:

  • A ViewSet, see SViewSet
  • One (or more) table of labels, see SLabel
  • 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
Naming data

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.

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

Adding labels

It is very common that a report contains tables of labels (deviations, distances between points...).
A SReportData can contain several tables of labels: for example deviation labels and distance 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 may be shared or moved next to the script.

The following image shows the default template provided by the application for SPoly.Compare:

It 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 following image now shows the difference with the same data but with a custom 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?

var theReport = SReport.New();
Allow the creation of reports.
Definition: Reshaper.h:8207
static SReport New()
Create an empty SReport.

How to set report options (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);
@ A4
A4.
Definition: Reshaper.h:8214

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?

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