Skip to content

Instantly share code, notes, and snippets.

@pmolodo
Created May 16, 2019 01:02
Show Gist options
  • Save pmolodo/668d9809873125f608e0f7360fff7fac to your computer and use it in GitHub Desktop.
Save pmolodo/668d9809873125f608e0f7360fff7fac to your computer and use it in GitHub Desktop.
Removing a addPolyComponentIdChangedCallback can cause a crash (Maya 2019)
#execfile('/Volumes/home/paulm/Desktop/testPolyComponentIdChanged.py')
import maya.cmds as cmds
import maya.api.OpenMaya as om
cmds.file(f=1, new=1)
cubeTrans = cmds.polyCube()[0]
cubeShape = cmds.listRelatives(cubeTrans)[0]
sel = om.MSelectionList()
sel.add(cubeShape)
mobj = sel.getDependNode(0)
def myPolyComponentCallback(*args, **kwargs):
print "poly components changed!"
polyCompCbid = om.MPolyMessage.addPolyComponentIdChangedCallback(mobj, (True, True, True), myPolyComponentCallback)
def removeCallbacks(*args, **kwargs):
print "removing callbacks..."
om.MMessage.removeCallback(polyCompCbid)
del globals()['polyCompCbid']
polyDestroyCbid = om.MNodeMessage.addNodeDestroyedCallback(mobj, removeCallbacks)
cmds.refresh()
cmds.undo()
cmds.refresh()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment