Restraints Script Examples#
Download the blankModel.rs3v3 for this example.
from rs3.RS3Modeler import RS3Modeler
from rs3.CommonEnums import *
import os
import shutil
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 = 60106
RS3Modeler.startApplication(port)
2026-03-13 17:02:26,734 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60106...
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.
blankModelPath = rf"{current_dir}\example_models\blankModel.rs3v3"
copiedModelPath = rf"{current_dir}\example_models\copiedModel.rs3v3"
_ = shutil.copy(blankModelPath, copiedModelPath)
Open the copied model file.
model = modeler.openFile(copiedModelPath)
1. Set and Delete Restraints#
restraints = model.Restraints
Check if the model has any restraints.
restraints.getIsRestraintsSet()
True
Delete any existing restraints.
restraints.deleteAllRestraints()
restraints.getIsRestraintsSet()
False
Set new auto-restraints.
restraints.setAutoRestraints(AutoRestraintsType.SURFACE_PINS)
restraints.getIsRestraintsSet()
True
2. Reset All Displacements#
Get stage names.
stages = model.ProjectSettings.Stages.getDefinedStageNames()
stages
['Stage 1', 'Stage 2', 'Stage 3', 'Stage 4', 'Stage 5']
Turn on reset displacements after stages.
restraints.setResetAllDisplacements(True, [stages[0], stages[3]])
Turn off reset all displacements.
restraints.setResetAllDisplacements(False)
Save and close the model.
model.close(True)
Close the program.
modeler.closeProgram()
Full Script#
# Restraints Script Examples
# Download the [blankModel.rs3v3](https://github.com/Rocscience/rs3-scripting/tree/main/docs/example_code/example_models/blankModel.rs3v3) for this example.
from rs3.RS3Modeler import RS3Modeler
from rs3.CommonEnums import *
import os
import shutil
# 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 = 60106
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.
blankModelPath = rf"{current_dir}\example_models\blankModel.rs3v3"
copiedModelPath = rf"{current_dir}\example_models\copiedModel.rs3v3"
_ = shutil.copy(blankModelPath, copiedModelPath)
# Open the copied model file.
model = modeler.openFile(copiedModelPath)
# 1. Set and Delete Restraints
restraints = model.Restraints
# Check if the model has any restraints.
print(restraints.getIsRestraintsSet())
# Delete any existing restraints.
restraints.deleteAllRestraints()
# Set new auto-restraints.
restraints.setAutoRestraints(AutoRestraintsType.SURFACE_PINS)
# 2. Reset All Displacements
# Get stage names.
stages = model.ProjectSettings.Stages.getDefinedStageNames()
# Turn on reset displacements after stages.
restraints.setResetAllDisplacements(True, [stages[0], stages[3]])
# Turn off reset all displacements.
restraints.setResetAllDisplacements(False)
# Save and close the model.
model.close(True)
2026-03-13 17:03:24,652 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60106...
True