Advertisement
Totheroo

Nuke - Flip/Mirror Rotoshape (Python)

May 20th, 2025
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import nuke
  2. import nuke.rotopaint as rp
  3.  
  4. def flip_roto_shapes():
  5.     node = nuke.selectedNode()
  6.     if node.Class() not in ("Roto", "RotoPaint"):
  7.         nuke.message("Please select a Roto or RotoPaint node.")
  8.         return
  9.  
  10.     curves = node['curves']
  11.     root = curves.rootLayer
  12.     frame = nuke.frame()
  13.     format_width = node.format().width()
  14.  
  15.     def flip_shape(shape, shape_path):
  16.         for i, pt in enumerate(shape):
  17.             center = pt.center
  18.             x_curve = center.getPositionAnimCurve(0)
  19.             y_curve = center.getPositionAnimCurve(1)
  20.  
  21.             orig_x = x_curve.evaluate(frame)
  22.             orig_y = y_curve.evaluate(frame)
  23.             flipped_x = format_width - orig_x
  24.  
  25.             x_curve.addKey(frame, flipped_x)
  26.             y_curve.addKey(frame, orig_y)
  27.  
  28.             print(f"  → Flipped {shape_path} pt {i}: ({orig_x:.2f}, {orig_y:.2f}) → ({flipped_x:.2f}, {orig_y:.2f})")
  29.  
  30.     def walk(layer, path=""):
  31.         for item in layer:
  32.             if isinstance(item, rp.Shape):
  33.                 shape_path = path + item.name
  34.                 print(f"[✓] Flipping shape: {shape_path}")
  35.                 flip_shape(item, shape_path)
  36.             elif isinstance(item, rp.Layer):
  37.                 walk(item, path + item.name + "/")
  38.  
  39.     print("== BEGIN FLIPPING SHAPES ON CURRENT FRAME ==")
  40.     walk(root)
  41.     curves.changed()
  42.     print("== DONE ==")
  43.  
  44. flip_roto_shapes()
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement