Run script at startup
To specify a script to be executed at startup, open Edit > Preferences > Python > Startup. Enable the Run python script on startup checkbox and specify which script should be run in the Workspace Path field. The script is run in the environment specified by its project, both Python 3 and Jython environments are supported.
startup.py (Jython only)
Note:
startup.py is only run if the Run python script on startupcheckbox (see above) is disabled.
If the file startup.py exists in the current CityEngine workspace root, it will be executed automatically during CityEngine startup. Typical use cases for the startup script is running automated tasks with CityEngine. In the example below, a Python script defining an automation job is automatically executed after startup.
if __name__ == '__startup__':
sys.path.append(ce.toFSPath("automationProject/scripts"))
import automationJob
automationJob.run()Note:
Make sure startup.py is well formed and does not contain errors. An incorrect startup.py can prevent the main scripting module from being parsed, and can prevent correct execution of the scripting interface.
Initial Commands in the Interactive Console
To simplify working with interactive consoles, initial commands can be specified that will be executed in every new interactive console. These commands can be changed in Edit > Preferences > Python > Interactive Console > Initial Commands.
CityEngine comes with default initial commands that load the cityengine package and creates an instance of the CE object under the name ce.
Note:
These initial commands will be run in interactive consoles of any environment. Make sure the code is compatible both with Jython and Python 3. You can check if Jython is active by evaluating sys.platform.startswith('java').
scripting.py (Jython only)
If the file scripting.py exists in the current CityEngine workspace root, its content will be appended to the end of the main CityEngine scripting module with the same name. The from scripting import * command is automatically executed when a new Python console is opened and added to each new Python file created in within CityEngine. Typical use cases include adding your scripting directory to the system path, or loading your custom modules to the scripting environment.
Note:
CityEngine needs to be restarted in order to load changes in the file scripting.py. Make sure scripting.py is well formed and does not contain errors. An incorrect scripting.py can prevent the main scripting module from being parsed, and can prevent correct execution of the scripting interface.
See also