Mel
Quick Reference I


return to main index



index


Print


print "hello world";
float $val = 1.5;
print $val;

Print the contents of a string literal. Print the value of a variable.



Setting Variables


int $age = 54;
float $pi = 3.142;
string $hi = "good-day";
vector $xyz = <<1, 0, 0>>;
float $coord[] = {0.6, 0.3};

age is assigned the integer 54 pi is assigned the fractional value 3.142 hi is assigned a string literal xyz is assigned a vector of 3 values coord is assigned an array of 2 values



Using Arrays


int $ages[3]; // or $ages[]
$ages = {25, 33, 45};
$ages[0] = 12;
print $ages;
print $ages[2];
  
string $names[] = `ls -cameras`;
int $num = size($names);
print("Num Cameras = " + $num);

declare an integer array of three elements assign three values change the value of the first element print all three values print the last value get the names of the all the cameras size() counts the elements of an array print a confimation of the number of cameras



Using Vectors


vector $p = <<1, 2, 3>>;
sphere -pivot ($p.x) ($p.y) ($p.z);

declare a vector - must have 3 components note the use of parentheses WRONG - cannot change an individual component RIGHT



if-else tests


tring $name[] = `ls -selection`;
if(size($name) >= 1)
   print("Selection 1 = " + $name[0]);
else
   print("Nothing selected");
  
if(gmatch($name[0], "nurbs*"))
   print("Found a nurbs object");

get the names of the selected objects does the array of names have at least one item? if so, then output the name otherwise print a warning use gmatch() to see if the name begins with the word "nurbs" - notice the use of the wild card *



for loops


sstring $names[] = `ls -selection`;
for($i = 0; $i < size($names); $i++)
   print($names[$i] + "\n");
  
string $item;
for($item in $names)
   print($item + "\n")

get the names of the selected objects for each element in the array of names ...output the name a more convenient way of dealing with an array is to use the "for in" variation of a for loop



Querrying


cone;
float $rad = `cone -q -radius`;
  
string $names[] = `ls -lights`;
print $names;

make a default nurbs cone querry its radius and assign its value to $rad use the ls command to list the lights in a scene print the array of light names



Using the eval Command


string $cmd = "curve -p 0 0 0 -p 1 0 0 \
-p 1 4 0 -p -1 2 3";
string $pnt = "-p 3 3 3";
string $name = eval($cmd + $pnt);
print $name;

make a string variable containing text for a command (the backslash enables a string to go onto two lines) make another string containing some extra info use eval to execute the combined strings print the name returned from the "curve" command



Create a Window


window -title "test" myWindow;
showWindow myWindow;

Create a window titled "test", to be identified as "myWindow" show the window.



Using Column Layout


window -title "test" myWindow;
columnLayout;
button;
showWindow myWindow;

Create a window titled "test", to be identified as "myWindow" use the column layout manager add a button show the window.



Assigning a Command to a Button


vector $pnts[];
string $ball = "curve ";
for($i = 0; $i < 200; $i++)
   {
   $pnts[$i] = <<rand(-5,5),
               rand(-5,5),
               rand(-5,5)>>;
   $ball += " -p " + $pnts[$i];
   }
window -title "test";
columnLayout;           
button 
    -label "make hairball"
    -command "eval($ball)";
showWindow;

declare an array of vectors declare a string to command text create 200 CV's

Create a window titled "test" use the column layout manager add a button with a title and a command

show the window



switch


int $x = 2;
switch ($x) {
   case 0: print "zero"; break; 
   case 1: print "one"; break;
   case 2: print "two"; break;
   default: print "no match"; 
   }

Assign x the value 2. Attempt to match the value of x to the following,
0
1
2
No match, then do this default action.





© 2002- Malcolm Kesson. All rights reserved.