您好,欢迎来到我的51CTO博客,这是我在51CTO的第一篇文章。
我今天分享的是一个Maya大纲重命名节点的工具。
作者Artstation主页:https://www.artstation.com/igorsilva3d/store
作者主页还有两款插件,由于用不到也没有了解。感兴趣可以去看一下。
ig_EzRename
这款插件我第一次用到是在劲暴羊工具盒里面。由于画忆大佬的推荐加入到了羊盒里面。后来用了Maya的2022版本,不支持羊盒,不支持Python2的的脚本。后来就不太使用这款插件了,再后来无意间发现了这个插件的作者,去作者的主页发现了作者已经更新了1.3版本,主要是针对Python3进行的版本升级,下载下来使用了一下,支持了Maya2022。这个插件有一个很好的功能,"干掉pasted__"。既然支持了新版本的Maya,那就再拿回来用一下吧。
原版依旧是纯英文版,虽然常用的功能看英文也能使用,感觉不太明了,又看了一下画佬推荐的版本。我就进行了对这个插件的汉化优化,主要修改了汉化,对布局进行了一些优化,大部分查考了以前的汉化版。我是基于原作者的1.3版本支持Python3的脚本进行修改,修改后进行测试,支持Maya2018,Maya2020,Maya2022,运行没有问题。
下载
蓝奏云:https://zhangzhilong.lanzoue.com/iKSeX16m8w2h
压缩包内包含三个版本,作者原版,画忆推荐版本,我的修改版。
画忆推荐版:只支持Maya2022以下版本。
三岁豆Er修改版:支持Maya2018,Maya2020,Maya2022。其他版本没用测试。
安装插件方法
把 ig_EzRename.py 复制到C:\Users\Administrator\Documents\maya\scripts 路径下
在Maya的Python脚本编辑器内输入启动脚本启动该插件
启动方法有两种,一种是Maya2022以下版本Python2环境的启动脚本
还有一种是Maya2022版本以上Python3环境的启动脚本
Python2启动脚本(Maya2022以下版本)
import ig_EzRename
reload(ig_EzRename)
ig_EzRename.UI()
Python3启动脚本(Maya2022以上版本)
from importlib import reload
import ig_EzRename
reload(ig_EzRename)
ig_EzRename.UI()
源码
# -*- coding: gb2312 -*-
import maya.cmds as cmds
def UI():
global SelectName
global RenameText
global StartValue
global PaddingValue
global NumberCheck
global RemoveFirst
global RemoveEnd
global PrefixText
global SuffixText
global SearchText
global ReplaceText
global SRCheck
#UI Width
sizeX = 280
version = "v1.3"
if cmds.window("igEzRenameWin", exists=True):
cmds.deleteUI("igEzRenameWin", window=True)
#Creating UI
igEzRenamWin = cmds.window("igEzRenameWin", title="重命名工具 "+version, width=sizeX+6, height=385, mnb = True, mxb = False, sizeable = False)
#Creating interface elements
mainLayout = cmds.columnLayout("mainColumnLayout", width = sizeX, adjustableColumn=False, co = ["both",2])
#Select All Button
cmds.separator(h=5, style = "none", parent = mainLayout)
cmds.button(label = "选择全部", w=sizeX, h=30, c=SelectAll, ann = "选择场景中的所有对象")
cmds.separator(h=5, style = "none", parent = mainLayout)
#Select by Name
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 30), (2, 60)], cs = [(5,5), (5,5)])
cmds.button(label = "按名称选择", w=sizeX/3, h=30, c=SelectName, align = "Center", ann="按名称选择对象")
SelectName = cmds.textField(w = sizeX*0.646)
cmds.separator(w = sizeX, h=15, style = "in", parent = mainLayout)
#Rename and Number
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)])
#Rename Field
cmds.text(label=" 重命名 :", font = "boldLabelFont", w = sizeX/4, align="left")
RenameText = cmds.textField(w = sizeX*0.75)
#Start Field
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)])
cmds.text(label=" 开始 :", font = "boldLabelFont", w = sizeX/4, align="left")
StartValue = cmds.textField(w = sizeX/4, tx="1")
#Padding Field
cmds.text(label=" 位数 :", font = "boldLabelFont", w = sizeX/4, align="left")
PaddingValue = cmds.textField(w = sizeX/4, tx="2")
#Number Letters
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 20), (2, 60)])
cmds.text(label="", font = "boldLabelFont", w = sizeX/4-2, align="left")
NumberCheck = cmds.radioButtonGrp(labelArray2=[ '数字', '字母'], numberOfRadioButtons=2, w=sizeX, h=20, sl=1, cw = ([1,120]))
#ButtonRename and Number
cmds.separator(h=5, style = "none", parent = mainLayout)
cmds.button(label = "重命名和编号", w=sizeX, h=30, c=RenameNumber, align = "Center", parent = mainLayout, bgc = (.1,.5,.3))
cmds.separator(w = sizeX, h=15, style = "in", parent = mainLayout)
#RemoveCharacter
#Remove First/Last
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)], cs = [(5,5)])
cmds.text(label=" 移除:", font = "boldLabelFont", w = sizeX/3-12, align="left")
cmds.button(label = "首字符->", w=sizeX/3, h=25, c="ig_EzRename.Remove(True)", align = "Center")
cmds.button(label = "<-末尾字符", w=sizeX/3, h=25, c="ig_EzRename.Remove(False)", align = "Center")
cmds.separator(h=5, style = "none", parent = mainLayout)
#Remove pasted__
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)], cs = [(90,91)])
cmds.text(label=" ", font = "boldLabelFont", w = sizeX/3, align="left")
cmds.button(label = "干掉 pasted__", w=sizeX/3, h=25, c=RemovePasted, align = "Center")
#Remove UI
cmds.separator(h=5, style = "none", parent = mainLayout)
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)], cs = [(8.5,8.5)])
RemoveFirst = cmds.textField(w = sizeX/5, tx="1", ann="写下你想在文本开头删除的字符数量")
cmds.button(label = "-", w=25, h=25, c="ig_EzRename.RemoveChar('begin')", align = "Center", ann="在文本开头处删除")
cmds.button(label = "移除", w=sizeX/4, h=25, c="ig_EzRename.RemoveChar('all')", align = "Center", ann="在文本开头和末尾处删除")
cmds.button(label = "-", w=25, h=25, c="ig_EzRename.RemoveChar('end')", align = "Center", ann="在文本末尾处删除")
RemoveEnd = cmds.textField(w = sizeX/5, tx="1", ann="写下你想在文本末尾删除的字符数量")
cmds.separator(w = sizeX, h=15, style = "in", parent = mainLayout)
#Suffix
#Control Suffix
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)], cs = [(5,5)])
cmds.text(label=" 前缀:", font = "boldLabelFont", w = sizeX/4-10, align="left", ann="添加前缀")
PrefixText = cmds.textField(w = sizeX/2.5+33, tx="Prefix_", ann="输入你想添加的前缀名称")
cmds.button(label = "添加", w=sizeX/4-10, h=25, c="ig_EzRename.PrefixSuffix(False)", align = "Center")
cmds.separator(h=5, style = "none", parent = mainLayout)
#Group Suffix
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)], cs = [(5,5)])
cmds.text(label=" 后缀:", font = "boldLabelFont", w = sizeX/4-10, align="left", ann="添加后缀")
SuffixText = cmds.textField(w = sizeX/2.5+33, tx="_Mesh", ann="请输入你想添加的后缀名称")
cmds.button(label = "添加", w=sizeX/4-10, h=25, c="ig_EzRename.PrefixSuffix(True)", align = "Center")
cmds.separator(w = sizeX, h=15, style = "in", parent = mainLayout)
#Prefix
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 30), (2, 60)], cs = [(5,5)])
cmds.button(label = "_Grp", w=sizeX/5-4, h=25, c="ig_EzRename.Suffix('_Grp')", align = "Center", ann = "添加 Grp 后缀", bgc = (.1,.2,.3))
cmds.button(label = "_Geo", w=sizeX/5-4, h=25, c="ig_EzRename.Suffix('_Geo')", align = "Center", ann = "添加 Geo 后缀", bgc = (.1,.2,.3))
cmds.button(label = "_Hi", w=sizeX/5-4, h=25, c="ig_EzRename.Suffix('_Hi')", align = "Center", ann = "添加 Hi 后缀", bgc = (.1,.2,.3))
cmds.button(label = "_Jnt", w=sizeX/5-4, h=25, c="ig_EzRename.Suffix('_Jnt')", align = "Center", ann = "添加 Jnt 后缀", bgc = (.1,.2,.3))
cmds.button(label = "_Drv", w=sizeX/5-4, h=25, c="ig_EzRename.Suffix('_Drv')", align = "Center", ann = "添加 Drv 后缀", bgc = (.1,.2,.3))
cmds.separator(w = sizeX, h=15, style = "in", parent = mainLayout)
#Search and Replace
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)], cs = [(5,5)])
cmds.text(label=" 搜索:", font = "boldLabelFont", w = sizeX/4-10, align="left")
SearchText = cmds.textField(w = sizeX/2+100)
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 25), (2, 60)], cs = [(5,5)])
cmds.text(label=" 替换:", font = "boldLabelFont", w = sizeX/4-10, align="left")
ReplaceText = cmds.textField(w = sizeX/2+100)
cmds.rowColumnLayout( numberOfRows=1, w=sizeX, parent=mainLayout, rowHeight=[(1, 30), (2, 60)], cs = [(5,5)])
SRCheck = cmds.radioButtonGrp(labelArray3=[ '已选择', '层级', '全部'], numberOfRadioButtons=3, w=sizeX, h=30, sl=1, cw = ([1,100],[2,100],[3,100]))
cmds.button(label = "应 用", w=sizeX, h=30, c=SearchReplace, align = "Center", parent = mainLayout, bgc = (.1,.5,.3))
cmds.separator(h=5, style = "none", parent = mainLayout)
#Show UI:
cmds.showWindow(igEzRenamWin)
def SelectAll(*args):
cmds.select(ado=True, hi = True)
selection = cmds.ls(selection=True, sn=True)
selectionAdd = []
def SelectName(*args):
cmds.select(cl=True)
name = cmds.textField(SelectName, text = 1, q=True)
try:
selection = cmds.ls(name, l = True)
except:
cmds.warning("Object Don't Exist")
for objs in selection:
cmds.select(objs, add=True)
def RenameNumber(*args):
number = cmds.textField(StartValue, text = 1, q=True)
number = int(number)
padding = cmds.textField(PaddingValue, text = 1, q=True)
padding = int(padding)
NumberLetters = cmds.radioButtonGrp(NumberCheck, q=True, select=True)
newName = cmds.textField(RenameText, text = 1, q=True)
selection = cmds.ls(selection=True, sn=True)
lettersList = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
#Number suffix
y = 0
for obj in selection:
try:
#Teste if has duplicate mesh with the same name on the scene and return the name without parents
trueName = testDuplicateName(obj)
#Save the original name
oldName = trueName
#If true use numbers, else use letters
if NumberLetters == 1:
zeros = ""
for x in range(int(padding)):
if len(str(number)) <= x:
zeros = zeros+"0"
#Create the newName and rename
name = newName+"_"+"{:0>"+str(padding)+"}"
newNameList = name.format(number)
cmds.rename(obj, name.format(number))
else:
newNameList = newName+"_"+lettersList[y]
cmds.rename(obj, newName+"_"+lettersList[y])
if y < len(lettersList)-1:
y+=1
else:
y=0
#For to rename all the oldNames on list to newNames
for x in range(len(selection)):
newParentName = selection[x].replace(oldName, newNameList)
selection[x] = newParentName
except:
pass
number = int(number+1)
def RemoveChar(Type):
first = cmds.textField(RemoveFirst, text = 1, q=True)
end = cmds.textField(RemoveEnd, text = 1, q=True)
selection = cmds.ls(selection = True, sn=True)
for objs in selection:
#Teste if has duplicate mesh with the same name on the scene
trueName = testDuplicateName(objs)
#Save the original name
oldName = trueName
if Type == "all":
name = trueName[:-int(end)]
name = name[int(first):]
if Type == "begin":
name = trueName[int(first):]
if Type == "end":
name = trueName[:-int(end)]
try:
cmds.rename(objs, str(name))
except:
pass
#For to rename all the oldNames on list to newNames
for x in range(len(selection)):
newParentName = selection[x].replace(oldName, name)
selection[x] = newParentName
def Remove(Type):
selection = cmds.ls(selection = True, sn = True)
for objs in selection:
#Teste if has duplicate mesh with the same name on the scene
trueName = testDuplicateName(objs)
#Save the original name
oldName = trueName
if Type:
name = trueName[1:]
else:
name = trueName[:-1]
try:
cmds.rename(objs, name)
except:
pass
#For to rename all the oldNames on list to newNames
for x in range(len(selection)):
newParentName = selection[x].replace(oldName, name)
selection[x] = newParentName
def RemovePasted(*args):
selection = cmds.ls("pasted__*", sn = True)
for objs in selection:
#Teste if has duplicate mesh with the same name on the scene
trueName = testDuplicateName(objs)
name = trueName[8:]
try:
cmds.rename(objs, name)
except:
cmds.warning("已删除字符 pasted__")
def PrefixSuffix(Suffix):
prefix = cmds.textField(PrefixText, text = 1, q=True)
suffix = cmds.textField(SuffixText, text = 1, q=True)
selection = cmds.ls(selection = True, sn = True)
for objs in selection:
#Teste if has duplicate mesh with the same name on the scene
trueName = testDuplicateName(objs)
#Save the original name
oldName = trueName
if Suffix:
name = str(trueName)+suffix
else:
name = prefix+str(trueName)
try:
cmds.rename(objs, name)
except:
pass
#For to rename all the oldNames on list to newNames
for x in range(len(selection)):
newParentName = selection[x].replace(oldName, name)
selection[x] = newParentName
def Suffix(Text):
selection = cmds.ls(selection = True, sn = True)
for objs in selection:
#Test if has duplicate mesh with the same name on the scene
trueName = testDuplicateName(objs)
#Save the original name
oldName = trueName
newName = trueName+Text
try:
cmds.rename(objs, newName)
except:
pass
#For to rename all the oldNames on list to newNames
for x in range(len(selection)):
newParentName = selection[x].replace(oldName, newName)
selection[x] = newParentName
def SearchReplace(*args):
search = cmds.textField(SearchText, text = 1, q=True)
replace = cmds.textField(ReplaceText, text = 1, q=True)
SRMethod = cmds.radioButtonGrp(SRCheck, q=True, select=True)
#Selected search and Replace method
if SRMethod == 1:
selection = cmds.ls(selection = True, sn = True)
#Hierarchy search and Replace method
if SRMethod == 2:
cmds.select(hi = True)
selection = cmds.ls(selection = True, sn = False)
#All search and Replace method
if SRMethod == 3:
#Select All DagObjects in scene
selection = []
cmds.select(ado = True, hi = True)
selection = cmds.ls(selection = True, sn=False)
#for to rename the objects
for obj in selection:
#Teste if has duplicate mesh with the same name on the scene and return the name without parents
trueName = testDuplicateName(obj)
#Save the original name
oldName = trueName
#Search and replace to create the new name
newName = trueName.replace(search, replace)
#Rename the object
try:
cmds.rename(obj, newName)
except:
pass
#For to rename all the oldNames on list to newNames
for x in range(len(selection)):
newParentName = selection[x].replace(oldName, newName)
selection[x] = newParentName
print("Slecao: ", selection)
def testDuplicateName(Obj):
try:
trueName = Obj.split("|")
return trueName[len(trueName)-1]
except:
return Obj