Maya: Extract blendshape targets from wrapped mesh

Hi,
i was wondering if it is possible to extract blendshape targets from a wrapped mesh.
What i mean:
lets say you have a meshA with a blendshape that has 5 targets.
then on the meshA we wrap a meshB
For each target of blendshape1
1)the weight is 1,
2)we duplicate meshB,
3)rename the shape node copy as the name of target, without ‘‘shape’’ in the naming,
4)add this new copy as a target to a blensghape2
(a new blendshape of a copy of meshB that now is renamed as MASTER, no wrap for this one)
5)then delete this duplicated meshB
6)the weight is 0
and the loop continues for all the targets of blendshape1

at the moment i have written this one but it pops many errors…
The main error is that is not looping through all targets…

import maya.cmds as cmds
import re

tempDupl = []
wrapped = "pCube1"
target_data = cmds.aliasAttr('blendShape1', q=1)
indices = [int(re.findall(r'\[([\d]+)\]',i)[0]) for i in target_data[1::2]]
i=0

def extract_blnd_targets():
    for i in indices:
        cmds.blendShape('blendShape1', edit=True, w=[(i,1)])
        dupe_mesh = cmds.duplicate(wrapped)[0]
        cmds.blendShape('blendShape1', edit=True, w=[(i,0)])
        tempDupl.extend(cmds.ls(dupe_mesh,type='transform'))
        for d in tempDupl:
            cmds.blendShape( 'blendShape2', edit=True, t=('MASTER', 1, d, 1.0) )
        deleteDupeMesh = cmds.delete(dupe_mesh)
        tempDupl[:] = []
  
        queryWeights1 = cmds.aliasAttr ( 'blendShape1', query = True )
        queryWeights2 = cmds.aliasAttr ( 'blendShape2', query = True )
        for n in queryWeights2:
            cmds.aliasAttr(queryWeights1[0],'blendShape2'+'.'+n)

Any help would be appreciated

Hey Stathis,

If all of the targets are not being iterated over then your variable “indices” may contain the wrong data. If “indices” does look correct to you then try commenting out the code after after the line:

" cmds.blendShape(‘blendShape1’, edit=True, w=[(i,0)])".

Run your function again and make sure the duplicate meshes are in the scene. If they are, then the problem is further down in your function.

I also would recommend pulling out the second for loop. Create all of the duplicate meshes first and then add them as targets to blendShape2 in a separate loop after the first loop has ran.

Hope that helps. Let me know if you need more clarification.

1 Like

Thank you for your reply.
I will check it