- #jfm_findObjectsByNames.py
- #created by Seth Meshko, 12/26/17
- #website: www.3danimationartist.com
- #you are welcome to use and redistribute this code, please just give credit where credit is due.
-
-
- '''
- This script allows you to pass in a list of strings and iterate through your scene to find all matches for objects with
- those strings in the object names. This script is not really usefull on its own. It is to be used in conjunction with other
- functions to process the objects that get returned
-
- the flaw that you may run into in this script is if your search words are contained in other words then you will get false returns
- for instance if you are searching for 'Rig' and you have a bunch of stuff in your scene with the name 'Right' then you will get
- those words returned too. This script is written for a really solid naming convention and the way that I get around things
- like this is by using 'Rt' for 'Right'. Basically anything that I know is going to be a key word gets a special treatment, another
- way of making a distinction is using all caps like: 'RIG' or 'SKIN'
- '''
-
- import maya.cmds as cmds
-
- def findObjectByNamingConvention(objectToSearch, listOfNames):
-
- countList = []
- i= 0
- for eachName in listOfNames:
- print('eachName is : ' + listOfNames[i])
- countList.append(objectToSearch.count(listOfNames[i]))
- print(countList)
- i = i+1
-
- numOfOccurances = 0
- for eachCountListEntry in countList:
- numOfOccurances = numOfOccurances + eachCountListEntry
-
- if(numOfOccurances == len(listOfNames)):
- return True
- else:
- return False
-
- selectAll = cmds.select(allDagObjects = True)
- selectAllList = cmds.ls(selection = True)
- print('the selectAllList is: ' + str(selectAllList))
- objectList = []
-
- i = 0
- for eachObject in selectAllList:
- eachHierarchy = cmds.listRelatives(eachObject, allDescendents = True)
- eachHierarchy.extend(selectAllList)
- print('eachHierarchy is: ' + str(eachHierarchy))
- listOfNames = []
- listOfNames = ['blerg', 'floop'] #Change and add to this list for more search criteria
-
- for eachSubObject in eachHierarchy:
- print('the object being searched is: ' + str(eachSubObject))
- objectFound = findObjectByNamingConvention(eachSubObject, listOfNames)
- if(objectFound == True):
- print('duplicateJoints(), the joint found is: ' + str(eachSubObject))
- objectList.append(eachSubObject)
-
- print('the objectList is: ' + str(objectList))
- cmds.select(objectList)
Share
25
DEC
2017
DEC
2017
About the Author:
I RUN this joint! And I am a digital artist. BFA from the University of Colorado with an emphasis in 3D Animation. I worked in medical animation for some time. I then narrowly escaped with an only partially crushed spirit. Since then I have been expanding my skill set, reaching out into custom coding, game and app development.