Mesh Script Example#
Download the blankModel.rs3v3 for this example.
from rs3.RS3Modeler import RS3Modeler
from rs3.mesh.MeshEnums 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 = 60107
RS3Modeler.startApplication(port)
2026-03-13 16:51:54,882 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60107...
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 model file.
model = modeler.openFile(copiedModelPath)
1. Change Mesh Element Type#
Get the current mesh element type.
model.Mesh.getElementType()
<MeshElementType.MESH_4_NODED_TETRAHEDRA: 'TET4'>
Set the current mesh element type to 10 noded tetrahedra.
model.Mesh.setElementType(MeshElementType.MESH_10_NODED_TETRAHEDRA)
model.Mesh.getElementType()
<MeshElementType.MESH_10_NODED_TETRAHEDRA: 'TET10'>
2. Graded Mesh#
Set the mesh gradition to GRADED.
model.Mesh.setMeshGradation(MeshGradation.GRADED)
Check the current Graded mesh settings
model.Mesh.Graded.getProperties()
{'MinGradedElementSize': -1.0,
'MaxGradedElementSize': -1.0,
'OneDGradation': 0.5,
'TwoDGradation': 0.5,
'ThreeDGradation': 0.5}
Set individual properties.
model.Mesh.Graded.setMaxGradedElementSize(1.2)
model.Mesh.Graded.setMinGradedElementSize(0.5)
model.Mesh.Graded.getProperties()
{'MinGradedElementSize': 0.5,
'MaxGradedElementSize': 1.2,
'OneDGradation': 0.5,
'TwoDGradation': 0.5,
'ThreeDGradation': 0.5}
Set properties all in once.
model.Mesh.Graded.setProperties(OneDGradation=0.1, TwoDGradation=0.2, ThreeDGradation=0.3)
model.Mesh.Graded.getProperties()
{'MinGradedElementSize': 0.5,
'MaxGradedElementSize': 1.2,
'OneDGradation': 0.1,
'TwoDGradation': 0.2,
'ThreeDGradation': 0.3}
3. Uniformed Mesh#
Set the mesh gradation to UNIFORM.
model.Mesh.setMeshGradation(MeshGradation.UNIFORM)
Tip: create a short alias to avoid repeatedly typing model.Mesh.Uniform
uniformMesh = model.Mesh.Uniform
Check current Properties.
uniformMesh.getMeshDensity()
<MeshDensity.LOW: 'LOW'>
uniformMesh.getUniformMeshElementSize()
2.7095086413377265
uniformMesh.setMeshDensity(MeshDensity.HIGH)
uniformMesh.getMeshDensity()
<MeshDensity.HIGH: 'HIGH'>
uniformMesh.getUniformMeshElementSize()
0.451584773556288
uniformMesh.setMeshDensity(MeshDensity.USER_DEFINED)
uniformMesh.setUniformMeshElementSize(3.5)
uniformMesh.getMeshDensity()
<MeshDensity.USER_DEFINED: 'USERDEFINED'>
uniformMesh.getUniformMeshElementSize()
3.5
uniformMesh.setMeshDensity(MeshDensity.LOW)
uniformMesh.getMeshDensity()
<MeshDensity.LOW: 'LOW'>
uniformMesh.getUniformMeshElementSize()
3.5
4. Mesh the model#
model.Mesh.mesh()
Save and close the model.
model.close(True)
Close the program.
modeler.closeProgram()
Full Script#
# Mesh Script Example
# 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.mesh.MeshEnums 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 = 60107
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 model file.
model = modeler.openFile(copiedModelPath)
# 1. Change Mesh Element Type
# Set the current mesh element type to 10 noded tetrahedra.
model.Mesh.setElementType(MeshElementType.MESH_10_NODED_TETRAHEDRA)
# 2. Graded Mesh
# Set the mesh gradition to GRADED.
model.Mesh.setMeshGradation(MeshGradation.GRADED)
# Set individual properties.
model.Mesh.Graded.setMaxGradedElementSize(1.2)
model.Mesh.Graded.setMinGradedElementSize(0.5)
# Set properties all in once.
model.Mesh.Graded.setProperties(OneDGradation=0.1, TwoDGradation=0.2, ThreeDGradation=0.3)
# 3. Uniformed Mesh
# Set the mesh gradation to UNIFORM.
model.Mesh.setMeshGradation(MeshGradation.UNIFORM)
# Create a short alias to avoid repeatedly typing model.Mesh.Uniform
uniformMesh = model.Mesh.Uniform
uniformMesh.getUniformMeshElementSize()
uniformMesh.setMeshDensity(MeshDensity.HIGH)
uniformMesh.setMeshDensity(MeshDensity.USER_DEFINED)
uniformMesh.setUniformMeshElementSize(3.5)
uniformMesh.setMeshDensity(MeshDensity.LOW)
# 4. Mesh the model
model.Mesh.mesh()
# Save and close the model.
model.close(True)
2026-03-13 16:52:49,009 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60107...