创建新的nHair系统集

时间:2014-08-26 07:49:06

标签: python maya

编写一套新发系统的python方法是什么? 显然,当我尝试运行我的代码时,它只能创建第一组hairSystem,并且当试图再次重新运行它时,它无法这样做。

编辑:我设法解决了我的其他问题,但目前我遇到了hairSystem的问题

def createPlane(self):
        global nurbsPlane
        # Create the nurbsPlane
        nurbsPlane = cmds.nurbsPlane(n = "nurbsPlane", p=[0,0,0], ax = [0,1,0], w=1, lr=5, d=3, u=1,v=5, ch=1)
        cmds.select(nurbsPlane, r=True)
        # Cleanup the control vertexs
        mm.eval("createHair 1 5 5 0 0 0 0 5 0 2 1 1;")
        cmds.rename("hairSystem1Follicles", "hairSys_Follicles")

1 个答案:

答案 0 :(得分:1)

在第一次运行后尝试重命名hairSystem1Follicles时,Maya会抛出错误,因为创建的对象具有不同的名称。这是maya.cmds / MEL世界的基本问题之一。但是对于我们的优势,createHair方法在成功运行后保持hairSystem的选择。我们可以利用这个事实来动态地找出您尝试在代码中重命名的已创建的hairSystemFollicles组。您可以尝试以下解决方案:

import maya.cmds as cmds
import pymel.core as pm

def createPlane(self):
    # Create the nurbsPlane
    nurbsPlane = cmds.nurbsPlane(n = "nurbsPlane", p=[0,0,0], ax = [0,1,0], w=1, lr=5, d=3, u=1,v=5, ch=1)
    cmds.select(nurbsPlane, r=True)
    # Cleanup the control vertices

    pm.language.Mel.eval("createHair 1 5 5 0 0 0 0 5 0 2 1 1;") # Pymel's evals are easier to debug and more robust
    created_hairsystem = pm.PyNode("hairSystem1")
    follicles_created = created_hairsystem.getShape().listFuture(type="follicle")
    follicles_group = pm.nodetypes.DagNode(follicles_created[0]).getParent(generations=2)
    cmds.rename(follicles_group, "hairSys_Follicles")

此方法始终有效。