Rocscience International Conference 2025 is going to take place in Sydney, Australia Read more

Search Results

Getting Started with RS2 Python Scripting

Welcome to RS2 Scripting!

In this guide, we will walk you through the setup process. Follow these steps to run your first Python script for RS2.

Prerequisites

Before you begin, ensure you have RS2 program installed.

Python Environment

There are two methods to run a script, differing in the Python environment used:

  1. Running on RocScript Editor
    • comes pre-installed with RS2 and includes the RS2 Python API library
    • For all-level users
  2. Running on your own Python environment
    • Requires downloading the RS2 Python API library
    • For advanced users.

Each method is detailed below.

Method 1: Using RocScript

Step 1: Opening the editor

Select the Open Scripting Editor option from the Scripting menu (see the screenshot below) in either RS2 Modeler or RS2 Interpret program. The RocScript Editor will be prompted.

open scripting editor option

For more information about other options, see the topic here.

You can also open the RocScript Editor from the start menu:

Rocscript from start menu

Step 2: Open a File

Open a file from the RocScript Editor. Select the Open File option under the File menu:

VSCodium open file

Select the helloScripting.py python file from the tutorial folder directory:

C:\Users\Public\Documents\Rocscience\RS2 Examples\Tutorials\Scripting\HelloScripting\helloScripting.py

If you provided a custom location for examples when installing RS2, search the provided location instead.

Step 3 (Optional): Install Libraries

Select the Manage Python Environment option from the Scripting menu in either RS2 Modeler or RS2 Interpret program, as shown below.

manage python environ_option

The RocScript WinPython Command Prompt will open:

Rocscript cmd

Check the installed libraries with the command:

pip list

Pre-installed libraries include the RS2 Python API Library (i.e., RS2Scripting on the list) and two common python libraries: Pandas and Matplotlib.

If you wish to install more libraries, use the command to do so:

pip install [library name]

Step 4: Run the File

To run the file, click on the play button at the top right of the window:

Run button

The helloScripting.py script showcases a simple application of RS2 Scripting. Utilizing functions from the RS2 Python API library, it initiates the RS2 Modeler and a server at port 60054, opens the Getting Started (Initial).fez RS2 model file, modifies a material property value, saves the file and computed. Then, the RS2 Interpret and a server at port 60055 are launched. The computed file is opened, displaying the specified contour data.

Files are located at: C:\Users\Public\Documents\Rocscience\RS2 Examples\Tutorials\Scripting

Method 2: Using your Own Environment

The python environment is made up of two parts which need to be installed:

  1. The Python interpreter (Step 1 below)
  2. The Code Editor (Step 2 below)

Step 1: Install Python

Navigate to the 3.11.4 release page, scroll down and select 'Windows installer (64-bit)'.

python install_webpage

Run the installer. Keep the defaults and select 'Install Now'. Installation should complete successfully.

Note that any version of python above 3.7 should work, but 3.11.4 was the most thoroughly tested.

Step 2: Install a Python Code Editor

Any code editor can be used, but we recommend you use Visual Studio Code. Navigate to the download page and select the windows option:

https://code.visualstudio.com/download

vscode install_webpage

Step 3: Configure Editor for Python

Visual Studio Code has extensions which can be installed. Navigate to the 'Extensions' pane and search for python. Install the python extension. Restart VSCode.

install python extension

Step 4: Install the RS2 Library

In VSCode, select the Terminal option under the View menu to open a terminal.

terminal option

Install the library using pip, which is a package manager that comes with python:

pip install RS2Scripting 

If you are not using the latest release of RS2, you need to specify a library version that matches your rs2 version. For example:

pip install "RS2Scripting==11.23.0"

To find a list of available versions, see Release History.

You can find your version of RS2 by going to Help > About RS2 in the program.

about rs2 option

The RS2 Python API Library is now installed.

Step 5: Open a File

In VSCode, select the Open File option under the File menu:

vscode_open file

Select the helloScripting.py python file from the tutorial folder directory:

C:\Users\Public\Documents\Rocscience\RS2 Examples\Tutorials\Scripting\HelloScripting\helloScripting.py

If you provided a custom location for examples when installing RS2, search the provided location instead.

Step 6: Run the file

To run the file, click on the play button at the top right of the window:

run button

The helloScripting.py script showcases a simple application of RS2 Scripting. Utilizing functions from the RS2 Python API library, it initiates the RS2 Modeler and a server at port 60054, opens the Getting Started (Initial).fez RS2 model file, modifies a material property value, saves the file and computed. Then, the RS2 Interpret and a server at port 60055 are launched. The computed file is opened, displaying the specified contour data.

Files are located at: C:\Users\Public\Documents\Rocscience\RS2 Examples\Tutorials\Scripting

You’ve successfully set up your Python environment to use RS2 Scripting. You can build your own python scripts for RS2 now!

Resources

More resources are provided, including:

Rocscience logo, click here to return to the homepage Portal Account Portal Account Log In Log Out Home Shopping Cart icon Click here to search our site Click here to close Learning Tech Support Documentation Info Chevron Delete Back to Top View More" Previous Next PDF File Calendar Location Language Fees Video Click here to visit Rocscience's LinkedIn page Click here to visit Rocscience's YouTube page Click here to visit Rocscience's X page Click here to visit Rocscience's Facebook page Click here to visit Rocscience's Instagram page Click here to visit Rocscience's Reddit page Bookmark Network Scroll down for more Checkmark Download Print Back to top Single User Multiple Users RSLog RocFall3 CPillar Dips EX3 RocFall RocPlane RocSlope3 RocSupport RocTopple RS2 RS3 RSData RSPile Settle3 Slide2 Slide3 SWedge UnWedge RocTunnel RocSlope2 Commercial License Education License Trial License Shop safe & secure Money-back guarantee