- As per the documentation rename command takes only strings as input parameters. You are providing a list named
objects
while trying to rename the filenames. - Moreover, you are searching for string
"test"
inobjects
list. Instead you should search for string"test"
in each filename which is present in objects list. rename
command renames the old string with the newer one. It does not replace the substring within a string (e.g. "sphere" in "nurbsSphere"). In order to achieve this you should create the new filenames separately and then use them to rename the files.
You can try this:
charReplace = "test"
for filename in objects:
if charReplace in filename:
newFilename = filename.replace(charReplace, "Circle")
cmds.rename(filename, newFilename)
I do not have Maya installed so code is not tested.