【问题标题】:3D Max modifier index confusion3D Max 修改器索引混乱
【发布时间】:2019-03-06 21:00:07
【问题描述】:

我有一个应用蒙皮修改器的 3DS Max 场景对象。我想把它转换成蒙皮修改器,然后在堆栈中直接删除它下面的蒙皮包裹。

所以我应该通过它的堆栈号简单地删除修饰符吗? 哎呀,我什至有一个打印行来标识它在堆栈中的编号。

我为 python 和 EvalMAXScript 之间的来回道歉,我不是程序员,只是一个难以理解的人。

# setup =======================================================

import MaxPlus as mp
from pymxs import runtime as rt

mySel = rt.selection
max = mp.Core.EvalMAXScript

box    = mp.Factory.CreateGeomObject(mp.ClassIds.Box)
sphere = mp.Factory.CreateGeomObject(mp.ClassIds.Sphere)
cyl    = mp.Factory.CreateGeomObject(mp.ClassIds.Cylinder)
node   = MaxPlus.Factory.CreateNode

node(box)
node(sphere)
node(cyl)
#setup =======================================================

max("select #($Sphere001, $Cylinder001)")

# =============================================
rt.addModifier (mySel[0], rt.Skin())
max("select $Sphere001")
max("skinOps.addBone $.modifiers[#Skin] $Cylinder001 1")
# =============================================

max("select $Box001")

rt.addModifier (mySel[0], rt.Skin_Wrap())
max("append $" + str(mySel[0].name) +".modifiers[#Skin_Wrap].meshList $Sphere001")
mySel[0].modifiers[0].meshDeformOps.convertToSkin (False) 

print mySel[0].modifiers[0].name + " <----- ZERO"
print mySel[0].modifiers[1].name + " <----- ONE!!!!"
#print mySel[0].modifiers[2].name  #<----- will say IndexError: Index out of range <--- This makes sense

rt.deleteModifier (mySel[0], 2) #<------------------ I want to delete the SKIN WRAP modifier SO WHY 2??? 

但是为什么删除蒙皮修饰符需要在 deleteModifer arg 中使用“2”?

打印出修改器的名称时,3Ds Max 的编号顺序与删除时的编号顺序不同吗?

这是否与 python 计数/迭代从 0 而不是 1 开始这一事实有关?

有人可以将我/或任何想在 max 中使用 python 学习脚本的人指向我可以获取有关此类信息的文档吗?因为我想像输入正确索引号这样常见的东西应该在一些基本文档中的某个地方(我显然没能找到)。

请原谅我的焦虑。我花了好几个小时试图弄清楚为什么这不起作用,直到我不小心偶然发现了一个超出范围的索引号。

谢谢。

【问题讨论】:

    标签: python 3dsmax


    【解决方案1】:

    according to the doc,您可以直接将修饰符而不是索引传递给deleteModifier函数:

    deleteModifier &lt;node&gt; &lt;modifier_or_index&gt;

    所以类似的东西可以工作:

    import MaxPlus as mp
    from pymxs import runtime as rt
    
    mySel = rt.selection
    max = mp.Core.EvalMAXScript
    
    node   = MaxPlus.Factory.CreateNode
    box = mp.Factory.CreateGeomObject(mp.ClassIds.Box)
    
    node_box = node(box) # Watch out, 'node_box' this is a MaxPlus node
    
    max("select $Box001")
    
    # Create the modifiers
    rt.addModifier (mySel[0], rt.Skin_Wrap()) # Skin Wrap
    rt.addModifier (mySel[0], rt.Skin()) # Skin
    
    # Get their references
    modifier_skin      = mySel[0].modifiers[0]
    modifier_skin_wrap = mySel[0].modifiers[1]
    
    print (modifier_skin.name + " <----- modifier_skin")
    print (modifier_skin_wrap.name + " <----- modifier_skin_wrap")
    
    rt.deleteModifier (mySel[0], modifier_skin_wrap)
    rt.deleteModifier (mySel[0], modifier_skin)
    

    你甚至可以做一个可以删除给定名称的修饰符的函数:

    import MaxPlus as mp
    from pymxs import runtime as rt
    
    def delete_modifier_by_name(node, modifier_name):
        max_node = rt.getnodebyname(node.Name)
        for modifier in max_node.modifiers:
            if modifier.name == modifier_name:
                print("Deleting %s..." % modifier.name)
                rt.deleteModifier (max_node, modifier)
                return
    
    mySel = rt.selection
    max = mp.Core.EvalMAXScript
    
    node   = MaxPlus.Factory.CreateNode
    box = mp.Factory.CreateGeomObject(mp.ClassIds.Box)
    
    node_box = node(box) # Watch out, 'node_box' this is a MaxPlus node
    
    max("select $Box001")
    
    # Create the modifiers
    rt.addModifier (mySel[0], rt.Skin_Wrap()) # Skin Wrap
    rt.addModifier (mySel[0], rt.Skin()) # Skin
    
    delete_modifier_by_name(node_box, "Skin")
    #~ delete_modifier_by_name(node_box, "Skin Wrap")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      相关资源
      最近更新 更多