Tuesday, April 30, 2013

grep recursively to search from specific file type


grep -r --include=<pattern> <string> <directory>

grep -r --include=*.nk "Shot200" .

The above code will search any .nk files that contain the word 'Shot200' in the current folder and its subfolders recursively .

or use 'find'

find . -name "*.nk" -exec grep "Shot200" {} +

or 

find . -name "*.nk" | xargs grep "Shot200"

Saturday, July 21, 2012

matrix 4x4 class

To create matrix 4x4 :

mtx=nuke.math.Matrix4()
print mtx

--> {2.379e-17, 0, 5.7439e-20, 0, 5.65215e-22, 0, 3417.91, 0, 0, 0, 0, 0, 0, 0, 6.27864e-24, 0}

mtx.makeIdentity()
print mtx
--> {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}

mtx[12]=3
mtx[13]=5
print mtx
--> {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3, 5, 0, 1}

element #12,#13,#14 = dx,dy,dz (translate x/y/z)
The mapping (relationship) between the matrix4 class and matrix knob is as follow :
(note : see below, the translate element is colored in red just for example purpose only )

matrixknob :
00 - 01 - 02 - 03
10 - 11 - 12 - 13
20 - 21 - 22 - 23
30 - 31 - 32 - 33

matrix class :
{
00,01,02,03,
01,11,21,31,
02,12,22,32,
03,13,23,33
}

so dx/dy/dz respectively is element 03/13/23.
To access this element in nuke, we use 2d index :
matrixknob.value(0,3) for 03
matrixknob.value(1,3) for 13
matrixknob.value(2,3) for 23

in nuke matrix class/object , we access this by linear indexing (1d index)
mtx[12] for 03
mtx[13] for 13
mtx[14] for 23


- end-

How to grab matrix value

To grab value of matrix knob, we need use an indexing.
Format :
matrixknob.value(x,y) , where x and y is 2d index.

For example in 3dTransform node, we have 4x4 matrix like this format :

00 - 01 - 02 - 03
10 - 11 - 12 - 13
20 - 21 - 22 - 23
30 - 31 - 32 - 33

so to access element 32 , we use : matrixknob.value(3,2) etc.

Tuesday, June 5, 2012

How to check if knob exist in selected Node?

if node[knobname] <-- this command will fail when the knob doesn't exist :
e.g :
if node['translate'] : XXX
#NameError: knob translate does not exist


The trick is using .knob() :
if node.knob(knobname)
e.g :
if node.knob('translate') : XXX
Nuke won't spit out error message, it will just simply pass/ignore the 'XXX' when knob 'translate' doesn't exist.