单击一个物体,然后选择与它相同材质的所有物体。
1 #------------------------------- 2 # Select Objects By Material(s) 3 #------------------------------- 4 # nerdocs - Just nerdy stuff that no one really cares about 5 # https://paololazatin.com.com 6 # created: 2015-02-19 7 # last updated: 2016-03-18 - //output info to the bottom command line 8 9 import maya.cmds as mC 10 import maya.OpenMaya as oM 11 12 messageOutput = " [nerdocs]: " 13 objectsSelected = mC.ls(dag = True, o = True, s = True, sl = True) 14 15 if objectsSelected == []: 16 messageOutput += "No Objects Selected." 17 oM.MGlobal.displayError(messageOutput) 18 else: 19 shadingGroups = mC.listConnections(objectsSelected,type='shadingEngine') 20 selectionMaterial = mC.ls(mC.listConnections(shadingGroups),materials = True) 21 22 materialCount = 0 23 previousMaterial = " " 24 mC.select(clear = True) 25 selected = mC.ls(sl = True) 26 27 for object in selectionMaterial: 28 if (previousMaterial != object): 29 materialCount += 1 30 previousMaterial = object 31 mC.hyperShade(objects = object) 32 selected += mC.ls(sl = True) 33 mC.select(selected) 34 35 messageOutput += str(len(selected)) + " object(s) selected based on the material of " + str(materialCount) + " selection(s)." 36 oM.MGlobal.displayInfo(messageOutput)