Skip to content

Scripting

Script view

The script editor view comprises of scripts list, extra input files and the main code editor.

If you are working with a regular project, the scripting mode is by default in preview mode. The contents will update whenever you make changes to the project configuration.

The auto-generated scripts make the regions, materials and shared expressions defined in the GUI easily available in your custom scripts.

Initial scripts view
Scripting view in preview mode

You can at any time activate project scripting mode by toggling it on from Scripting mode switch.

Once in scripting mode, you take full control over the simulation.py file. The autogenerated files will still update if you, for example, update your shared expressions or regions.

Scripting active
Scripting view with activated scripting mode

The simulation.py file acts as the primary entry point for the simulation and initially contains the generated (if any defined in the GUI) physics. It is also possible to split your simulation into multiple modules by adding new files in “your scripts” -section.

Scripting mode can be disabled at any time which causes any user made changes to be lost. You can also press the Refresh button to update the script with the current project state.

To make modifications to an existing script, select the script from the list and edit the contents as necessary. You can rename a script by double-clicking its name in the list. The autogenerated scripts can not be modified.

Extra input files

Input files such as custom mesh files and CSV files can be utilized within your script. You can upload files to be used only in single simulations or use existing project level shared files by selecting them.

Script editor

Several useful features are available in the script editor to aid the coding process, including syntax error checking, which alerts you to any errors in the code. Code autocomplete tool is also provided for easy access to the API and its reference documentation.

The script autocomplete function in Quanscient Allsolve supports:

  • In the code editor, you can use the intelligent autocompletes by hovering over function names to see their documentation.
  • Use the control space key to quickly fill in function names, properties, and parameters by accessing the autocomplete model.
  • Utilize the Python snippets provided, such as try/except for error handling and a transient snippet for simulating over time.

How to use more advanced scripting features

The script editor allows folding blocks for any indentation in Python code.

By double-clicking on a word, it can be highlighted across the entire script.

Search function which can be accessed by pressing the control or command F keys while the editor is active. This function allows for searching a specific word within the script and navigating through the search results using the arrow keys or the ‘All’ button.

While search bar is active, replace function within the search function can be accessed, allowing to replace a single occurrence or all occurrences of a specific string by clicking the plus button. Both search and replace support text and regular expressions.

Multi-cursor mode which can be enabled by pressing the alt or option key and dragging.

The control Z key can be used to undo the change or use the shift key to redo it if a mistake is made.

Outputs from simulation Script

If you want to print something to simulation logs from the script, use the print() function.