Skip to content

Commit 52f39a7

Browse files
authored
Merge pull request #22 from ynput/bugfix/set_virtual_resolution_and_pixel_aspect
Set resolution using the virtual resolution and set pixel aspect ratio from entity
2 parents 4ef6822 + 52e3e5f commit 52f39a7

File tree

1 file changed

+21
-2
lines changed
  • client/ayon_cinema4d/api

1 file changed

+21
-2
lines changed

client/ayon_cinema4d/api/lib.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,29 @@ def set_resolution_from_entity(task_entity, doc=None):
467467
attrib = task_entity["attrib"]
468468
width: int = int(attrib["resolutionWidth"])
469469
height: int = int(attrib["resolutionHeight"])
470+
pixel_aspect: float = attrib["pixelAspect"]
471+
472+
@contextlib.contextmanager
473+
def _unlocked_ratio(render_data):
474+
"""Temporarily unlock the ratio of the render resolution."""
475+
original = render_data[c4d.RDATA_LOCKRATIO]
476+
render_data[c4d.RDATA_LOCKRATIO] = False
477+
try:
478+
yield
479+
finally:
480+
render_data[c4d.RDATA_LOCKRATIO] = original
470481

471482
rd = doc.GetFirstRenderData()
472483
while rd:
473-
rd[c4d.RDATA_XRES] = width
474-
rd[c4d.RDATA_YRES] = height
484+
# Fix #20: Set the virtual resolution with user interaction so Redshift
485+
# still triggers some additional checks on the attribute change.
486+
with _unlocked_ratio(rd):
487+
flag = c4d.DESCFLAGS_SET_USERINTERACTION
488+
rd.SetParameter(c4d.RDATA_XRES_VIRTUAL, width, flag)
489+
rd.SetParameter(c4d.RDATA_YRES_VIRTUAL, height, flag)
490+
491+
# Set pixel aspect ratio
492+
rd[c4d.RDATA_PIXELASPECT] = pixel_aspect
493+
475494
rd = rd.GetNext()
476495
c4d.EventAdd()

0 commit comments

Comments
 (0)