在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)