Creo.JS Testing Web Tool
This section provides a brief overview of the testing web tool, which is available in the Creo.JS framework.
Overview
To help you test the Creo.JS scripts with current Creo session, a testing web tool is provided with the Creo.JS installation. The tool provides an interactive user interface to work with Creo.JS APIs. You can test the APIs before using them in web applications. The page is called script_engine_testing.html and is available in creojsweb folder at <creojs_loadpoint>. To start using it, drag and drop the page in the Creo embedded browser. You can add the page location to favorites also.
Image
Figure 1
The page consists of four areas:
•  Creo.JS scripts toolbar
•  Creo.JS script edit area
•  Creo.JS script execution toolbar
•  Creo.JS script output area
To run a script, type the script in the editor and click Run.
The script is sent to Creo.JS engine and executed. After execution, the output generated by the script is printed in the output area. In the example shown in Figure 1, the following script is executed in the tool:
{
  let session = pfcGetCurrentSession ();
  print (session.GetEnvironmentVariable ("PRO_DIRECTORY"));
}
The following result is displayed in the output area:
C:\Program Files\PTC\Creo 4.0\M080\Common Files
Note that the script is included in curly braces. This prevents the variable definitions within the script to be populated into the page context, which can prevent the consecutive execution of the same script. If you do not add the curly braces, the script can be executed only once. If you try to run it for a second time you will get an error message.
Every script executed by this page is executed in the very same context. Thus, after the script is executed the first time, the context has a new variable session defined in it. When the script is executed the second time, it tries to define already defined variable and fails. If we add { and } to the scripts, we limit the visibility area for variable session by the block specified by its boundaries { and }. Thus, after the script is executed the variable session is removed from context and can be reused.
Creo.JS Scripts Toolbar
To save a script that you executed in the tool, click Save As in the Creo.JS scripts toolbar. Specify a name for the script. You can specify a name with relative path in it. For example, if you specify the name as test/test_env_var.js, the script is stored in a subdirectory test of the script directory.
Image
Scripts lists all the saved scripts. If you select a script from the list, it is loaded in the script editor. If you modify the script, the Save button is enabled.
The Creo.JS installation includes a library of sample Creo.JS scripts, which can you can execute in the web tool.
Creo.JS Scripts Execution Toolbar
To execute the script in the editor, click Run. It sends the script to the Creo.JS engine. If the script executes successfully, the output of the script appears in the area at the bottom of the page. Clear button enables you to clear the area, and Clear and Run first clears the output area and then executes the script.
Image
The tool also has a box field where you can execute single line scripts. This gives the user the ability to execute a single command in the same Creo.JS context. For example, you can get information about an element type by running help() method. For example, help(pfcSession) opens a new window with information about the pfcSession type. Similarly, you can select a text in the script editor and click Help on the Creo.JS scripts toolbar. This will also run the function help(selected_text).
Reset and Run set a new Javascript context and then execute the script. For example, the following script can be executed sequentially time after time if you use Reset and Run. In this case, the page is reloaded by first terminating the current Creo.JS context and initializing a new one:
let session = pfcGetCurrentSession ();
  print (session.GetEnvironmentVariable ("PRO_DIRECTORY"));