Maya retrieve blendshape name

maya
python

#1

Hello guys, is there a way, given the name of a mesh, to retrieve the name of the blendshape linket to it through Maya.cmds?


#2

Definitely. Something like:

history = cmds.listHistory( mesh )
blendshapes = cmds.ls( history, type = ‘blendShape’)

then you should be able to access the name with blendshapes[0].name()


#3

The name is just in blendshape[0] without the name(), but except for this it works!
Thank you man!


#4

Is this what you’re looking to do?

Get the Mesh

my_mesh = cmds.ls(sl=True)

Get the blendShape

my_history = cmds.listHistory(my_mesh)

my_blendShape_node = cmds.ls( my_history, type=‘blendShape’)

Get the blend Shape Names

cmds.select(my_blendShape_node)

my_blendShape_names = cmds.listAttr( my_blendShape_node[0] + ‘.w’ , m=True )

print(my_blendShape_names)


#5

What’s the difference between print just my_blendShape_node[0] and my_blandShape_names?


#6

The difference is that he is getting the names of each blendshape weight in the blendshape node.

If you iterate over my_blendshape_node.w you’ll get weight[0], weight[1], weight[2]

But if you get the “alias” of the weights, you get “smile_left”, “smile_right”, “ooh”, “mmm”, etc.

In your original question, are you trying to get the name of the blendshape node, or the individual weights inside the blendshape?


#7

The name of the blendshape node!


#8

import pymel.core as pm
from maya import cmds

def getBlendShapeAttributeNames():
“”" Gets all the the attributes names on blendshape at each weight index
“”"
#the node var only has to list some blendshape. I have it listing all blendshapes in scene which you probably don’t want
node = cmds.ls(type=‘blendShape’)
# returns tuple of weight attrs
blendAttrSize = cmds.getAttr(node[0]+’.weight’)

#loop over the attributes now and get their name info
for i in range(len(blendAttrSize[0])):
    attrName = node[0] + ".weight[" + str(i) + "]"
    print(cmds.aliasAttr(attrName, q=True))
    print(str(i))

def getTargetsFromSelection():
“”“This function will get the blendshape on selected and print out
the blendshape name,
the base shape name, and
all the targets at their weight index
“””
selectedNode = pm.ls(sl=True)
#I only have this getting history from first selected.
nodeHis = pm.listHistory(selectedNode[0])
objectBlendshape = []

#append blendshape to a list
for each in nodeHis:
	if (pm.nodeType(each) == 'blendShape'): 
		objectBlendshape.append(each)
print("Blendshape node name: {0}".format(objectBlendshape[0]))
#loop through number of blendshapes get the targets and base shape on blendshape 
for psds in objectBlendshape:
	targets = psds.getTarget()
	baseShape = psds.getBaseObjects()
	print("Base Shape: {0}".format(baseShape[0]))
	for i in range(len(targets)):
		print("Target Shape at Index {0}: {1}".format(str(i), targets[i]))

I am not entirely sure what you are asking for. However, I got a list of attrs from the blendshape and listed a bunch of other things that might be useful for blenshapes.


#9

I want only the name of the blendshape, like “blendShape1”.
I’ve obtained it with the first solution:
history = cmds.listHistory( mesh )
blendshapes = cmds.ls( history, type = ‘blendShape’)
print blendshapes[0]