我正在编写一个脚本,该脚本复制所选网格中的曲线。
一旦创建了曲线,我希望它根据用于创建带有后缀的曲线的原始网格名称重命名结果。例如:“ meshName_Crv”或类似名称。
import pymel.core as pm
#Select meshes to use as a source for copying the curves.
tarlist = pm.ls(selection=True, fl=True)
#Select an edge within the selected meshes
edgelist = pm.ls(selection=True, fl=True)
alledgelist = []
for i in edgelist:
index = i.index()
for tar in tarlist:
tarpy = pm.PyNode(tar)
alledgelist.append(tarpy.e[index])
for edges in alledgelist:
pm.select(edges)
pm.mel.eval('SelectEdgeLoop;')
pm.mel.eval('polyToCurve -form 2 -degree 3;')
当前,它正在创建默认名称为“ polyToCurve”的曲线。 但是我需要根据原始的源网格进行重命名。
我知道到目前为止我的代码还不够完善... 我将不胜感激。
答案 0 :(得分:0)
许多命令记录在案:https://help.autodesk.com/cloudhelp/2018/CHS/Maya-Tech-Docs/CommandsPython/polySelect.html
每个命令都有很多示例,还包括一些标志:-name
如果此文档中未显示命令,则可以输入mel:
whatIs commandName;
它将为您提供模块的路径
我也喜欢使用regex,所以我在这里使用了regex,但是您可以将其删除,因为我给了您另一条22行(虽然感觉不太干净,但是可以使用)
import maya.cmds as cmds
# if using regex
import re
#Select meshes to use as a source for copying the curves.
# pSphere3 pSphere2 pSphere1
tarlist = cmds.ls(selection=True, fl=True)
#Select an edge within the selected meshes
# pSphere3.e[636]
edgelist = cmds.ls(selection=True, fl=True)
# Result: [u'e[636]'] #
indexes = [i.split('.')[-1] for i in edgelist]
# Result: [u'pSphere3.e[636]', u'pSphere2.e[636]', u'pSphere1.e[636]'] #
alledgelist = [t+'.'+i for i in indexes for t in tarlist]
# regex = `anyString`.e[`anyDigit`] \\ capture what is in ``
p = re.compile('(\w+).e\[(\d+)\]')
for e in alledgelist:
# without regex
name, id = e.replace('e[', '')[:-1].split('.')
# with regex
name, id = p.search(e).group(1), p.search(e).group(2)
edgeLoop = cmds.polySelect(name, el=int(id))
cmds.polyToCurve(form=2, degree=3, name='edgeLoop_{}_{}'.format(name, id))