DM_CALL_SCRIPT

Syntax

int_val = DM_CALL_SCRIPT ( script_file, script_name[, arg1, arg2, …] );
Input arguments
string script_file The path and the name of the script file. The file can be either already compiled (.bs) or in source format (.mac). The file can be located in the COS database (path not needed), or it can be located in the file system using either an absolute or relative file path.

The argument cannot be an empty string. This interface does not support the script library concept that is supported by the other applications.
string script_name The name of the script function to be called.
Optional input/output arguments
variable arg1, arg2, … The argument list for the script function to be called.

Return Values

Standard

Description

This function can be used to call a script function located in another file or in the same file, allowing the reuse of existing code. Although the call can be made in Plant Modeller, P&ID, or Piping Isometrics & Spools, the script being called must contain only Datamatic script functions that run under DM_TOOLS.

When needing to call a script that contains application-specific script functions, use the following instead:

Plant Modeller

PM_CALL_SCRIPT

P&ID

PD_CALL_SCRIPT

Piping Isometrics & Spools

PI_CALL_SCRIPT

Calls using a file path

The script file can be loaded from the file system by using an absolute or relative file path.

Call Details

DM_CALL_SCRIPT("C:\temp\script.mac", "hello_world")

This call uses an absolute path to load the script from C:\temp\script.mac.

DM_CALL_SCRIPT(".\script.mac", "hello_world")

This call uses the relative path .\ which under DM_TOOLS loads the script from the workspace folder: <project>.pms\<workspace>.wsp\script.mac.

Under design applications (.pm, .pd, .pi), this relative path loads the script from the design area. For example, under Plant Modeller it loads it from <project>.pms\<workspace>.wsp\<area>.pm\script.mac.

DM_CALL_SCRIPT("..\script.mac", "hello_world")

Under DM_TOOLS, using the relative path ..\ is not recommended because it loads the script from the parent folder of the workspace folder, and this can be either the real project folder or the local parent of the workspace folder.

Under design applications (.pm, .pd, .pi), this relative path loads the script from the workspace folder: <project>.pms\<workspace>.wsp\script.mac.

Calls using the COS database

The script file can be loaded from the 'common' category of either the library or project database by omitting the path:

DM_CALL_SCRIPT("script.mac", "hello_world")

Note: The call specifies whether the target script is a precompiled file (.bs) or a script source file (.mac). However, in the COS database, the file name is always just "script" without the extension.

The function call searches for the file name and runs it from the first applicable location in this order:

  1. The script is found in the project database. In this case, all other locations are ignored and the script is run from the project database.

  2. The script is found in the library database, but not in the project database. In this case, all other locations are ignored and the script is run from the library database.

  3. The script is found under the system directory %PMS_HOME%\dm, but not in the project or library database. In this case, the script is run from the system directory.