MEL中神奇的运算符“ + ”

MEL中神奇的运算符“ + ”
MEL中的“+”,不仅可以对数值作“加”运算,而且可以对字符串、数值、变量等作相加运算。
看下面的MEL实例:
int $year = 2006;
string $country = " Germany ";
string $event = "World Cup";
string $champion = "Italy";
print "\n";
print ("The last World Cup is at " + ($year-4) + ".\n");
print ("Here is " + $year + $country + $event + ".\n");
print ("The champion is " + $champion + "!!!\n");
将其输入脚本编辑器,并执行,运行结果如图:

图 运行MEL
在上面的MEL 中的print 命令中,即有字符又有整数,MEL均可以使用“+”将它们连接起来。
再看下面的例子:
string $pre = "T_";
int $n = 7;
string $post = "_00";
string $Name = $pre + $n + $post;
print $Name;
print "\n";
rename trees $Name;
将其输入脚本编辑器执行,运行结果如图,我们使用“+”将字符串、数值混合,并存储在一个变量中了。

图 使用“+”将字符串、数值混合

作者: hmaya

developer!

看完不过瘾?点此向作者提问

发表评论

邮箱地址不会被公开。 必填项已用*标注