Beam Script Examples#
Download the blankModel.rs3v3 for this example.
from rs3.RS3Modeler import RS3Modeler
from rs3.properties.PropertyEnums import *
import os
import shutil
Get the current folder directory.
current_dir = os.path.abspath("")
Specify a port number that is not in use and start the RS3 program.
port = 60301
RS3Modeler.startApplication(port)
2026-03-13 17:14:51,760 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60301...
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"{os.path.dirname(current_dir)}\example_models\blankModel.rs3v3"
copiedModelPath = rf"{os.path.dirname(current_dir)}\example_models\copiedModel.rs3v3"
_ = shutil.copy(blankModelPath, copiedModelPath)
Open the copied model file.
model = modeler.openFile(copiedModelPath)
1. Create and Get Beam#
Get the first beam in the list.
beam1 = model.getAllBeamProperties()[0]
beam1.getBeamName()
'Beam 1'
Create a new beam and get the beam by name.
beam2Name = "Beam 2"
model.createNewBeamProperty(beam2Name)
beam2 = model.getBeamPropertyByName(beam2Name)
beam2.getBeamName()
'Beam 2'
2. Set Beam Properties#
beam1.setBeamType(BeamType.TRUSS)
beam1.getBeamType()
<BeamType.TRUSS: 'TRUSS'>
beam1.Truss.getProperties()
{'YoungsModulus': 30000000.0,
'PoissonsRatio': 0.2,
'ShearStrength': 5000.0,
'Area': 0.5,
'UnitWeight': 20.0,
'PreTensioning': False,
'PreTensioningForce': 0.0,
'IncludeWeightInStressAnalysis': False,
'CompressiveStrength': 35000.0,
'TensileStrength': 5000.0,
'ResidualCompressiveStrength': 5000.0,
'ResidualTensileStrength': 0.0}
beam1.Truss.setMaterialType(MaterialType.PLASTIC)
beam1.Truss.getMaterialType()
<MaterialType.PLASTIC: True>
beam1.Truss.setProperties(Area=0.2, UnitWeight=15.1)
beam1Properties = beam1.Truss.getProperties()
beam1Properties
{'YoungsModulus': 30000000.0,
'PoissonsRatio': 0.2,
'ShearStrength': 5000.0,
'Area': 0.2,
'UnitWeight': 15.1,
'PreTensioning': False,
'PreTensioningForce': 0.0,
'IncludeWeightInStressAnalysis': False,
'CompressiveStrength': 35000.0,
'TensileStrength': 5000.0,
'ResidualCompressiveStrength': 5000.0,
'ResidualTensileStrength': 0.0}
3. Copy Beam Properties#
beam2.setBeamType(BeamType.TRUSS)
beam2.getBeamType()
<BeamType.TRUSS: 'TRUSS'>
beam2.Truss.getProperties()
{'YoungsModulus': 30000000.0,
'PoissonsRatio': 0.2,
'ShearStrength': 5000.0,
'Area': 0.5,
'UnitWeight': 20.0,
'PreTensioning': False,
'PreTensioningForce': 0.0,
'IncludeWeightInStressAnalysis': False,
'CompressiveStrength': 35000.0,
'TensileStrength': 5000.0,
'ResidualCompressiveStrength': 5000.0,
'ResidualTensileStrength': 0.0}
beam2.Truss.setProperties(**beam1Properties)
beam2.Truss.getProperties()
{'YoungsModulus': 30000000.0,
'PoissonsRatio': 0.2,
'ShearStrength': 5000.0,
'Area': 0.2,
'UnitWeight': 15.1,
'PreTensioning': False,
'PreTensioningForce': 0.0,
'IncludeWeightInStressAnalysis': False,
'CompressiveStrength': 35000.0,
'TensileStrength': 5000.0,
'ResidualCompressiveStrength': 5000.0,
'ResidualTensileStrength': 0.0}
4. Set Stage Factors#
Turn on the stage factors of beams.
beam1.setApplyStageFactors(True)
Now, create a stage factor object for stage 2.
beamStageFactors_s2 = beam1.Truss.StageFactorInterface.createStageFactor(2)
Get the current stage factor of compressive strength.
beamStageFactors_s2.getCompressiveStrengthFactor()
1.0
Set stage factor of compressive strength.
beamStageFactors_s2.setCompressiveStrengthFactor(1.43)
Get stage factors of all stages and check stage factor of compressive strength at stage 2.
stageFactors_s2 = beam1.Truss.StageFactorInterface.getStageFactor(2)
stageFactors_s2.getCompressiveStrengthFactor()
1.43
Create another stage factor for stage 4 and set the stage factor of compressive strength.
beam1.Truss.StageFactorInterface.createStageFactor(4)
beamStageFactors_s4 = beam1.Truss.StageFactorInterface.getDefinedStageFactors()[4]
beamStageFactors_s4.setCompressiveStrengthFactor(2.1)
beamStageFactors_s4.getCompressiveStrengthFactor()
2.1
5. Delete Beam Stage Factor#
Get the dictionary of all stage factors.
beamStageFactors = beam1.Truss.StageFactorInterface.getDefinedStageFactors()
beamStageFactors
{2: <rs3.properties.beam.BeamCommon.BeamCommonDefinedStageFactor at 0x2c13b82bce0>,
4: <rs3.properties.beam.BeamCommon.BeamCommonDefinedStageFactor at 0x2c14b590050>}
Remove stage factors at stage 4.
beamStageFactors.pop(4)
<rs3.properties.beam.BeamCommon.BeamCommonDefinedStageFactor at 0x2c14b590050>
Set the dictionary back and check the defined stage factors. Now only stage 2 has stage factors defined.
beam1.Truss.StageFactorInterface.setDefinedStageFactors(beamStageFactors)
beam1.Truss.StageFactorInterface.getDefinedStageFactors()
{2: <rs3.properties.beam.BeamCommon.BeamCommonDefinedStageFactor at 0x2c13b917130>}
6. Delete Beam#
Delete beam2.
model.deleteBeamProperty(beam2Name)
Check if beam2 still exist in the beam list.
allBeams = model.getAllBeamProperties()
for beam in allBeams:
print(beam.getBeamName())
Beam 1
Save and close the model.
model.close(True)
Close the program.
modeler.closeProgram()
Full Script#
# Beam 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.properties.PropertyEnums import *
import os
import shutil
# Get the current folder directory.
current_dir = os.path.abspath("")
# Specify a port number that is not in use and start the RS3 program.
port = 60301
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"{os.path.dirname(current_dir)}\example_models\blankModel.rs3v3"
copiedModelPath = rf"{os.path.dirname(current_dir)}\example_models\copiedModel.rs3v3"
_ = shutil.copy(blankModelPath, copiedModelPath)
# Open the copied model file.
model = modeler.openFile(copiedModelPath)
# 1. Create and Get Beam
# Get the first beam in the list.
beam1 = model.getAllBeamProperties()[0]
# Create a new beam and get the beam by name.
beam2Name = "Beam 2"
model.createNewBeamProperty(beam2Name)
beam2 = model.getBeamPropertyByName(beam2Name)
# 2. Set Beam Properties
beam1.setBeamType(BeamType.TRUSS)
beam1.Truss.setMaterialType(MaterialType.PLASTIC)
beam1.Truss.setProperties(Area=0.2, UnitWeight=15.1)
beam1Properties = beam1.Truss.getProperties()
# 3. Copy Beam Properties
beam2.setBeamType(BeamType.TRUSS)
beam2.Truss.setProperties(**beam1Properties)
# 4. Set Stage Factors
# Turn on the stage factors of beams.
beam1.setApplyStageFactors(True)
# Now, create a stage factor object for stage 2.
beamStageFactors_s2 = beam1.Truss.StageFactorInterface.createStageFactor(2)
# Set stage factor of compressive strength.
beamStageFactors_s2.setCompressiveStrengthFactor(1.43)
# Get stage factors of all stages and check stage factor of compressive strength at stage 2.
stageFactors_s2 = beam1.Truss.StageFactorInterface.getStageFactor(2)
# Create another stage factor for stage 4 and set the stage factor of compressive strength.
beam1.Truss.StageFactorInterface.createStageFactor(4)
beamStageFactors_s4 = beam1.Truss.StageFactorInterface.getDefinedStageFactors()[4]
beamStageFactors_s4.setCompressiveStrengthFactor(2.1)
# 5. Delete Beam Stage Factor
# Get the dictionary of all stage factors.
beamStageFactors = beam1.Truss.StageFactorInterface.getDefinedStageFactors()
# Remove stage factors at stage 4.
beamStageFactors.pop(4)
# Set the dictionary back and check the defined stage factors. Now only stage 2 has stage factors defined.
beam1.Truss.StageFactorInterface.setDefinedStageFactors(beamStageFactors)
# 6. Delete Beam
# Delete beam2.
model.deleteBeamProperty(beam2Name)
# Check if beam2 still exist in the beam list.
allBeams = model.getAllBeamProperties()
for beam in allBeams:
print(beam.getBeamName())
# Save and close the model.
model.close(True)
2026-03-13 17:15:45,620 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60301...
Beam 1