Package nukescripts :: Module crop
[hide private]
[frames] | no frames]

Source Code for Module nukescripts.crop

 1  # Copyright (c) 2009 The Foundry Visionmongers Ltd.  All Rights Reserved. 
 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 # Sort out execute range 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 # Remember original set of selected nodes...we'll need this 23 original_nodes = nuke.selectedNodes() 24 25 # Deselect everything so we can add CurveTool nodes 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 # Reselect originally selected nodes and create a CurveTool node, 32 # which will automatically connect to the last selected. 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 # Execute the CurveTool node thru all the frames 38 nuke.executeMultiple([autocropper,], ([first, last, inc],)) 39 40 # select the curvewriter 41 autocropper.knob("selected").setValue(True) 42 43 # add crop node 44 cropnode = nuke.createNode("Crop", "label AutoCrop", False) 45 46 # put the new data from the autocrop into the new crop 47 cropbox = cropnode.knob("box"); 48 autocropbox = autocropper.knob("autocropdata"); 49 cropbox.copyAnimations(autocropbox.animations()) 50 51 # turn on the animated flag 52 cropnode.knob("indicators").setValue(1) 53 54 # deselect everything 55 all_nodes = nuke.allNodes() 56 for j in all_nodes: 57 j.knob("selected").setValue(False) 58 59 # select the curvewriter and delete it 60 autocropper.knob("selected").setValue(True) 61 62 # delete the autocropper to make it all clean 63 nodes.node_delete() 64 65 # deselect everything 66 all_nodes = nuke.allNodes() 67 for j in all_nodes: 68 j.knob("selected").setValue(False) 69 70 # select the new crop 71 cropnode.knob("selected").setValue(True) 72 73 # place it in a nice spot 74 nuke.autoplace(cropnode) 75 76 # De-Select it 77 cropnode.knob("selected").setValue(False)
78