Restraints Script Examples#

Download the ExampleAutoRestraint.fez for this example.

The Restraints class is accessed via model.getRestraintsProperty() and provides the following functions:

  • setResetAllDisplacementsByIndices(resetDisplacementsAfterStages, stageIndices) — Enable or disable reset all displacements and define stage indices (1-based).

  • getResetAllDisplacementsByIndices() — Returns a tuple of (bool, list[int]) indicating whether reset is enabled and which stage indices are selected.

  • setResetAllDisplacementsByNames(resetDisplacementsAfterStages, stageNames) — Same as above but using stage names instead of indices.

  • getResetAllDisplacementsByNames() — Returns a tuple of (bool, list[str]).

  • setAutoRestraints(autoRestraintType) — Applies one of the automatic boundary restraint modes: UNDERGROUND, SURFACE_PINS, or SURFACE_ROLLERS.

from rs2.modeler.RS2Modeler import RS2Modeler
from rs2.modeler.properties.PropertyEnums import AutoRestraintsType
import os

current_dir = os.path.dirname(os.path.abspath(""))
RS2Modeler.startApplication(port=60096)
modeler = RS2Modeler(port=60096)
model = modeler.openFile(rf"{current_dir}\example_models\ExampleAutoRestraint.fez")

restraints = model.getRestraintsProperty()

# Reset All Displacements by stage indices (1-based)
restraints.setResetAllDisplacementsByIndices(True, [1, 2])
is_enabled, indices = restraints.getResetAllDisplacementsByIndices()
print(f"Reset by indices — Enabled: {is_enabled}, Stages: {indices}")

# Reset All Displacements by stage names
restraints.setResetAllDisplacementsByNames(True, ["Stage 1", "Stage 2"])
is_enabled, names = restraints.getResetAllDisplacementsByNames()
print(f"Reset by names   — Enabled: {is_enabled}, Names: {names}")

# Verify the same configuration via the index getter
is_enabled, indices = restraints.getResetAllDisplacementsByIndices()
print(f"Verify by index  — Enabled: {is_enabled}, Stages: {indices}")

# Disable reset displacements by passing False
restraints.setResetAllDisplacementsByIndices(False, [])
is_enabled, indices = restraints.getResetAllDisplacementsByIndices()
print(f"After disable    — Enabled: {is_enabled}, Stages: {indices}")

# Apply automatic boundary restraints
restraints.setAutoRestraints(AutoRestraintsType.UNDERGROUND)
print("\nApplied auto restraint: UNDERGROUND")

restraints.setAutoRestraints(AutoRestraintsType.SURFACE_PINS)
print("Applied auto restraint: SURFACE_PINS")

restraints.setAutoRestraints(AutoRestraintsType.SURFACE_ROLLERS)
print("Applied auto restraint: SURFACE_ROLLERS")

model.close()
modeler.closeProgram()
Reset by indices — Enabled: True, Stages: [1, 2]
Reset by names   — Enabled: True, Names: ['Stage 1', 'Stage 2']
Verify by index  — Enabled: True, Stages: [1, 2]
After disable    — Enabled: False, Stages: []

Applied auto restraint: UNDERGROUND
Applied auto restraint: SURFACE_PINS
Applied auto restraint: SURFACE_ROLLERS