Thursday, August 8, 2013

paintNodeOpacity.py

paintNodeOpacity python code


This little code will help you to control nuke "rotopaint" nodes clone & paint brush opacity via some short-cut keys. I created this code for my fellow artist who's working with me in paint department.

Short-cut keys are assigned as per his need. You can use your custom short-cut keys.




There are 5 control option.

"shift+>",  "shift+<"
user can up & down the opacity value using "shift+>" and "shift+<". This will jump between current value to +0.05 or -0.05.

If your value will 1 it start to decrease 0.95, 0.9, 0.85 so one so forth....


"ctrl+>", "ctrl+<"
 user can up & down the opacity value using "ctrl+>" and "ctrl+<". This will jump between current value to +0.01 or -0.01.

If your value will 1 it start to decrease 0.99, 0.98, 0.97 so one so forth....

"ctrl+Shift+<" and "ctrl+Shift+<"
This will return the opacity value to default 1 and 0.



Hope this will help you guys.


updated Aug19th:  Fixed NameError:. In previous version, while user accidentally hit these short-cut nuke will pop-up the name error. This issue fixed now and removed "please select rotopaint node" message.


Download: paintOpacity.py

else: copy paste below code:

'''
Created on 07-august-2013
@author: satheesh-R
mail - satheesrev@gmail.com
'''


import nuke, math, os

def paintOpacityUp():
    selNode = None
    try:
        selNode = nuke.selectedNode()
    except ValueError: # no node selected
        pass
    cls = selNode.Class()

    if cls  == 'RotoPaint':
        for a in nuke.selectedNodes():
            getValue = a['toolbar_opacity'].value()
            newValue = sorted([0, getValue + 0.05, 1])[1]
            setVal = a['toolbar_opacity'].setValue(newValue)
    else:
        return

def paintOpacityUpIncrease():
    selNode = None
    try:
        selNode = nuke.selectedNode()
    except ValueError: # no node selected
        pass
    cls = selNode.Class()

    if cls  == 'RotoPaint':
        for a in nuke.selectedNodes():
            getValue = a['toolbar_opacity'].value()
            newValue = sorted([0, getValue + 0.01, 1])[1]
            setVal = a['toolbar_opacity'].setValue(newValue)
    else:
        return


def paintOpacityDown():
    selNode = None
    try:
        selNode = nuke.selectedNode()
    except ValueError: # no node selected
        pass
    cls = selNode.Class()

    if cls  == 'RotoPaint':
        for a in nuke.selectedNodes():
            getValue = a['toolbar_opacity'].value()
            newValue = getValue - 0.05
            if newValue < 0: newValue = 0
            setVal = a['toolbar_opacity'].setValue(newValue)
    else:
        return

def paintOpacityDecrease():
    selNode = None
    try:
        selNode = nuke.selectedNode()
    except ValueError: # no node selected
        pass
    cls = selNode.Class()

    if cls  == 'RotoPaint':
        for a in nuke.selectedNodes():
            getValue = a['toolbar_opacity'].value()
            newValue = getValue - 0.01
            if newValue < 0: newValue = 0
            setVal = a['toolbar_opacity'].setValue(newValue)
    else:
        return

def paintOpacityDefault():
    selNode = None
    try:
        selNode = nuke.selectedNode()
    except ValueError: # no node selected
        pass
    cls = selNode.Class()

    if cls  == 'RotoPaint':
        for a in nuke.selectedNodes():
            a['toolbar_opacity'].setValue(1)

    else:
        return

def paintOpacityZero():
    selNode = None
    try:
        selNode = nuke.selectedNode()
    except ValueError: # no node selected
        pass
    cls = selNode.Class()

    if cls  == 'RotoPaint':
        for a in nuke.selectedNodes():
            a['toolbar_opacity'].setValue(0)

    else:
        return
_______________________________________________



menu.py

import paintOpacity

menuBar = nuke.menu("Nuke")

menuBar.addCommand('Edit/Node/paintOpacity/Up', 'paintOpacity.paintOpacityUp()', 'shift+>')
menuBar.addCommand('Edit/Node/paintOpacity/Down', 'paintOpacity.paintOpacityDown()', 'shift+<')
menuBar.addCommand('Edit/Node/paintOpacity/increase', 'paintOpacity.paintOpacityUpIncrease()', 'ctrl+.')
menuBar.addCommand('Edit/Node/paintOpacity/decrease', 'paintOpacity.paintOpacityDecrease()', 'ctrl+,')
menuBar.addCommand('Edit/Node/paintOpacity/default', 'paintOpacity.paintOpacityDefault()', 'ctrl+shift+>')
menuBar.addCommand('Edit/Node/paintOpacity/zero', 'paintOpacity.paintOpacityZero()', 'ctrl+shift+<')


Tuesday, August 6, 2013

autoPinning.py

auto pinning nuke cornerPin

 This little code place the cornerPin nodes 4 pin's automatically based on the bbox. If your image dosen't have bbox add a crop node and crop it as per your need.

Before:



After:





 
Download: autopinning.py


python code:


'''
Created on 04-august-2013
@author: satheesh
mail - satheesrev@gmail.com
'''

import sys
import nuke

def autoPinning():
    selNode = None
    try:
      selNode = nuke.selectedNode()
    except ValueError:  # no node selected
      pass

    if selNode is not None:
    ## auto pin for from
        selNode['from1'].setExpression('[value name].bbox.x', 0)
        selNode['from1'].setExpression('[value name].bbox.y', 1)
        selNode['from1'].clearAnimated()
        selNode['from2'].setExpression('[value name].bbox.r', 0)
        selNode['from2'].setExpression('[value name].bbox.y', 1)
        selNode['from2'].clearAnimated()
        selNode['from3'].setExpression('[value name].bbox.r', 0)
        selNode['from3'].setExpression('[value name].bbox.t', 1)
        selNode['from3'].clearAnimated()
        selNode['from4'].setExpression('[value name].bbox.x', 0)
        selNode['from4'].setExpression('[value name].bbox.t', 1)
        selNode['from4'].clearAnimated()

    ## copying value's from
        selNode['to1'].setExpression('[value name].bbox.x', 0)
        selNode['to1'].setExpression('[value name].bbox.y', 1)
        selNode['to1'].clearAnimated()
        selNode['to2'].setExpression('[value name].bbox.r', 0)
        selNode['to2'].setExpression('[value name].bbox.y', 1)
        selNode['to2'].clearAnimated()
        selNode['to3'].setExpression('[value name].bbox.r', 0)
        selNode['to3'].setExpression('[value name].bbox.t', 1)
        selNode['to3'].clearAnimated()
        selNode['to4'].setExpression('[value name].bbox.x', 0)
        selNode['to4'].setExpression('[value name].bbox.t', 1)
        selNode['to4'].clearAnimated()


    else:
      nuke.message('No node selected')

scale up and down cornerpin node

global scale up and down cornerpin This script help you to global scale up or down the selected cornerpin. Recently i had situation to ...