{ "cells": [ { "cell_type": "markdown", "id": "aececd27", "metadata": { "papermill": { "duration": 0.005972, "end_time": "2026-03-19T15:24:21.282647", "exception": false, "start_time": "2026-03-19T15:24:21.276675", "status": "completed" }, "tags": [] }, "source": [ "(Material Query Example)=\n", "# Material Query Script Examples" ] }, { "cell_type": "markdown", "id": "8f03602b", "metadata": { "papermill": { "duration": 0.000991, "end_time": "2026-03-19T15:24:21.287846", "exception": false, "start_time": "2026-03-19T15:24:21.286855", "status": "completed" }, "tags": [] }, "source": [ "Download the [ExampleModel.fez](https://github.com/Rocscience/rs2-scripting/blob/main/docs/example_code/example_models/ExampleModel.fez) for this example." ] }, { "cell_type": "code", "execution_count": 1, "id": "7b715563", "metadata": { "execution": { "iopub.execute_input": "2026-03-19T15:24:21.291231Z", "iopub.status.busy": "2026-03-19T15:24:21.290966Z", "iopub.status.idle": "2026-03-19T15:24:27.837132Z", "shell.execute_reply": "2026-03-19T15:24:27.835145Z" }, "papermill": { "duration": 6.549757, "end_time": "2026-03-19T15:24:27.838570", "exception": false, "start_time": "2026-03-19T15:24:21.288813", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Query Unique ID = {578FE10E-AC26-4f3d-A159-E31ECA9F23C1}, MaterialID = 2\n", "----------------\n", "X-Coord =4.5, Y-Coordinate = 4.5, Distance = 0.0, Result Type Node Value = None\n", "X-Coord =-2.5, Y-Coordinate = 4.5, Distance = 7.0, Result Type Node Value = None\n", "X-Coord =-2.5, Y-Coordinate = 2.5, Distance = 9.0, Result Type Node Value = 28.653523301103142\n", "X-Coord =-6.0, Y-Coordinate = 2.5, Distance = 12.5, Result Type Node Value = 24.14127197144012\n", "\n", "\n", "Query Unique ID = {105BD04E-DC55-4560-B3B0-4464597099B7}, MaterialID = 1\n", "----------------\n", "X-Coord =-6.189, Y-Coordinate = 0.5, Distance = 0.0, Result Type Node Value = 56.58757059397466\n", "X-Coord =-2.4655593574243744, Y-Coordinate = -2.2477321255343847, Distance = 4.627530880769754, Result Type Node Value = 103.75317200467164\n", "X-Coord =-2.4655569435405527, Y-Coordinate = -2.2477339068723357, Distance = 4.627533880769755, Result Type Node Value = 105.82926734317422\n", "X-Coord =-0.751, Y-Coordinate = -3.513, Distance = 6.758403139795673, Result Type Node Value = 124.52168304580846\n", "\n", "\n", "Query Unique ID = {8A1FDD81-99DF-4ddb-A70F-CAF1E52B8B91}, MaterialID = 4\n", "----------------\n", "X-Coord =4.5, Y-Coordinate = 4.5, Distance = 0.0, Result Type Node Value = None\n", "X-Coord =-2.5, Y-Coordinate = 4.5, Distance = 7.0, Result Type Node Value = None\n", "X-Coord =-2.5, Y-Coordinate = 2.5, Distance = 9.0, Result Type Node Value = 28.653523301103142\n", "X-Coord =-6.0, Y-Coordinate = 2.5, Distance = 12.5, Result Type Node Value = 24.14127197144012\n", "\n", "\n" ] } ], "source": [ "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", "RS2Interpreter.startApplication(port=60073)\n", "interpreter = RS2Interpreter(port=60073)\n", "model = interpreter.openFile(rf\"{current_dir}\\example_models\\ExampleModel.fez\")\n", "\n", "pointID = model.AddMaterialQuery(points=[[3.3, -2.2]])\n", "\n", "points_making_line = [[4.5, 4.5], [-2.5, 4.5], [-2.5, 2.5], [-6, 2.5]]\n", "lineID = model.AddMaterialQuery(points=points_making_line)\n", "\n", "model.RemoveMaterialQuery([pointID])\n", "\n", "model.SetActiveStage(2)\n", "\n", "results = model.GetMaterialQueryResults()\n", "\n", "for mat_query_data in results:\n", " unique_ID = mat_query_data.GetUniqueIdentifier()\n", " material_ID = mat_query_data.GetMaterialID()\n", " print(f\"Query Unique ID = {unique_ID}, MaterialID = {material_ID}\")\n", " print(\"----------------\")\n", " query_results = mat_query_data.GetAllValues()\n", " for result in query_results:\n", " x = result.GetXCoordinate()\n", " y = result.GetYCoordinate()\n", " distance = result.GetDistance()\n", " value = result.GetValue()\n", " print(f\"X-Coord ={x}, Y-Coordinate = {y}, Distance = {distance}, Result Type Node Value = {value}\")\n", " print(\"\\n\")\n", "\n", "model.close()\n", "\n", "interpreter.closeProgram()" ] } ], "metadata": { "kernelspec": { "display_name": "myenv", "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.0" }, "papermill": { "default_parameters": {}, "duration": 8.080001, "end_time": "2026-03-19T15:24:28.071895", "environment_variables": {}, "exception": null, "input_path": "C:\\Users\\GraceHu\\source\\repos\\RS2_Python_Client_Library\\docs\\example_code\\results\\material_query_script_examples.ipynb", "output_path": "C:\\Users\\GraceHu\\source\\repos\\RS2_Python_Client_Library\\docs\\example_code\\results\\material_query_script_examples.ipynb", "parameters": {}, "start_time": "2026-03-19T15:24:19.991894", "version": "2.6.0" } }, "nbformat": 4, "nbformat_minor": 5 }