Reputation: 21
I have the following code:
import maya.cmds as cmds
list = cmds.ls(sl=True)
my_list = [object.upper() for object in list]
print(my_list)
However, it doesn't change the name of the objects even though it prints out upper case names in the print statement at the end.
Upvotes: 1
Views: 1104
Reputation: 4681
It's quite hackish, and I honestly wouldn't recommend it, but if you REALLY want to do that, you could do:
def global_var_to_upper(var):
for _ in globals():
if var is globals()[_]:
globals()[str(_).upper()] = globals()[_]
del globals()[_]
break
abc = 123
global_var_to_upper(abc)
print(ABC) # prints 123
Upvotes: 0
Reputation: 20344
What you want is
import maya.cmds as cmds
list = cmds.ls(sl=True)
for n in list:
cmds.rename(n, n.upper())
new_list = cmds.ls(sl=True)
print(new_list)
This is documented here with an example.
This code will rename all objects in list
you can also work with whichever you have selected with cmds.select()
if you want to.
Upvotes: 2
Reputation: 12679
The proper way to “mutate” a string is to use slicing and concatenation to build a new string by copying from parts of the old string.
Upvotes: 0