Composite Liner Result Script Example#
Download the RS3_Result_Scripting_Example folder for this example.
from rs3.RS3Modeler import RS3Modeler
from rs3.results.ResultEnums import LinerResultTypes
from rs3.Geometry import Point, Cube
import os
Get the current folder directory.
current_dir = os.path.dirname(os.path.abspath(""))
Specify a port number that is not in use and start the RS3 program.
port = 60506
RS3Modeler.startApplication(port)
2026-03-13 17:08:03,903 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60506...
Connect with the RS3 Modeler.
modeler = RS3Modeler(port)
For the demonstration purposes only, the model is copied for reuse. You may change the model path to your own model path.
model = modeler.openFile(rf"{current_dir}\example_models\RS3_Result_Scripting_Example\RS3_Result_Scripting_Example.rs3v3")
1. Get Node Results#
1.1 Define a box region to filter liner elements (optional)#
A cube region is defined by two corners. Only mesh nodes inside or intersecting the box will be returned. If you omit the region in the next step, all nodes in the model would be returned.
In this example, the middle part of the tunnel will be queried.
liner_query_region = Cube(
corner1=Point(x=8.5, y=14.5, z=-8.5),
corner2=Point(x=11.5, y=15.5, z=-11.5),
)
1.2 Get the liner results object for the desired stage(s)#
getCompositeLinerResults returns a list: one entry per stage requested. Here we request only stage 3, so the list has one element at index 0.
liner_results_list = model.Results.getCompositeLinerResults(stageNumber=[3])
liner_results_stage_3 = liner_results_list[0]
1.3 Get all liner node results for this stage#
No region is passed, so we get nodes for the all liner in this stage.
liner_node_results_list = liner_results_stage_3.getLinerNodeResults()
Build a lookup: NodeID -> nodal result object. This is used later to get coordinates for each node attached to an element.
liner_node_by_id = {nr.NodeID: nr for nr in liner_node_results_list}
1.4 Get liner element results within the region#
liner_element_results_list = liner_results_stage_3.getLinerElementResults(region=liner_query_region)
1.5 Take one element and read its per-node result values#
Each element has attached nodes. getResults(…) returns a list of values, one per node of the element (in the same order as AttachedNodeIDs).
element_index = 0
selected_liner_element = liner_element_results_list[element_index]
attached_node_ids = selected_liner_element.AttachedNodeIDs
total_disp_per_node = selected_liner_element.getResults(LinerResultTypes.TOTAL_DISPLACEMENT)
moment_y_per_node = selected_liner_element.getResults(LinerResultTypes.MOMENT_YY)
print(f"Liner element ID {selected_liner_element.ElementID}, nodal results:")
for i in range(len(attached_node_ids)):
node_id = attached_node_ids[i]
nodal_result = liner_node_by_id[node_id]
print(
f" Node {node_id}: (x, y, z, Total Displacement, Moment YY) = "
f"({nodal_result.XCoordinate}, {nodal_result.YCoordinate}, {nodal_result.ZCoordinate}, "
f"{total_disp_per_node[i]}, {moment_y_per_node[i]})"
)
Liner element ID 81643, nodal results:
Node 2375: (x, y, z, Total Displacement, Moment YY) = (10.368124552684677, 15.559329226663175, -9.070223514111749, 0.017510250963789133, 0.3562554391291303)
Node 2622: (x, y, z, Total Displacement, Moment YY) = (10.587785252292472, 15.559329226663177, -9.190983005625052, 0.01659801477075613, 0.3562554391291307)
Node 2621: (x, y, z, Total Displacement, Moment YY) = (10.587785252292472, 15.27928756138166, -9.190983005625052, 0.016808917305162055, 0.3562554391291303)
Since accessing results doesn’t change the model, close the model without saving.
model.close(False)
Close the program.
modeler.closeProgram()
Full Script#
# Composite Liner Result Script Example
# Download the [RS3_Result_Scripting_Example folder](https://github.com/Rocscience/rs3-scripting/tree/main/docs/example_code/example_models/RS3_Result_Scripting_Example) for this example.
from rs3.RS3Modeler import RS3Modeler
from rs3.results.ResultEnums import LinerResultTypes
from rs3.Geometry import Point, Cube
import os
# Get the current folder directory.
current_dir = os.path.dirname(os.path.abspath(""))
# Specify a port number that is not in use and start the RS3 program.
port = 60506
RS3Modeler.startApplication(port)
# Connect with the RS3 Modeler.
modeler = RS3Modeler(port)
# For the demonstration purposes only, the model is copied for reuse.
# You may change the model path to your own model path.
model = modeler.openFile(rf"{current_dir}\example_models\RS3_Result_Scripting_Example\RS3_Result_Scripting_Example.rs3v3")
# 1. Get Node Results
# 1.1 Define a box region to filter liner elements (optional)
# A cube region is defined by two corners. Only mesh nodes inside or
# intersecting the box will be returned. If you omit the region in the next
# step, all nodes in the model would be returned.
# In this example, the middle part of the tunnel will be queried.
liner_query_region = Cube(
corner1=Point(x=8.5, y=14.5, z=-8.5),
corner2=Point(x=11.5, y=15.5, z=-11.5),
)
# 1.2 Get the liner results object for the desired stage(s)
# getCompositeLinerResults returns a list: one entry per stage requested.
# Here we request only stage 3, so the list has one element at index 0.
liner_results_list = model.Results.getCompositeLinerResults(stageNumber=[3])
liner_results_stage_3 = liner_results_list[0]
# 1.3 Get all liner node results for this stage
# No region is passed, so we get nodes for the all liner in this stage.
liner_node_results_list = liner_results_stage_3.getLinerNodeResults()
# Build a lookup: NodeID -> nodal result object. This is used later to get
# coordinates for each node attached to an element.
liner_node_by_id = {nr.NodeID: nr for nr in liner_node_results_list}
# 1.4 Get liner element results within the region
liner_element_results_list = liner_results_stage_3.getLinerElementResults(region=liner_query_region)
# 1.5 Take one element and read its per-node result values
# Each element has attached nodes. getResults(...) returns a list of values,
# one per node of the element (in the same order as AttachedNodeIDs).
element_index = 0
selected_liner_element = liner_element_results_list[element_index]
attached_node_ids = selected_liner_element.AttachedNodeIDs
total_disp_per_node = selected_liner_element.getResults(LinerResultTypes.TOTAL_DISPLACEMENT)
moment_y_per_node = selected_liner_element.getResults(LinerResultTypes.MOMENT_YY)
print(f"Liner element ID {selected_liner_element.ElementID}, nodal results:")
for i in range(len(attached_node_ids)):
node_id = attached_node_ids[i]
nodal_result = liner_node_by_id[node_id]
print(
f" Node {node_id}: (x, y, z, Total Displacement, Moment YY) = "
f"({nodal_result.XCoordinate}, {nodal_result.YCoordinate}, {nodal_result.ZCoordinate}, "
f"{total_disp_per_node[i]}, {moment_y_per_node[i]})"
)
# Since accessing results doesn't change the model, close the model without saving.
model.close(False)
2026-03-13 17:08:53,394 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60506...
Liner element ID 81643, nodal results:
Node 2375: (x, y, z, Total Displacement, Moment YY) = (10.368124552684677, 15.559329226663175, -9.070223514111749, 0.017510250963789133, 0.3562554391291303)
Node 2622: (x, y, z, Total Displacement, Moment YY) = (10.587785252292472, 15.559329226663177, -9.190983005625052, 0.01659801477075613, 0.3562554391291307)
Node 2621: (x, y, z, Total Displacement, Moment YY) = (10.587785252292472, 15.27928756138166, -9.190983005625052, 0.016808917305162055, 0.3562554391291303)