Skip to content

Instantly share code, notes, and snippets.

@Roumenov
Last active May 19, 2020 03:23
Show Gist options
  • Save Roumenov/7a0675d4bc346a0659e6a3030a0d05df to your computer and use it in GitHub Desktop.
Save Roumenov/7a0675d4bc346a0659e6a3030a0d05df to your computer and use it in GitHub Desktop.
add blendshape proc because the maya ui for this is obtuse and i always fuck it up like an idiot
import pymel.core as pm
def get_blendShape(target):
"""Get blendshape of target."""
if (pm.nodeType(target.getShape()) in ["mesh", "nurbsSurface", "nurbsCurve"]):
blendShape = pm.listHistory(target, type="blendShape")[0]
return blendShape
def add_blendShape(new_shape, blend_mesh):
"""
Add blendshape target to mesh with existing blendShape deformer
Parameters
----------
new_shape : mesh, nurbsSurface, nurbsCurve
blend_mesh : mesh, nurbsSurface, nurbsCurve
"""
#pm.select(blend_mesh)
blendShape_node = get_blendShape(blend_mesh)
new_index = blendShape_node.numWeights()
print(new_index)
try:
pm.blendShape(blendShape_node, edit=True, target=(blend_mesh, new_index, new_shape, 1.0))
except:
pm.warning('not working')
return
####==== USAGE ====####
#first selected is the new shape, second is the target mesh with a blendshape to add to
new_shape, blend_mesh = pm.ls(sl=1)[0:2]
add_blendShape(new_shape, blend_mesh)
@Roumenov
Copy link
Author

Happy to help and entertain :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment