Created
August 21, 2024 07:38
-
-
Save MustafaJafar/97a1e73f7b85b925c495e69a4a39e801 to your computer and use it in GitHub Desktop.
name_convention_fix_script.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" name convention fix script for Maya. | |
I used this script as a fix action for the following pyblish plugin in AYON: validate_transform_naming_suffix.py | |
plugin link: | |
https://github.com/ynput/ayon-maya/blob/develop/client/ayon_maya/plugins/publish/validate_transform_naming_suffix.py | |
""" | |
from collections import (defaultdict , OrderedDict ) | |
import maya.mel as mel | |
import maya.cmds as cmds | |
objs_dic = defaultdict( list ) | |
name_convs = OrderedDict( [ ("mesh" , "_GEO") , | |
("nurbsCurve" , "_CRV") , | |
("nurbsSurface" , "_NRB") , | |
("locator" , "_LOC") , | |
("transform" , "_GRP") ]) | |
for obj in cmds.ls(type = "transform" , l = 1): | |
child = cmds.listRelatives(obj , children = 1 , f =1) | |
if (child) : | |
typ = cmds.nodeType(child[0]) | |
if not obj.endswith(name_convs.get(typ, "")): objs_dic[typ].append(obj) | |
else : | |
if not obj.endswith(name_convs.get(typ, "")): objs_dic[cmds.nodeType(obj)].append(obj) | |
for typ , suffix in name_convs.items() : | |
objs = objs_dic.get(typ ,[]) | |
if (objs) : | |
#print(objs) | |
cmds.select(cl=True) | |
cmds.select(objs) | |
mel.eval(f'searchReplaceNames "$" "{suffix}" "selected";') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment