Skip to content

Commit 4de6fa7

Browse files
hakonhaglandclaude
andcommitted
Add Instance.set_snapshot_size to rips Python client
Wraps the new setSnapshotSize gRPC command so callers can do ri.set_snapshot_size(1600, 1000) for plot in ri.project.plots(): plot.export_snapshot(export_folder=...) and get 1600x1000 PNGs back. Mirrors the existing Instance.set_plot_window_size wrapper shape. The headless_plot_export example is updated to demonstrate the call between plot creation and the export_snapshot loop. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 40a70f1 commit 4de6fa7

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

GrpcInterface/Python/rips/PythonExamples/export_and_plotting/headless_plot_export.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
summary_cases=[summary_case], address="WOPR:A*;WOPR:B*"
2727
)
2828

29+
# Resize the plot sub-windows so the exported PNGs come out at the
30+
# requested resolution. Without this, the offscreen layout engine picks
31+
# its own (typically small) geometry and snapshots ignore the --size
32+
# launch parameter.
33+
resinsight.set_snapshot_size(1200, 1000)
34+
2935
plots = resinsight.project.plots()
3036
for plot in plots:
3137
plot.export_snapshot()

GrpcInterface/Python/rips/instance.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,44 @@ def set_plot_window_size(self, width: int, height: int):
561561
)
562562
)
563563

564+
def set_snapshot_size(self, width: int, height: int):
565+
"""
566+
Set the size used for snapshot export of plots and 3D views.
567+
568+
Affects subsequent calls to ``export_snapshot`` /
569+
``export_snapshots``. Equivalent to the ``--snapshotsize`` CLI
570+
flag. Must be called after at least one plot window has been
571+
created (otherwise there is nothing to resize).
572+
573+
Unlike :meth:`set_plot_window_size`, which only resizes the
574+
outer plot main window, this method un-maximizes and resizes
575+
each MDI sub-window so the actual plot widget is rendered at
576+
the requested dimensions.
577+
578+
Recommended call order for a filled snapshot:
579+
580+
1. :meth:`set_plot_window_size` *before* creating plots, so the
581+
plots are realized inside MDI sub-windows.
582+
2. Create the plot(s).
583+
3. ``project.plots()`` to fetch the plot to export. This can
584+
re-tile the MDI sub-windows back to their defaults, so call
585+
``set_snapshot_size`` *after* it, not before.
586+
4. ``set_snapshot_size(width, height)``.
587+
5. ``plot.export_snapshot(...)``.
588+
589+
**Parameters**::
590+
591+
Parameter | Description | Type
592+
--------- | ---------------- | -----
593+
width | Width in pixels | Integer
594+
height | Height in pixels | Integer
595+
"""
596+
return self.__execute_command(
597+
setSnapshotSize=Commands_pb2.SetWindowSizeParams(
598+
width=width, height=height
599+
)
600+
)
601+
564602
def major_version(self) -> int:
565603
"""Get an integer with the major version number"""
566604
return int(self.__version_message().major_version)

0 commit comments

Comments
 (0)