Stuck on a Rename + Find and Replace Script

Stuck on a Rename + Find and Replace Script

Anonymous
Not applicable
811 Views
1 Reply
Message 1 of 2

Stuck on a Rename + Find and Replace Script

Anonymous
Not applicable
Any ideas on what I'm missing? When I click the button that executes the replace function, nothing happens, no errors, no results...


#Import Necessary Modules
import maya.cmds as mc

# mc.ls( selection = True, long = True, flatten = True )

# Find the First Index
def firstIndexFind( item = "", inList = [] ):
for i in range( len(inList) ):
if inList == item:
return i
else:
pass

# Remembers Original Selection Order
def getListMap( unchanged = [], changed = [] ):
returnList = []
searchList = unchanged
for i in range( len( changed ) ):
fI = firstIndexFind( changed, searchList )
returnList.append( fI )
searchList = ""
return returnList

# Function to Rename Selected Objects
def rName(*args):
unsorted = mc.ls( selection = True, long = True, flatten = True )
newN = mc.textField( 'NEWNAME', query = True, text = True )
sortedL = sorted( unsorted )
map = getListMap( unsorted, sortedL )
# Iterated Through List Backwards
for iM in range( len(map) -1, -1, -1 ):
eI = map
mc.rename( unsorted, newN )
return unsorted

# Function to replace chosen string in the names of selected objects
def rpName(*args):
oldN = mc.textField( 'ONAME', query = True, text = True )
newN = mc.textField( 'RNAME', query = True, text = True )
selObjs = mc.ls( selection = True, long = True, flatten = True )
oList = []
for i in range(len(selObjs)):
cObj = selObjs
cObj = cObj.replace( oldN, newN )
oList.append(cObj)
selObjs = oList

# UI Call Function
def openUI():
if mc.window( 'Rename Tools', exists = True ):
mc.deleteUI( 'Rename Tools', window = True )
window = mc.window( 'Rename Tools' )
mc.columnLayout( 'primeColumn', adjustableColumn = False, height=180, width=360 )
mc.frameLayout( 'rpName', label = 'Replace Name', parent = 'primeColumn', collapsable = False )
mc.rowLayout( numberOfColumns = 4 )
mc.text( label = 'Original Name' )
mc.textField( 'ONAME' )
mc.text( label = 'New Name' )
mc.textField( 'RNAME' )
mc.setParent( '..' )
mc.setParent( '..' )
mc.columnLayout()
mc.button( label = 'Replace', command = rpName )
mc.setParent( '..' )
mc.setParent( '..' )
mc.frameLayout( 'reNameIter', label = 'Rename', parent = 'primeColumn', collapsable = False )
mc.rowLayout ( numberOfColumns = 3 )
mc.text( label = 'New Name' )
mc.textField( 'NEWNAME' )
mc.button( label = 'Rename', command = rName )
mc.setParent( '..' )
mc.setParent( '..' )
mc.showWindow( window )
0 Likes
812 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
You're replacing a string alright, but you're not actually renaming the object.

def rpName(*args):
oldN = mc.textField( 'ONAME', query = True, text = True )
newN = mc.textField( 'RNAME', query = True, text = True )
selObjs = mc.ls( selection = True, long = True, flatten = True )
oList = []
for i in range(len(selObjs)):
cObj = selObjs
oldName = cObj
newName = cObj.replace( oldN, newN )
mc.rename (oldName, newName)
oList.append(cObj)
selObjs = oList
0 Likes