1
2
3 import nuke
4 import nodes
5
6 -def autocrop(first=None, last=None, inc=None, layer="rgba"):
7 """Run the CurveTool's AutoCrop function on each selected node over the
8 specified frame range and channels. If the range values are None, the
9 project first_frame and last_frame are used; if inc is None, 1 is used.
10 After execution, the CurveTool AutoCrop results are copied into a Crop
11 node attached to each selected node."""
12
13
14 root = nuke.root()
15 if first is None:
16 first = int(root.knob("first_frame").value())
17 if last is None:
18 last = int(root.knob("last_frame").value())
19 if inc is None:
20 inc = 1
21
22
23 original_nodes = nuke.selectedNodes()
24
25
26 all_nodes = nuke.allNodes()
27 for i in all_nodes:
28 i.knob("selected").setValue(False)
29
30 for i in original_nodes:
31
32
33 i.knob("selected").setValue(True)
34 autocropper = nuke.createNode("CurveTool",
35 '''operation 0 ROI {0 0 input.width input.height} Layer %s label "Processing Crop..." selected true''' % (str(layer), ), False)
36
37
38 nuke.executeMultiple([autocropper,], ([first, last, inc],))
39
40
41 autocropper.knob("selected").setValue(True)
42
43
44 cropnode = nuke.createNode("Crop", "label AutoCrop", False)
45
46
47 cropbox = cropnode.knob("box");
48 autocropbox = autocropper.knob("autocropdata");
49 cropbox.copyAnimations(autocropbox.animations())
50
51
52 cropnode.knob("indicators").setValue(1)
53
54
55 all_nodes = nuke.allNodes()
56 for j in all_nodes:
57 j.knob("selected").setValue(False)
58
59
60 autocropper.knob("selected").setValue(True)
61
62
63 nodes.node_delete()
64
65
66 all_nodes = nuke.allNodes()
67 for j in all_nodes:
68 j.knob("selected").setValue(False)
69
70
71 cropnode.knob("selected").setValue(True)
72
73
74 nuke.autoplace(cropnode)
75
76
77 cropnode.knob("selected").setValue(False)
78