Display "Hello, World" in the Script log

In this tutorial, we will write a Script to display the characters of "Hello, World" in the "Script log" window by the following two methods:

  • Log output by Python standard string output
  • Log output by CRI Atom Craft API - Debug Module

Using log output function is convenient for visually checking the Script execution status. Let's begin by learning the differences between these two log outputs.

Preparing a Script file

First, prepare a Script file(Python file) for writing the process.
Start CRI Atom Craft, select "Script list..." from the "Script" menu to display the Script list window.
Select "tutorials [CRI]" from the Script list. Click the "New" button of the script file.

criatom_tools_atomcraft_api_tutorial_hello_scriptlist1.png

Click "New" button to display the dialog for creating files.
Input "tutorial01-1_helloworld.py" as the file name. Click the "Save" button to save the file.
The saved Script file "tutorial01-1_helloworld" is displayed in the Script list.

criatom_tools_atomcraft_api_tutorial_hello_scriptlist2.png

Script Description

Script files are created.
There are some sample scripts in the "samples [CRI]" script list.
Script files other than the created "tutorial01-1_helloworld" also display explanations.

The Script list can read the written comment in the following format in the Script, and display the "<b>Description</b>" field of the script list.

# --Description: Description text

Double-click "tutorial01-1_helloworld" in the Script list, open the Script list by Run the Script from the Script Editor , and input the comment for the description as follows:

# --Description:[Tutorial] Displaying "Hello, World" in the Script log

After inputting the comment, click the "Save" button on the Script Editor toolbar to save the Script.
By returning to the Script list, you can check the displayed description of the "tutorial01-1_helloworld" Script.

criatom_tools_atomcraft_api_tutorial_hello_description.png

For details about Script description format, refer to Extension for Script Editor .

Use Python standard string output to display "Hello, World"

After learning how to write the Script description, try using Python standard String output function - the print function to display "Hello, World".

Return Run the Script from the Script Editor and input the following:

print("Hello, World")

Click the "Save" button on the Script Editor toolbar to save the Script.

criatom_tools_atomcraft_api_tutorial_hello_scripteditor.png
Note
The Script is executed by reading the files.
Therefore, if the Script is edited, you need to save the file before executing.
If not, the Save dialog will be displayed before executing the Script.

Executing Script

Execute the created Script to display "Hello, World" in the Script log window.
Return to the Script list window, and click the "View log" button to display the Script log window.

Click "Run" button on the toolbar to execute the Script. "Hello, World" will appear in the Script log script.

criatom_tools_atomcraft_api_tutorial_hello_log.png

Use cri.atomcraft.debug module to display "Hello, World"

Use Python's print function to display the characters "Hello, World" in the Script log.
Next, Use the CRI Atom Craft API - Debug Module , to display "Hello, World" in the Script log.

Import the Debug module of CRI Atom Craft

CRI Atom Craft contains Python modules for manipulating CRI Atom Craft.
To use an external Python module in Python, use import in the Script to declare the "Use module".

To use the CRI Atom Craft API - Debug Module , write as follows:

import cri.atomcraft.debug
criatom_tools_atomcraft_api_tutorial_hello_import_debug.png


For details about the Debug module and other modules of CRI Atom Craft API, refer to Module reference .

Note
By writing "<b>import module name</b>", you can use the modules in the Script.
By writing "import module name as the replaced name, you can replace the specified name with the module to import, and can access to the module using more concise code.
import cri.atomcraft.debug as acdebug

Use "Log" of Debug module to display "Hello, World"

Declaring "import" and get prepared to use the CRI Atom Craft API - Debug Module .

Now, try to use Debug module to display "Hello, World".
The Debug module provides several string output functions, but here we use the log function to display "Hello, World".

After declaring " import cri.atomcraft.debug ", write a script as below:

cri.atomcraft.debug.log("Hello, World")

Save the Script and click the "Clear" button in the Script log window before executing the Script, to clear the log display.
By executing the Script, you can see that two lines of "Hello, World" characters are displayed together when using the "print" function.

criatom_tools_atomcraft_api_tutorial_hello_debug_module.png


Note
Differences between Python standard output print function and the Debug module log function
If you use the print function and the log function in the local execution of the Script from Run the Script from the Script Editor, both will be logged in the Script log and there is no distinct difference.
However, if you use the print function with Remote execution of Python script, the message will not be output to the CRI Atom Craft Script log, but the message will be output to the executing application.
This difference occurs because the "print" function is being processed by the Script execution application. Conversely, the log function only outputs to the Script log even during remote execution.

When working with CRI Atom Craft by Script remote execution from an external application, sometimes you may need to output logs in the external application.
You may choose to use the print function and log function respectively for different output destination.

[Example of remote execution: Execute the "print" function after connecting to CRI Atom Craft by remote execution from the terminal]
criatom_tools_atomcraft_api_tutorial_hello_terminal_and_log.png


Note
This tutorial introduced how to use the log function to output the log to display the characters "Hello, World".
If you write a Script to work with CRI Atom Craft, log output is often used mainly for debugging to check the processing during execution.
In addition to the log function, Debug Module also provides a "warning function" to output warnings.
Function name Description
log Outputs the standard log
warning Outputs the warning log
The highlighted log will be output
The character string output by the warning function is displayed in colored characters in the log view of CRI Atom Craft. (Colored output in the Script log is not supported)
Efficient Script execution confirmation can be performed by properly using the functions designed for each purpose.
criatom_tools_atomcraft_api_tutorial_debug_log.png