3dsmax python 为子动画添加浮动脚本

3dsmax python add float script to sub animations

我有下一个设置:我有一个带有变形修改器的球体。这个 morpher 修改器有一定数量的通道,其中充满了变形目标,也就是子动画。现在我想为每个子动画添加一个控制器,更具体地说是一个带有浮动脚本的控制器。我有应该工作的代码片段,但是当我转到曲线编辑器时,变形通道/子动画没有改变控制器,它们的控制器的值也没有改变。

import MaxPlus
target = MaxPlus.INode.GetINodeByName('Sphere001')
#Retrieve the morpher modifier
mod = target.GetModifier(0)
#ID of a float script controller
id = MaxPlus.Class_ID(1233584870,1911625032)
#Create float controller
float_co = MaxPlus.Factory.CreateFloatController(id)
#Retrieve the first morph channel / sub animation
sub = mod.GetSubAnim(1)
#Controller is assigned to the sub animation
sub.AssignController(float_co,1)
#Basic test which assigns 20 to the sub animation
float_co.ParameterBlock.Script.Value = '20'

当我向脚本添加错误值时,例如:

float_co.ParameterBlock.Script.Value = '=20'

当您手动将控制器添加到对象或节点时,我收到错误和常见的 window。然而奇怪的是,在 window 的顶部:它所连接的对象的名称并没有显示。看图说明:

有人可以告诉我我做错了什么吗?谢谢!

我用丑陋的方式解决了它:

import MaxPlus
test = MaxPlus.FPValue()
success = MaxPlus.Core.EvalMAXScript(string_with_command,test)

这被使用了两次:第一次创建浮动脚本控制器,第二次将脚本添加到控制器。如果有人想尝试这个,请小心,控制器的脚本需要是一个字符串。不要使用

x as string

使用您想要用作浮动脚本控制器脚本的表达式,因为 maxscript 将在您当前处于 3ds max 中的时间范围内评估 x,并将此值转换为字符串。该值将用作所有时间范围的脚本,这显然不是您想要的。我使用的一个小技巧是:

script_value_example = '"amax #(0, ($sphere.position.x - cube.position.y))"'

这仍然是 python 的字符串,maxscript 会看到“”并将其解释为字符串。反之亦然,maxscript 不会将 ' ' 解释为字符串。 也许这会在将来帮助某人。另外,如果有人知道使用问题中的代码进行此操作的正确方法,请留下回复,我很想知道。