Python Console and How to Execute Scripts
Accessible from the Flame menu, the Flame Python Console is your main tool when using the Python API. It allows you to write, edit, and run code, while being able to view the console output. The major parts are discussed in this section.
Console windows:
- Terminal Window: This is where any output from your code will be shown. The terminal is useful when debugging an error, you will get a detailed report of the error within the console (in a red font). This is also the place where any "print()" command or any calls to the help() function will be outputted.
- Editor Window: The Editor window is a simple text editor used to write or edit your Python scripts. The editor has the feature of being able to have multiple tabs of Python Script files; you can access the multiple tabs underneath the editor's window. To create a new tab, simply click the 'plus' (+) sign in the bottom right corner of the Python Console.
Executing Scripts
There are two ways to execute Python API scripts in Flame.
The Python API allows a user to run a script when the project is loaded by defining what script should be run when starting flame from the command line.
Running a script at Startup
Launch Flame from the command line with
/opt/Autodesk/<version>/bin/startApplication
To define a script to be ran at startup, append the -s argument to the
startApplication
command and then include a valid path to a valid Python script.Example:
/opt/Autodesk/<version>/bin/startApplication -s /home/user/scripts/onStart.py
There are two ways to execute code from within the Python Console.
Running a script from the console:
- By Script: Clicking the 'Play' button within the Python Console will run the entire script (start to finish) that is open in the current tab of the Editor.
- By Selection: With a section of the script highlighted, using the 'Play' button within the Python Console will only execute the selected parts of the code.