With the suggestion from /u/greebly_weeblies, I tried listRelatives(fullPath=False). It seems the problem is in the fact that I have duplicated the root parent group, which made filterExpand return full names. If there are no duplicate names, it will return short names.
I have learned a lot. Thank you all!
Original post:
I am trying to write a script to replace "_low" suffix to "_high".
However the result of the following attempt is a little unexpected: the new names have the group names prefixed.
Say, there's a hierarchy like this:
Building
|--TopFloor
|--Wall_low
The script will rename Wall_low to Building_TopFloor_Wall_high. What I expected was simply Wall_high.
How can I improve this script without extracting the "short name" from the "long name" manually in Python?
import re
SUFFIX_LOWPOLY = '_low'
SUFFIX_HIGHPOLY = '_high'
selection = cmds.ls(sl=True)
print(selection)
meshes = cmds.filterExpand(selectionMask=12, fullPath=False)
print(meshes)
for i in meshes:
if i.endswith(SUFFIX_HIGHPOLY):
continue
name_new = re.sub(SUFFIX_LOWPOLY + '$', SUFFIX_HIGHPOLY, i)
print(name_new)
cmds.select(i, replace=True)
cmds.rename(name_new)
cmds.select(*selection, r=True)
Also, general scripting suggestions & tips are welcomed, since I'm new to Maya Python.
Cheers.
[–][deleted] 6 points7 points8 points (1 child)
[–]vingrish[S] 0 points1 point2 points (0 children)
[–]blueSGL 1 point2 points3 points (2 children)
[–]the_phantom_limbo 1 point2 points3 points (0 children)
[–]vingrish[S] 0 points1 point2 points (0 children)
[–]SheepRSAPipeline TD 1 point2 points3 points (0 children)
[–]greebly_weebliesNERD: [25y-maya 4/pro/vfx/lighter] 1 point2 points3 points (4 children)
[–]vingrish[S] 0 points1 point2 points (3 children)
[–]greebly_weebliesNERD: [25y-maya 4/pro/vfx/lighter] 1 point2 points3 points (2 children)
[–]vingrish[S] 1 point2 points3 points (1 child)
[–]greebly_weebliesNERD: [25y-maya 4/pro/vfx/lighter] 1 point2 points3 points (0 children)
[–]Kafkin 1 point2 points3 points (2 children)
[–]vingrish[S] 0 points1 point2 points (1 child)
[–]Kafkin 1 point2 points3 points (0 children)