Maya重命名工具:ig_EzRename

作者:https://www.artstation.com/igorsilva3d/store (需科学上网)

image-20230827161845157

作者官网还有两款插件,由于用不到也没有了解。感兴趣可以去看一下。

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环境的启动脚本

2024年1月24日更新

如果你懒得选择版本,我将提供一个判断的脚本帮您自动完成。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import sys

# 检查当前Python版本
if sys.version_info[0] >= 3:
# Python 3代码
from importlib import reload
import ig_EzRename
reload(ig_EzRename)
ig_EzRename.UI()
else:
# Python 2代码
import ig_EzRename
reload(ig_EzRename)
ig_EzRename.UI()

Python2启动脚本(Maya2022以下版本)

1
2
3
import ig_EzRename
reload(ig_EzRename)
ig_EzRename.UI()

Python3启动脚本(Maya2022以上版本)

1
2
3
4
from importlib import reload
import ig_EzRename
reload(ig_EzRename)
ig_EzRename.UI()

源代码

三岁豆Er修改版源代码

文件名:ig_EzRename.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# -*- 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