-
Notifications
You must be signed in to change notification settings - Fork 2
/
mayaRenamer.py
102 lines (93 loc) · 3.65 KB
/
mayaRenamer.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
'''..................................................................................................
Author: Diego Inácio
GitHub: github.com/diegoinacio
Date: NOV/12/2012
.....................................................................................................
This script is a simple renamer for objects, nodes or anything in your scene do you want to rename.
If you have any comment send it to: diegodci@gmail.com
Thank you! :D
..................................................................................................'''
import maya.cmds as cmds
ui = 'mayaRenamer'
version = '1.0.0'
title = ui + ' ' + version
#############
# Functions #
#############
def closeUI():
if cmds.window(ui, menuBar = True, exists = True):
cmds.deleteUI(ui)
def mayaRenamerUI():
global field1
global field2
global field3
global field4
global field5
closeUI()
cmds.window(ui, title = title, sizeable = False)
tabs = cmds.tabLayout()
tab1 = cmds.columnLayout(columnAttach = ['both', 5], rowSpacing = 10, columnWidth = 220)
cmds.separator(style = 'in')
cmds.text(label = '..: Renamer :..')
cmds.separator(style = 'out')
cmds.frameLayout(label = 'Search and Replace', borderStyle='etchedIn', collapse = True, collapsable = True)
cmds.text(label = 'Search for:')
field1 = cmds.textField()
cmds.text(label = 'Replace with:')
field2 = cmds.textField()
cmds.button(label = 'Apply', command = 'srOption()')
cmds.setParent('..')
cmds.frameLayout(label = 'Prefix and Sufix', borderStyle='etchedIn', collapse = True, collapsable = True)
cmds.text(label = 'Sufix:')
field3 = cmds.textField()
cmds.text(label = 'Prefix:')
field4 = cmds.textField()
cmds.button(label = 'Apply', command = 'psOption()')
cmds.setParent('..')
cmds.frameLayout(label = 'Rename', borderStyle='etchedIn', collapse = True, collapsable = True)
cmds.text(label = 'Rename:')
field5 = cmds.textField()
cmds.button(label = 'Apply', command = 'rOption()')
cmds.setParent('..')
cmds.setParent('..')
tab2 = cmds.columnLayout(columnAttach = ['both', 5], rowSpacing = 10, columnWidth = 220)
cmds.text(label = info(), wordWrap = True)
cmds.tabLayout( tabs, edit=True, tabLabel=((tab1, 'Main'), (tab2, 'Info')))
cmds.setParent('..')
cmds.showWindow()
def srOption():
sel = []
sel = cmds.ls(selection = True)
if sel == []: noSelection()
else:
search = cmds.textField(field1, text = True, query = True)
replace = cmds.textField(field2, text = True, query = True)
for i in range(len(sel)):
temp = sel[i].replace(search, replace)
cmds.rename(sel[i], temp)
def psOption():
sel = []
sel = cmds.ls(selection = True)
if sel == []: noSelection()
else:
prefix = cmds.textField(field3, text = True, query = True)
sufix = cmds.textField(field4, text = True, query = True)
for i in range(len(sel)):
cmds.rename(sel[i], prefix + sel[i] + sufix)
def rOption():
sel = []
sel = cmds.ls(selection = True)
if sel == []: noSelection()
else:
renamer = cmds.textField(field5, text = True, query = True)
for i in range(len(sel)):
cmds.rename(sel[i], renamer + str(i + 1))
def noSelection():
cmds.confirmDialog(message = 'no object was selected')
def info():
infoText = ".: mayaRenamer :.\n\nThis script is a simple renamer for objects, nodes or anything in your scene do you want to rename.\nIf you have any comment, sent it to me at:\ndiegodci@gmail.com\n\nThank you! :D\nDiego Inácio\n"
return(infoText)
########
# Main #
########
mayaRenamerUI()