Max_Python_Help DOC 通读002

在python里执行Ms,在py文件里写入如下

import MaxPlus
MaxPlus.Core.EvalMAXScript("print #aaa")

然后Ctrl+E运行之后就看到了#aaa被print出来了

在Ms里执行Py,在ms文件里写入如下

commandString1 = 
"
import MaxPlus
MaxPlus.Core.EvalMAXScript(\"print #aaa\")
"
python.execute commandString1

然后Ctrl+E运行之后就看到了#aaa被print出来了

关于FPValue简单的记录一下

当ms表达式被执行的时候,在py里总会返回一个FPValue类型的值

举个?

import MaxPlus
fpvalue1 = MaxPlus.Core.EvalMAXScript("print #aaa; #(123')")

故意在表达式里多填入了一个单引号,执行这个命令之后,首先会执行print #aaa,会在监听窗口中打印#aaa

然后执行#(123'),报错,错误信息如下,此时runtime结束,后面的代码终止运行。

如果我们想这样做,“我管你报不报错,继续执行”

import MaxPlus
#~ MaxPlus.Core.EvalMAXScript("print #aaa")
#~ fpvalue1 = MaxPlus.Core.EvalMAXScript("print #aaa; #(123')")

res = MaxPlus.FPValue()
evaluation_success = MaxPlus.Core.EvalMAXScript("print #aaa; #(123')", res)
print(res.Get())
print(evaluation_success)
print(res)

这样就执行了整个脚本

看一下res.Get()  evaluation_success 和res究竟是什么

#aaa
-- Syntax error: at end of script, expected end of literal
--  In line: print #aaa;#(123')
False
__class_Autodesk__Max__FPValue_instance

可以看到,首先程序print了#aaa,

然后res.Get()返回了一个字符串,描述了错误类型,错误信息与错误位置。

而evaluation_success 得到的值是一个bool值,为false,说明这行语句没有正常结束。

res是FPValue的一个实例。

有人说直接try catch不就好咯。。。。呵呵,随便咯。。。到时候突然需要这种处理方式的时候,记着它一直都在就好了。

例外把文档里几个?也贴出来

import MaxPlus
obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Cone)
obj.ParameterBlock.radius1.Value = 5.0
obj.ParameterBlock.radius2.Value = 10.0
node = MaxPlus.Factory.CreateNode(obj)
node.Name = "PythonCone001"
r = MaxPlus.Core.EvalMAXScript('$'+node.Name)
import MaxPlus
# create a sphere node
node_name = "my_sphere"
obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Sphere)
node = MaxPlus.Factory.CreateNode(obj, node_name)
result = MaxPlus.FPValue()
# get one FPValue pointer to the object by running some MAXScript
evaluation_success = MaxPlus.Core.EvalMAXScript('$%s' % node_name, result)
handle1 =  result.Get()
# get a second pointer to the same object
evaluation_success = MaxPlus.Core.EvalMAXScript('$%s' % node_name, result)
handle2 = result.Get()

# this prints True:
print 'Objects are equal: %s' % (handle1 == handle2)
# this prints False:
print 'Objects are not equal: %s' % (handle1 != handle2)
# this prints False:
print 'Objects are identical: %s' % (handle1 is handle2)
# this prints True:
print 'Objects are not identical: %s' % (handle1 is not handle2)

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值