Export Image Script Examples#
Download the ExampleExportImage.fez for this example.
The ExportImage function on the Interpreter model exports the current view to an image file.
Workflow:
Open and compute the model using the Modeler.
Open the computed model in the Interpreter.
Use
SetActiveStage(stageNumber)to select which stage to display.Use
SetResultType(ExportResultType)to choose the result type to visualize.Use
ExportImage(filePath)to save the current view as a.pngimage.
from rs2.modeler.RS2Modeler import RS2Modeler
from rs2.interpreter.RS2Interpreter import RS2Interpreter
from rs2.interpreter.InterpreterEnums import *
import os
current_dir = os.path.dirname(os.path.abspath(""))
output_dir = os.path.join(current_dir, "export_images")
os.makedirs(output_dir, exist_ok=True)
RS2Modeler.startApplication(port=60097)
modeler = RS2Modeler(port=60097)
model = modeler.openFile(rf"{current_dir}\example_models\ExampleExportImage.fez")
model.compute()
model.close()
RS2Interpreter.startApplication(port=60098)
interpreter = RS2Interpreter(port=60098)
interpreterModel = interpreter.openFile(rf"{current_dir}\example_models\ExampleExportImage.fez")
stages = [1, 2]
result_types = [
(ExportResultType.SOLID_EFFECTIVE_STRESS_EFFECTIVE_SIGMA_Z, "effective_sigma_z"),
(ExportResultType.SOLID_DISPLACEMENT_TOTAL_DISPLACEMENT, "total_displacement"),
]
for stage in stages:
interpreterModel.SetActiveStage(stage)
for result_type, result_name in result_types:
interpreterModel.SetResultType(result_type)
image_path = os.path.join(output_dir, f"stage_{stage}_{result_name}.png")
interpreterModel.ExportImage(image_path)
print(f"Exported: stage_{stage}_{result_name}.png")
interpreterModel.close()
modeler.closeProgram()
interpreter.closeProgram()
Exported: stage_1_effective_sigma_z.png
Exported: stage_1_total_displacement.png
Exported: stage_2_effective_sigma_z.png
Exported: stage_2_total_displacement.png