Files
ResInsight/GrpcInterface/Python/rips/PythonExamples/surfaces_and_visualization/create_polygon.py
T
Kristian Bendiksen 614acc664a #13682 Python: Expose polygon appearance properties to Python API
Make RimPolygonAppearance scriptable so polygon visual properties
(colors, line thickness, spheres, closed state, plane lock) can be
controlled from the Python API.
2026-03-12 08:30:52 +01:00

50 lines
1.8 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()
if resinsight is not None:
# 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
)
)