Last active
May 19, 2020 03:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Happy to help and entertain :)