On Sat, Jan 19, 2019, 4:51 AM delibrax <adien.den...@gmail.com> wrote:
> Hi there, > > I would like to adding the suffix regarding the object type. So here my py: > > import maya.cmds as mc > import re > > SUFFIXES = { > 'mesh' : 'geo', > 'joint' : 'jnt', > 'follicle' : 'fol', > 'nurbsCurve' : 'crv', > } > GROUP = 'grp' > > def renameObject(object): > > for obj in object: > sN = obj.split('|')[-1] > > lR = mc.listRelatives(sN, s=1) > > if lR == None: > objType = mc.objectType(obj) > else: > objType = mc.objectType(lR) > > suffix = SUFFIXES.get(objType, GROUP) > > regex = r'_.*' > > if not suffix: > continue > > if sN.endswith('_' + suffix): > continue > > if re.match(regex, sN): > continue > > newName = "%s_%s" % (sN, suffix) > > mc.rename(sN, newName) > > index = object.index(obj) > > object[index] = obj.replace(sN, newName) > > return object > > > so the result is : > > when the 'joint' or 'mesh' (without have any suffix) been selected then it > will has 'joint_jnt' and 'mesh_geo'. Otherwise if it is re-run then WON'T > be 'joint_jnt_jnt' (we know it happened by statements endswith) > > My problem is when the object has suffix without on list dictionary (let > say 'mesh_ply') then become 'mesh_ply_geo'. As you can see I wanna that > every object with suffix will 'continue'. Any advice?! Thanks in advance. > You would have to make a decision on whether you consider any object name containing an '_' to indicate that it has a suffix. That is, if 'mesh_ply' has a suffix then 'my_obj_name' also has a suffix. If that is acceptable, then your check should include: if '_' in sN: continue What was the intention of your regex test? regex = r'_.*' if re.match(regex, sN): continue This is a more expensive way of saying: if sN.startswith('_'): continue since we can be pretty sure nothing would ever be named only a single underscore character. > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to python_inside_maya+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/1a3567b0-e603-4c3c-8499-ca04a7bafe35%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/1a3567b0-e603-4c3c-8499-ca04a7bafe35%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0fCYiKndPMM1KQRRYNahnc0tc%3DHPoKQT7QmoSwV3PPPw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.