Mel Quick Reference I

 

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

2
No match, then do this default action.





© 2002- Malcolm Kesson. All rights reserved.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值