Files
ResInsight/GrpcInterface/Python/rips/PythonExamples/surfaces_and_visualization/create_polygon.py
T
Kristian Bendiksen e7608536cf #13982 Python: Tighten Instance.launch/find return type and drop dead None checks
Instance.launch and Instance.find now always either return a connected
Instance or raise RipsError, so their return type narrows from
Optional[Instance] to Instance. In launch(), the unreachable `if pid:`
guard around the Popen result and the trailing `return None` are
removed; the only failure paths raise RipsError.

Update the PythonExamples that previously branched on a None return:
- Drop `if resinsight is None: exit(1)` style guards and `if resinsight
  is not None:` wrappers; dedent the body where applicable.
- export_corner_point_grid.py used the None check as a fallback to
  launch ResInsight; rewrite as try/except rips.RipsError so the
  fallback still works.
- instance_example.py is repurposed as a try/except example for
  reporting connection failure.
2026-05-13 13:47:40 +02:00

50 lines
1.7 KiB
Python

###################################################################################
# This example will connect to ResInsight, find bounding box and add a polygon
#
###################################################################################
# Import the ResInsight Processing Server Module
import rips
# Connect to ResInsight
resinsight = rips.Instance.find()
# Get a list of all cases
cases = resinsight.project.cases()
for c in cases:
print("Case name: " + c.name)
# create a polygon which is same a the bounding box in x and y.
# depth is set to middle of the bounding box
bbox = c.reservoir_boundingbox()
depth = bbox.max_z - ((bbox.max_z - bbox.min_z) / 2.0)
coordinates = []
coordinates.append([bbox.min_x, bbox.min_y, depth])
coordinates.append([bbox.max_x, bbox.min_y, depth])
coordinates.append([bbox.max_x, bbox.max_y, depth])
coordinates.append([bbox.min_x, bbox.max_y, depth])
polygon_collection = resinsight.project.descendants(rips.PolygonCollection)[0]
p = polygon_collection.create_polygon(
name="{} bounding box".format(c.name), coordinates=coordinates
)
print("Coordinates for {}:".format(p.name))
for coord in p.coordinates:
print(coord)
# Customize appearance
appearance = p.appearance()
if appearance is not None:
appearance.line_color = "#ff0000"
appearance.line_thickness = 5
appearance.show_spheres = True
appearance.sphere_color = "#0000ff"
appearance.update()
print(
"Appearance updated: line_color={}, line_thickness={}".format(
appearance.line_color, appearance.line_thickness
)
)