How to select all blendshape targets via MEL script (to add a prefix)?

How to select all blendshape targets via MEL script (to add a prefix)?

filip.masiulewicz7CQLH
Enthusiast Enthusiast
817 Views
2 Replies
Message 1 of 3

How to select all blendshape targets via MEL script (to add a prefix)?

filip.masiulewicz7CQLH
Enthusiast
Enthusiast

Hi Guys,

 

Unfortunately for me I don't know MEL or Python and I can't find that type of command in Maya documentation.

 

0 Likes
818 Views
2 Replies
Replies (2)
Message 2 of 3

gadasamarth13900
Explorer
Explorer

Hi, @filip.masiulewicz7CQLH , I'm not an expert with MEL or Python, but this cannot be done with a command, as I do not think that there are any specific commands that help you select them directly. What you could do is either get a script coded with the help of ChatGPT or code it yourself, but in my opinion, the easiest way would be to do it manually with the help of Modify>Prefix hierarchy names (a native Maya tool). This may not require any complex coding or surfing. I hope this helps!

Message 3 of 3

Kahylan
Advisor
Advisor

Hi!

 

Since you say "select" I'm assuming that that shapes are still in the scene and you want to modifiy the names of the models themselves. This can easily be done by looking for the connection on the right attributes of your blendshape.

Since you don't know MEL or Python, I'll give you the example in Python, because I don't see why I need to make my day harder by doing this in an inferior language.

import maya.cmds as mc


def addPrefixToBlendshapeTargets(BLDSHP = "", prefix = ""):
    
    if BLDSHP == "":
        BLDSHP = mc.ls(sl = True)[0]
    
    if prefix == "":
        mc.warning("no prefix specified")
        return
    
    tgtList = []
    
    connListPlugs = mc.listConnections(BLDSHP, c= True, p= True, d= False)
    
    for i in range(0, len(connListPlugs)):

        if "inputGeomTarget" in connListPlugs[i]:
            tgtList.append(mc.listConnections(connListPlugs[i])[0])
            
    

    for t in tgtList:
        
        splitName = t.split(":")
        targetName = splitName.pop(-1)
        targetName = prefix + targetName
        
        nameSpace = ""
        for n in splitName:
            nameSpace= nameSpace + n + ":"
        
        mc.rename(t,nameSpace + targetName)



addPrefixToBlendshapeTargets(BLDSHP = "", prefix = "tgt_")

 

either add the name of your Blendshape to the "BLDSHP" variable in the last line, or simply select your Blendshape, then run the script from a python tab in your Script Editor and it should add a prefix to all your targets. You obviously can also change the prefix in the last line.

I hope it helps!