2016年7月7日,about mel...

写一个script的步骤:
1、先看scene的state对script有没有意义。
2、创建界面。
3、validate input。
    a.如果要求是integer,是不是有效的integer?
      如果要求是float,是不是有效的float?
    b.如果要求是string,是不是都是合法字符?
    c.数字都在范围里面?
    d.指向文件的string确实指向一个现有文件?
4、a.step 3结果为true,运行script。
   b.step 3结果为false,给出错误信息,要求用户重新输入。

MAYA提供了一个内核和MEL,并且预先用MEL建立了一个界面。

command syntax: <command> <argument A> <argument B>;
function syntax: <command>("<argument A>", <argument B>);
note:assumes argument A is a string.

MEL command line: focus on/off in preferences; scroll with ↑↓;

about command auto-completion: turn on command => command completion, press ctrl + space.

When you source a MEL script, MEL does not allow you to forward reference locally scoped procedures. Locally scoped procedure definitions must appear before they are called.

有两种方式在MAYA里执行mel文件:
1、source,读入procedure并且执行command。又分为图形界面source;命令行source——必须在文件存在于script path后再启动maya。
2、直接执行文件的文件名(不加.mel)——必须在文件存在于script path后再启动maya。这会导入文件里的所有环境,包括所有procedure和变量,但不会执行command。然后,会自动找寻和文件名一样的procedure,如果找到,将会执行此procedure,没找到则会打印错误。

在一个文件里面,如果local procB要call local procA,那么A的定义要在B的前面。

integer计算速度比floating point块。

可以用16进制表示integer:0x123。

字符串换到下一行,行尾用'\'+回车。

implicitly: 1, 2.3, "000"; explicitly: (int)1, (float)2.3, (string)000 .

赋值的时候,对两个不同数据类型的数据进行操作的时候,explicit显示数据、指定数据类型和后面的常数数据类型不一致的时候,会发生自动数据转换。

对两个不同数据类型的数据进行操作:numeric + string:numeric to string;float + integer: integer to float。

The rand command generates a random floating point number. If you give one argument, it returns a number between 0 and the argument.If you give two arguments, it returns a random number between the first and second arguments.

$aryone = {1, 2, 3}; //不声明变量的类型,有后面的常量(int数组)确定其类型。
int $arytwo[] = {1, 2, 3}; //声明变量的类型,是一个int数组。
int $arythree = {1, 2, 3}; //wrong,不能把一个int数组赋给一个int标量。
$aryfour[] = {1, 2, 3}; //wrong,语法错误,没有完全声明变量的数据类型。

global procedure可以被覆盖。global procedure会一直保存在内存里。

When composing MEL scripts, keep the user in mind (even if you are the only user). Make sure that the MEL script considers user errors and handles these errors gracefully.

MAYA用true、on代表1;false、off代表0。 MAYA返回1代表true;返回0代表false。

MEL中,一个表达式不能成为一个单独的语句,否则会报syntax error。除了有“=” operator的expression,因为它不光是一个表达式,即计算一个值,它还有side effect,即赋值。

把返回一个值的函数调用当表达式用,返回的值即为表达式的值。

可以直接在expression里直接使用time、frame,time的值是即时秒数。frame(time1.outTime)是即时帧数。

switch ($letter) {
 case "a":
 case "A":
 print("Apple\n"); // Executed if "a" or "A"
 break;
 case "b":
 case "B":
 print("Banana\n"); // Executed if "b" or "B"
 break;
}

break;:跳出循环,执行紧接着循环的下一句;continue;:跳过continue;的下一句到循环最后一句的所有语句。

exists: check command, subroutine, script.
objExists: check node in a scene.
attributeExists: check attribute of a node.e.g.: attributeExists <attrName> <nodeName>

while (time > 3)
    Balloon.scaleY = time;
Even though a statement sets an attribute within an expression, Maya updates the attribute only after the expression finishes executing. Because the expression never finishes executing, Maya halts.
To get the desired result without halting Maya, use this expression:
if (time > 3)
    Balloon.scaleY = time;

A full attribute name has the name of the node, a period, and the name of the attribute on the node, with no spaces between them:nodeName.attributeName.

MEL中只能使用long name和short name。listAttr <nodeName>;listAttr -shortNames <nodeName>。

If you select an object as the Default Object in the Expression Editor, you can omit the object name and period that’s part of a full attribute name.

If two objects in a scene have different parents, they're permitted to have the same name.

有些属性有多个值,比如translate,注意是多个值,而不是作为某种数据类型的一个值。
getting多值属性:把这个属性赋给一个数组,操作数组;setting多值属性:setAttr,但不能把一个数组赋给这个属性,而是把值作为几个参数排列在后面。
有的属性是一个属性数组,比如nurbsSphereShape1.cv[][],curve1.cv[],可以用wildcard:nurbsSphereShape1.cv["*"]["*"],这代表这个属性数组里的所有的元素。

关于operator return:如果procedure名前面没有加data type,则说明此函数不返回值,那么return操作符不能结合数值使用,只能单独使用,作用是结束这个procedure,相当于break语句。

Variables you define outside of procedures are visible (able to be accessed and changed) to all other top level MEL code. Variables you define inside a procedure are only visible within that procedure. These variables are called local variables.
A local variable will override a global variable with the same name within the procedure.
The eval command is executed at the top level MEL scope. Therefore, it recognizes global variables but does not recognize variables that you define inside a procedure (local variables).


如果表达式里有循环,必须循环结束后MAYA才会更新属性。

删除一个expression:点clear,再点edit。

generally,按procedure执行的反序排列proc definition的位置。

包含custom dialog box的script的结构:

entry procedure(生成界面;call button procedure)=》button procedure(收集数据;call validation procedure;处理错误;call function procedure;关闭界面)=》validation procedure                                                                                ||      

                                                                                     function procedure(和界面是完全独立的)

window => layout => controls, groups(multiple controls work together), collections(make controls work together)

每个layout和control都有一个parent,默认是紧挨着它的上面那个layout或window,可以用setParent命令设置,参数可以直接指定,也可以相对指定。“..”意思是下面的layout的parent是其默认parent的上面那个layout。

如果要结束一个window,用window command或showWindow command;如果要结束一个layout为parent,用setParent。

menu独立于layout,写在一个window定义的第一级。

要用setParent结束哪个layout,就把这个setParent和那个layout的缩进写成一样,看起来好像是哪个layout和setParent成对出现,他就结束了一样。

columnLayout不必指定行数;rowLayout要,不指定即为一列。

再次关于global variable和local variable:top level code和任何每个procedure都自成一个scope,这个scope里面的变量是local variable;global variable也是一个scope,这个scope里面的变量top level code不用redeclaration就可以存取,其他的procedure需要redeclaration。

关于`button -command "buttonAction($varA)"`:
首先,这个command string必须加双引号。
最重要的:$varA必须是一个global variable,且必须在button procedure的最前面declaration。这是因为:执行双引号里面的function call和直接在procedure里进行function call是不一样的,而是相当于在top level执行function call,根据global variable的定义,只有当variable是global,这个function call才能找到变量。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值