{ "cells": [ { "cell_type": "markdown", "id": "95b0e0db", "metadata": { "papermill": { "duration": 0.000913, "end_time": "2026-07-17T15:59:34.002445", "exception": false, "start_time": "2026-07-17T15:59:34.001532", "status": "completed" }, "tags": [] }, "source": [ "(Export Image Example)=\n", "# Export Image Script Examples" ] }, { "cell_type": "markdown", "id": "2107f869", "metadata": { "papermill": { "duration": 0.000694, "end_time": "2026-07-17T15:59:34.003998", "exception": false, "start_time": "2026-07-17T15:59:34.003304", "status": "completed" }, "tags": [] }, "source": [ "Download the [ExampleExportImage.fez](https://github.com/Rocscience/rs2-scripting/blob/main/docs/example_code/example_models/ExampleExportImage.fez) for this example." ] }, { "cell_type": "markdown", "id": "809c7d67", "metadata": { "papermill": { "duration": 0.000503, "end_time": "2026-07-17T15:59:34.005153", "exception": false, "start_time": "2026-07-17T15:59:34.004650", "status": "completed" }, "tags": [] }, "source": [ "The `ExportImage` function on the Interpreter model exports the current view to an image file.\n", "\n", "**Workflow:**\n", "1. Open and compute the model using the **Modeler**.\n", "2. Open the computed model in the **Interpreter**.\n", "3. Use **`SetActiveStage(stageNumber)`** to select which stage to display.\n", "4. Use **`SetResultType(ExportResultType)`** to choose the result type to visualize.\n", "5. Use **`ExportImage(filePath)`** to save the current view as a `.png` image." ] }, { "cell_type": "code", "execution_count": 1, "id": "7a87f100", "metadata": { "execution": { "iopub.execute_input": "2026-07-17T15:59:34.007071Z", "iopub.status.busy": "2026-07-17T15:59:34.006900Z", "iopub.status.idle": "2026-07-17T15:59:45.623110Z", "shell.execute_reply": "2026-07-17T15:59:45.622545Z" }, "papermill": { "duration": 11.617984, "end_time": "2026-07-17T15:59:45.623649", "exception": false, "start_time": "2026-07-17T15:59:34.005665", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exported: stage_1_effective_sigma_z.png\n", "Exported: stage_1_total_displacement.png\n", "Exported: stage_2_effective_sigma_z.png\n", "Exported: stage_2_total_displacement.png\n" ] } ], "source": [ "from rs2.modeler.RS2Modeler import RS2Modeler\n", "from rs2.interpreter.RS2Interpreter import RS2Interpreter\n", "from rs2.interpreter.InterpreterEnums import *\n", "import os\n", "\n", "current_dir = os.path.dirname(os.path.abspath(\"\"))\n", "output_dir = os.path.join(current_dir, \"export_images\")\n", "os.makedirs(output_dir, exist_ok=True)\n", "\n", "RS2Modeler.startApplication(port=60097)\n", "modeler = RS2Modeler(port=60097)\n", "model = modeler.openFile(rf\"{current_dir}\\example_models\\ExampleExportImage.fez\")\n", "model.compute()\n", "model.close()\n", "\n", "RS2Interpreter.startApplication(port=60098)\n", "interpreter = RS2Interpreter(port=60098)\n", "interpreterModel = interpreter.openFile(rf\"{current_dir}\\example_models\\ExampleExportImage.fez\")\n", "\n", "stages = [1, 2]\n", "result_types = [\n", " (ExportResultType.SOLID_EFFECTIVE_STRESS_EFFECTIVE_SIGMA_Z, \"effective_sigma_z\"),\n", " (ExportResultType.SOLID_DISPLACEMENT_TOTAL_DISPLACEMENT, \"total_displacement\"),\n", "]\n", "\n", "for stage in stages:\n", " interpreterModel.SetActiveStage(stage)\n", " for result_type, result_name in result_types:\n", " interpreterModel.SetResultType(result_type)\n", " image_path = os.path.join(output_dir, f\"stage_{stage}_{result_name}.png\")\n", " interpreterModel.ExportImage(image_path)\n", " print(f\"Exported: stage_{stage}_{result_name}.png\")\n", "\n", "interpreterModel.close()\n", "modeler.closeProgram()\n", "interpreter.closeProgram()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.2" }, "papermill": { "default_parameters": {}, "duration": 12.690489, "end_time": "2026-07-17T15:59:45.750050", "environment_variables": {}, "exception": null, "input_path": "D:\\WORK_CPP\\RS2_Python_ClientLibrary\\docs\\example_code\\model\\export_image_script_examples.ipynb", "output_path": "D:\\WORK_CPP\\RS2_Python_ClientLibrary\\docs\\example_code\\model\\export_image_script_examples.ipynb", "parameters": {}, "start_time": "2026-07-17T15:59:33.059561", "version": "2.6.0" } }, "nbformat": 4, "nbformat_minor": 5 }