Material Query Script Examples#

Download the ExampleModel.fez for this example.

Code Snippet: Manipulation of Material Queries#
from rs2.interpreter.RS2Interpreter import RS2Interpreter
from rs2.interpreter.InterpreterEnums import *
import os, inspect

current_dir = os.path.dirname(os.path.abspath(inspect.getfile(lambda: None))) 
RS2Interpreter.startApplication(port=60073)
interpreter = RS2Interpreter(port=60073)
model = interpreter.openFile(rf"{current_dir}\example_models\ExampleModel.fez")

pointID = model.AddMaterialQuery(points=[[3.3, -2.2]])

points_making_line = [[4.5, 4.5], [-2.5, 4.5], [-2.5, 2.5], [-6, 2.5]]
lineID = model.AddMaterialQuery(points=points_making_line)

model.RemoveMaterialQuery([pointID])

model.SetActiveStage(2)

results = model.GetMaterialQueryResults()

for mat_query_data in results:
    unique_ID = mat_query_data.GetUniqueIdentifier()
    material_ID = mat_query_data.GetMaterialID()
    print(f"Query Unique ID = {unique_ID}, MaterialID = {material_ID}")
    print("----------------")
    query_results = mat_query_data.GetAllValues()
    for result in query_results:
        x = result.GetXCoordinate()
        y = result.GetYCoordinate()
        distance = result.GetDistance()
        value = result.GetValue()
        print(f"X-Coord ={x}, Y-Coordinate = {y}, Distance = {distance}, Result Type Node Value = {value}")

model.close()

interpreter.closeProgram()

Output#

Query Unique ID = {16FC1971-DBD9-4d12-873D-CBD1B6890EFC}, MaterialID = 1
----------------
X-Coord =-6.189, Y-Coordinate = 0.5, Distance = 0.0, Result Type Node Value = 55.65935856694917
X-Coord =-2.4655593574243744, Y-Coordinate = -2.2477321255343847, Distance = 4.627530880769754, Result Type Node Value = 97.35910559036152
X-Coord =-2.4655569435405527, Y-Coordinate = -2.2477339068723357, Distance = 4.627533880769755, Result Type Node Value = 100.30235902051997
X-Coord =-0.751, Y-Coordinate = -3.513, Distance = 6.758403139795673, Result Type Node Value = 118.49031904837915
Query Unique ID = {421E3CAA-B894-412a-9830-3B98A86EE825}, MaterialID = 3
----------------
X-Coord =4.5, Y-Coordinate = 4.5, Distance = 0.0, Result Type Node Value = None
X-Coord =-2.5, Y-Coordinate = 4.5, Distance = 7.0, Result Type Node Value = None
X-Coord =-2.5, Y-Coordinate = 2.5, Distance = 9.0, Result Type Node Value = 24.66258070715867
X-Coord =-6.0, Y-Coordinate = 2.5, Distance = 12.5, Result Type Node Value = 23.43662855220668
Query Unique ID = {21E04B25-3340-4fb2-9845-F5B445CBF758}, MaterialID = 5
----------------
X-Coord =4.5, Y-Coordinate = 4.5, Distance = 0.0, Result Type Node Value = None
X-Coord =-2.5, Y-Coordinate = 4.5, Distance = 7.0, Result Type Node Value = None
X-Coord =-2.5, Y-Coordinate = 2.5, Distance = 9.0, Result Type Node Value = 24.66258070715867
X-Coord =-6.0, Y-Coordinate = 2.5, Distance = 12.5, Result Type Node Value = 23.43662855220668