[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

MOTOOLS

MOTools for 3dsmax – A collection of tools. Feel free to copy, edit and change.

  • Script files with other authors will be in the header of the file. Please be curious and extend the authors info.
[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Variables

Global vs Local

global int $varname = 3; – This is a global variable and can be seen by other scripts

Defining a Variable

int $varname; – Integer value. Example int $varname = 10;

float $varname; – Float value. Example float $varname = 1.2345;

string $varname; – Creating a string. Example string $varname = “Hello World”;

vector $varname; – Creates a 3 digit vector. Example vector $varname = <<1,0,0>> or = <<255,128,0>>;

$varname[]; – This is for arrays

matrix $varname[3][4]; – Creates a Matrix


Int and Floats math

int $varA = 5;
float $varB = 5.123;
$varA + $varB = 10; < – You can get a float out of a int
$varB + $varA = 10.123;

Strings

string $varname; – Creating a string. Example string $varname = “Hello World”;

Line Options
"\n" = New line
"\t" = Tab
"\\" = Backslash

Examples:

string $varname = "Hello World";
// Result: “Hello world” //

print ($varname + ", Hello computer" ;
// Result: “Hello world, Hello computer” //

 

Vectors

Vectors are always three floats values

Examples:
vector $varname = <<255,128,0>>;
// Result: <<255, 128, 0>> //

print ($varname.x)
// Result: 255 //

Set a value
$varname = <<123,$varname.y,$varname.z>>;
// Result: <<123, 128, 0>> //

Arrays

int $varname[] = {1,2,3};
float $varname[] = {1.25,2.8,3.0};
string $varname[] = {"one","two","three"};

clear($varname); – Will clear an array out

Examples:

int $varname[] = {1,2,3};
$varname[0] = 9
// Result: 9 //

int $varname[] = {1,2,3};
$varname[0] = 9;
print ($varname);
// Result: 9 //
// Result: 2 //
// Result: 3 //

Looking for a value in a array. This returns a True (1) or False (0).
string $Lists[] = {"one","two","three"};
string $UserInput = "three";

print (stringArrayContains($UserInput, $Lists));
// Result: 1 //

 

 

Matrix

matrix $matrixname[Row#][Column#] = << 1, 2, 3, 4 ; 5, 6, 7, 8 ; 9, 10, 11, 12>>;
// Result: << 1 2 3 4; 5 6 7 8; 9 10 11 12 >> //

1 2 3 4
5 6 7 8
9 10 11 12

 

Script Clips

Get current render
GetCurrentRenderer();
// Result: arnold //

Get list of all render layers
string $GetRenderLayers[]=`ls -type renderLayer`;
// Result: defaultRenderLayer //

getAttr ($isRenderLayerEnabled + “.renderable “) == 1)

Gets frame padding via a number
setAttr ("defaultRenderGlobals.extensionPadding",4);
getAttr ("defaultRenderGlobals.extensionPadding");

// Result: 4 // myrender.####.exr

Gets format type via a number
setAttr( "defaultRenderGlobals.outFormatControl",1)
getAttr( "defaultRenderGlobals.outFormatControl")
  • 1 = name (Single Frame)
  • 2 = name.ext (Single Frame)

Pixel Aspect
setAttr( "defaultResolution.pixelAspect",1.25)
getAttr( "defaultResolution.pixelAspect")

Gets a list of all cameras in the scene
string $all_cameras[] = `ls -type camera`;
// Result: frontShape perspShape sideShape topShape //

 

EXR compression
getAttr( "defaultArnoldDriver.exrCompression" );
// Result: 3 //

32 or 16 bit EXR
getAttr( "defaultArnoldDriver.halfPrecision" );
// Result: 0 //

EXR tiled On/Off
getAttr( "defaultArnoldDriver.exrTiled" );
// Result: 1 //

Auto Crop On/Off
getAttr( "defaultArnoldDriver.autocrop" ) 
// Result: 0 //

MultiPart EXR On/Off
getAttr( "defaultArnoldDriver.mergeAOVs" );
// Result: 0 //

Finding Version name
import os
print "PATH : " + cmds.file(q=True, sn=True)
print "BASENAME : " + os.path.basename(cmds.file(q=True, sn=True).split('.')[0])
print "VERSION : _v"+ os.path.basename(cmds.file(q=True, sn=True)).split('.')[1].split('mb')[0]

Random Rotate:
vector $rndRot = << 0,0,90 >>;
for ($object in `ls -sl -tr`)
rotate `rand ($rndRot.x)` `rand ($rndRot.y)` `rand ($rndRot.z)` $object;

Adding Mathematical Functions to Expressions in Nuke

atop = AB+B(1-A)
average = (A+B)/2)
color-burn = Darken B towards A
color-dodge = brighten B towards A
conjoint-over = A+B(1-a/b), A if a>b
copy = A
difference = abs(A-B)
disjoint-over = A+B(1-a)/b, A+B if a+b<1
divide = A/B, 0 if A<0 and B<0
exclusion = A+B-2AB
from = B-A
geometric = 2AB/(A+B)
hard-light = multiply if A<0.5, screen if A>0.5
hypot = sqrt (A*A+B*B)
in = Ab
mask = Ba
matte = Aa+B(1-a)
max = max (A,B)
min = min (A,B)
minus = A-B
multiply = AB, A if A<0 and B<0
out = A(1-b)
over = A+B(1-a)
overlay = multiply if B<0.5, screen if B>0.5
plus = A+B
screen = A or B ≤1? A+B-AB: max(A,B)
soft-light = Image B gets lit up.
stencil = B(1-a)
under = A(1-b)+B
xor = A(1-b)+B(1-a)

http://help.thefoundry.co.uk/nuke/content/comp_environment/expressions/adding_math_functions.html