Cyclone 3DR Script
from Technodigit, part of Hexagon. Copyright 1997-2023.
Loading...
Searching...
No Matches
Upgrading scripts to V8 engine

Context

At the beginning, the script engine used to rely on Qt Script to provide a Javascript interface to communicate with the application.
Unfortunately, Qt Script isn't maintained anymore.

Starting with Cyclone 3DR 2023.0, the script engine has been ported to the V8 engine which fully replaces Qt Script.

This offers a better compliance with the Javascript standard and more flexibility to develop powerful scripts.
On the counterpart, some scripts may require edition to make them run correctly in the new engine.

The goal of this page is to help you to check most common errors that you may encounter while running existing code in the new engine.

API breaking changes

The following changes has been made which can break your script.

Changes on SCloud.FromFile

This method was changed during the migration:

  1. The parameter importScanDir has been removed.
  2. The following file formats are not supported anymore: .gsn, .iso, .stl.

Removal of SComp::RepresentationTypeEnum, SComp::SetRepresentationType

Those components have been removed. Use the specific enum and method of the object class instead (such as SCloud.CloudRepresentationTypeEnum and SCloud.SetCloudRepresentation).

Here is an example where changes are required:

var myMulti = SMultiline.FromSel()[0];
myMulti.SetRepresentationType(SMultiline.INSPECTION); // Error: INSPECTION was part of SComp::RepresentationTypeEnum enum
Provide polyline edition and creation methods.
Definition: Reshaper.h:5553
static Array< SMultiline > FromSel()
Get all the selected SMultiline.

It can be fixed like this:

var myMulti = SMultiline.FromSel()[0];
myMulti.SetRepresentationType(SMultiline.MULTILINE_INSPECTION);
@ MULTILINE_INSPECTION
Colors ares based on an inspection value on each point. Only available if the SMultiline contains ins...
Definition: Reshaper.h:5564

Common errors

Those errors are now triggered due to V8 engine being more compliant with Javascript standard.

Handling of the nullable type

0 can no longer be used as a valid value for javascript objects values: null must be used instead.

Example

The method ScriptUtil.GetCameraDirection() can optionaly accept a target point as input.

Previously, the following instruction was valid:

var dir = GetCameraDirection(0).Vector;

This code now generates an error and can be fixed the following way:

var dir = GetCameraDirection(null).Vector;
// or
var dir = GetCameraDirection().Vector;

Boolean values as integer

Writting 0 or 1 instead of boolean values (false, true) now generates a warning.

Example

For example, the method SPoly.PipeTubeAlongPath allow to fill the output pipe or not.

Previously, the following instruction was valid:

var radius = 10.;
var closeExtremities = 0; // bad practice
var paths = [myPath];
var ret = myPoly.PipeTubeAlongPath(radius, closeExtremities, paths);

This code now generates a warning. The good practice is to use true or false whenever a boolean value is used:

var radius = 10.;
var closeExtremities = false; // good practice
var paths = [myPath];
var ret = myPoly.PipeTubeAlongPath(radius, closeExtremities, paths);

Array vs map

Previously, it was possible to pass Array instead of Map. It could lead to silent conversion errors.

Example

The method SDialog.AddLine can be configured through a configration Map object.

Have a look at the following sample:

var dialog = SDialog.New("Form");
var settings = ["left"]; // invalid
dialog.AddLine("Input name", true, settings, "Default");
dialog.Execute();
Provide simple dialog creation methods.
Definition: Reshaper.h:1314
AddLine(string label, boolean isInput, Object labParams={}, string defaultInput="")
Adds a new line to the Dialog.
static SDialog New(string title="Dialog")
Dialog constructor.

Previously, the following instruction was not valid but didn't generate an error.
As a result, the desired alignment wasn't respected.

This code now generates an error and can be fixed the following way:

var dialog = SDialog.New("Form");
var settings = {"align": "left"};
dialog.AddLine("Input name", true, settings, "Default");
dialog.Execute();