Script

Documentation of javascript programming

The Javascript programming documentation is available here:

Documentation of script classes


About Javascript

JavaScript© (often shortened to JS) is a lightweight, interpreted, object-oriented language, most known as the scripting language for Web pages, but used in many non-browser environments as well. It is a dynamic, non-typed scripting language supporting object-oriented, imperative, and functional programming styles.

Warning

In Javascript, when you write strings the '\' character is an escape character, you need to use '\\' or '/' instead. Pay especially attention to this when writing file paths in your scripts. For example:

var res = SCloud.FromFile( 'C:/Cloud.nsd' ); // Valid syntax
var res2 = SCloud.FromFile( 'C:\\Cloud.nsd' ); // Valid syntax
var res3 = SCloud.FromFile( 'C:\Cloud.nsd' ); // Invalid syntax

Usage

The Script Plugin can be used to execute Javascript code either from command line or the software's main Graphical User Interface.

  • From Application's main window

    Read page Run.


  • From the command line

    When using the Script Plugin from the command line, you can specify several command line arguments as listed bellow:

    Feature

    Flag parameter

    Description

    Script dialog box auto-opening


    --Script="D:/script.js"

    Open script dialog box at startup and load a script from the given file path.

    Console output retrieval

    --ScriptOutput="D:/output.log"

    Writes the console output into a given file.

    Silent mode (no GUI)

    --Silent

    Disables the Graphical User Interface (no windows).

    Executing additionnal code

    --ScriptParam=var fileToLoad='d:/Project/3drfile.3dr'

    You can specify additional scripting code, which will be executed just before the specified input script (if any).

    It's useful to give argument to the script from the command line. As example, you can give the .3dr filename inside a variable named fileToLoad, and then, use it inside the .js file to open that file.

    Sample js file which used a variable define with --scriptParam
    if(typeof fileToLoad === "undefined")
    throw new Error("variable 'fileToLoad' must be define using --scriptParam");
     
    var res = OpenDoc(fileToLoad);
     
    ...

    Auto-run with GUI

    --ScriptAutorun

    If –silent is not defined, run automatically script after opening the dialog box.


    Here is an example for executing from the command line:

    3DR.exe --script="D:/Tuto/SmoothPoly.js" --scriptOutput="D:/Output.log" --silent --scriptParam="var deviation=0.12; print('Use deviation control: ' + deviation);"

    This example:

    • Starts the application in silent mode, no window, only an icon inside the taskbar.

    • Executes SmoothPoly.js

    • Writes the console output into

      D:/output.log
    • Prints

      Use deviation control: 0.12