Hi all!
I’m currently making a tool in Maya using Python and I’m running into some issues with returning the name of targets in a blendShape.
My UI is currently laid out so that the user can type in the name of a blendShape and then press a button which loads all the targets under that blendShape node in an optionMenu. Every time the button is pressed, the list in the optionMenu is cleared and updated to reflect the targets under the node in the text field.
What I’ve found through trial and error is that if I create a blendShape AFTER opening my UI, I’ll get a RuntimeError:Menu Item’s menu not found.
However, if I create the blendShape and only then open up the UI, the targets load just fine.
I have no clue why this might be. I’m wondering if it’s because I’m using aliasAttr to find the target nodes and that’s somehow messing things up behind the scenes.
Here’s the relevant part of the code:
#open UI window
def poseTrackerWindow():
if cmds.window( 'poseTrackerWindow2', exists = True ):
cmds.deleteUI( 'poseTrackerWindow2')
#window definition
cmds.window( 'poseTrackerWindow2', widthHeight = ( 470, 200 ), title = 'Pose Tracker Beta', minimizeButton = False, maximizeButton = False, resizeToFitChildren = True, sizeable = True )
cmds.rowColumnLayout(numberOfColumns = 2, columnWidth = [(1,100), (2, 200)])
#select an existing blendShape node
selectedBlendShapeTextField = cmds.textField( 'selectedBlendShapeText' )
#display corresponding targets
cmds.text( label='' )
cmds.button( label = 'Load Targets', command = 'loadTargetList()' )
targetList = cmds.optionMenu( 'targetObjectMenu', label='Target' )
cmds.menuItem(label='please select blendShape' )
cmds.showWindow( 'poseTrackerWindow2' )
poseTrackerWindow()
#function that loads target list to the UI
def loadTargetList():
allTargetShapesList = []
selectedBlend = cmds.textField('selectedBlendShapeText', q=True, tx=True )
targetInfo = cmds.aliasAttr(selectedBlend, q=True)
existingItems = cmds.optionMenu( 'targetObjectMenu', q=True, itemListLong=True )
if existingItems != None and existingItems != []:
cmds.deleteUI(existingItems)
for index in range(len(targetInfo)):
if index % 2 == 0:
allTargetShapesList.append(targetInfo[index])
for target in allTargetShapesList:
cmds.menuItem('targetObjectMenu', label='%s' %(target) )
(The code above is causing exactly the same bug as my full code, so if you’d like to see for yourself you’re of course welcome to)
Anyone have any clue what might be happening?