Determining ship's total weight
To determine the total weight of the ship, a JavaScript script can be used. The script calls the report generator, and sets some environment variables used by it. The report generator in turn uses a report layout to specify what is to be calculated.
The result of the calculation is copied to the opened block together with the generated log file.
Commands
In addition to the standard JavaScript functions supported by ECMA-262, the following CADMATIC Hull specific variables and commands are available. A global array holding the block names is also available.

Variable |
Type |
Description |
---|---|---|
blocks | String array | A list of the names of each block in the project that is not shadowed at the current site |
process.argv |
String array |
All command line parameters that are separated with a space and given to the Hull Clone executable after a double dash -- or /jsArgs. |

Command |
Argument |
Return type |
Description |
---|---|---|---|
|
|
String |
Returns the active block folder. |
|
|
String |
Returns the active block name. |
|
|
String |
Returns the active block group name. |
|
|
String |
Returns the active norms name. |
|
|
String |
Returns the active project name. |
|
|
Boolean |
Sends a DDE command to Hull Server. It can also be used to enable/disable the Models only mode in Hull Server. |
getEnv
|
Environment name * | String | Retrieves the value of the environment "name". If the requested name does not exist, returns the null object. |
getUsers
|
Block name |
username: string, pid:integer, processname: string, host: string, timestamp: integer, utctime: string |
Retrieves a list of user processes that are active in a given block. The function provides the following information for each user:
|
hullBinPath
|
|
String |
Returns the binary path of the Hull installation. Also available as the value of the %NCGBIN% environment variable used by the Hull Clone process and CADMATIC Hull. |
|
|
String |
Returns the binary path of the Hull temporary folder. Also available as the value of the %NCTMP% environment variable used by the Hull Clone process and CADMATIC Hull. |
|
|
Boolean |
Returns when the active block is a 3D block. |
|
Absolute or relative file path |
void |
Runs the JavaScript file included in the command. Separate JavaScript files can be run with this command in the middle of the current JavaScript. If the given file name has no extension, the extension .js is added. The file path can be a full path, or a path relative to the current directory. |
|
|
Boolean |
Returns whether or not the active block is a reference surface block. |
|
|
Boolean |
Returns whether or not the active block is virtual. |
|
Block name |
Boolean |
Returns when the specified block is a 3D construction block (that is, 2D blocks and predefined blocks are not returned). |
|
Block name |
Boolean |
Returns whether or not the specified block is a reference surface block. |
|
Block name |
Boolean |
Returns whether or not the specified block is a virtual block. |
|
Block name |
Boolean |
Releases locks in the active block, and removes environment variables that were set when the block was opened. |
|
|
String |
Returns the active norms folder. |
|
|
String |
Returns the active project folder. |
setEnv
|
Environment name, Environment value * | void | Assigns the environment value to the environment "name". |
|
Integer |
void |
Pauses the script for at least the given amount of milliseconds. |
|
Integer |
void |
Pauses the script for at least the given amount of seconds. |
|
|
|
Starts the Hull Server. |
|
Timer name |
Boolean |
Starts a named timer. Multiple timers with different names can be active at the same time. |
|
|
|
Stops the Hull Server. |
|
Timer name |
Double |
Stops a named timer. Returns the elapsed time between starting and stopping the named timer. After this the same name can be used again to start a new timer. |
|
DOS command |
Boolean |
Executes the specified command. |
|
Executable, |
cmdOke: boolean, exitcode: integer, status: integer, output: string |
Run the given executable with the given parameters. The system automatically executes this version of the Optionally a timeout in minutes can be given. If the executable takes longer than the given timeout to finish, it will be aborted. The function returns a JavaScript Object with four members:
|
|
|
void |
Pauses execution of the script until the hull server queue is empty. |
* For both Environment name and Environment value the actual values should be enclosed in double quotes. If backslashes are needed in a path, double backslashes should be used. |
In addition to the standard JavaScript functions, the following CADMATIC Hull specific commands are available.
Report layout
You can create a layout for generating a report with the total weight using the Production > Reports > Report Layout function in the System Management application. You can also copy the example below and save it as %NCGNORMS%\report\TotalWeightScript.rpt.
The example report layout is made for the example script presented below in Script example.
The layout contains only a summarized weight column. No sorting, sub summarizing or uniting is applied to the column. The header and footer are left empty.
The Total footer contains the keyword TWEIGHT for the total weight.

[SETTINGS]
'output' '1'
'printer' '1'
'lines' '1000'
'group' '0'
'startend' ' '
'dateformat' 'DD MM YYYY'
'index_lines' '0' '0'
'sumline' '0
'[END]
[HEADER]
[END]
'name' 'veld' 'type' 'length' 'align' 'summ' 'addzero' 'printifzero' 'mark' 'decimal' 'convcol'
[DETAIL]
'NCG_LOG_DATA_4' 'Nettoweight' 'Real' '10' '1' '1' '-1' '-1' ' ' '0' '-1' '32.-10.0.0'
[END]
[FOOTER]
[END]
[TOTALFOOTER]
Total Weight $TWEIGHT
[END]
[SUBSUM]
[END]
[SORTING]
[END]
[UNITE]
[END]
[RANGES]
'NCG_LOG_DATA_14' 'Sectionnumber' '10' ' * '
[END]
Remarks:
- Text can be added to clarify the purpose. For example, the date can be added with &date.
- The layout contains the default range value for the logistical field SECTIONNUMBER. This value is set to *. This makes the report generator handle all relevant blocks in the calculation of the total weight.
- Another range can be specified if for example only the weight of the blocks in the range 100..200 is needed. In that case * should be replaced by the range, 100..200.
- The keywords NCG_LOG_DATA_4 (weight) and NCG_LOG_DATA_14 (block) are used to make the layout independent of the user names defined in the first column of the Logistical layout. This way it is possible to copy this report layout to any norms folder.
Script example
Below is an example of a script, TotalWeightScript.jsp, that opens the first 3D block available in the block list, then sets a number of environment settings needed by the report generator and executes it.
This script is meant to be used with the report layout presented above in Report layout.

// JavaScript to calculate the total weight of a ship with help of the reportgenerator
{
var i=0,blockfound=-1
print("***************************************************************");
print("**** Determine Total Weight ****");
print("***************************************************************");
// Open the first 3Dblock.
for (i=0;i<blocks.length;i++){
if (is3Dblock(blocks[i])) {
if (switchBlock(blocks[i])){
blockfound=i;
i=blocks.length+1;
}
}
}
if (blockfound>-1) {
setEnv("REP_APPL","totalscript");
// Name of the report layout to be used.
setEnv("REPORT_FILE","TotalWeightScript.rpt");
setEnv("REPORTNAME","TotalWeightScript");
setEnv("REPORT_OUTPUTFORMAT","");
// Generate a empty repranges.dat file.
system("copy nul %NCTMP%\\repranges.dat > nul");
// Calculate the total weight.
system("reportnew > %NCTMP%\\totalweightscript.log");
system("copy %NCTMP%\\rep-totalweightscript.list totalweight.list > nul");
system("copy %NCTMP%\\totalweightscript.log totalweightscript.log > nul");
print(" Result copied to "+currentBlock()+"\\totalweight.list ");
print("***************************************************************");
}
else {
print("**** There is no 3D block available! ****");
}
}
Remarks:
- Environment variable REP_APPL is set to totalscript to have the body be presented normally (it is not presented in this case), and also to make sure that no time is spend on sorting, summarizing and uniting.
- The name of the report and the name of the layout file are specified in REPORTNAME and REPORT_FILE, respectively.
- Finally, the script will generate an empty repranges.dat file, which is needed for the report generator.