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?
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()
The name is just in blendshape[0] without the name(), but except for this it works!
Thank you man!
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)
Whatâs the difference between print just my_blendShape_node[0] and my_blandShape_names?
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?
The name of the blendshape node!
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.
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]