pymel-list Mailing List for Pymel
Status: Alpha
Brought to you by:
eelcol
You can subscribe to this list here.
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
|---|
|
From: Modulok <mo...@gm...> - 2012-10-03 23:09:39
|
List,
*waves* hello everyone. (I'm new to the list. Forgive me if this is a dev list
and not a users list. If so, please point me to the correct list.) I've written
a fair bit of python and MEL, but new to pymel and to mixing python and Maya in
general. Thus, few questions:
I have a marking menu as a child of the maya main window written in pymel. It
works. I trigger it via hotkey. The problem, is it doesn't go away when I'm
done. In the hotkey editor, when using MEL, you get a press and release hotkey
which run commands like this::
// Press code:
if (`popupMenu -exists tempMM`) { deleteUI tempMM; }
popupMenu -button 1 -ctl false -alt false -allowOptionBoxes true
-parent `findPanelPopupParent` -mm 1 tempMM;
source "menu_foo";
// Release code:
if (`popupMenu -exists tempMM`) { deleteUI tempMM; }
What is the python equivalent? I tried the following but I don't think it's
right::
# Press code:
try:
tempMM.delete()
except NameError:
pass
finally:
import foo
# Release code:
try:
tempMM.delete()
except NameError:
pass
Is there a better way to set this up for calling python code?
Below is my example pymel marking menu code. The other question I have, is
should this be wrapped in a function i.e. 'main' that I call after I import it?
I'm still wrapping my head around mixing python and maya.
# Generic marking menu sample code:
import pymel.core.windows as pwin
import pymel.core.uitypes as ui
def amazing(*args):
'''Does something amazing.'''
print("amazing!")
def fantastic(*args):
print("fantastic!")
#*************************************************************************
# Make the UI
#*************************************************************************
# Attach this control to the maya main window. (Just make sure to delete
# it when you're done.
tempMM = ui.PopupMenu(parent="MayaWindow")
tempMM.setMarkingMenu()
tempMM.setAltModifier()
tempMM.setButton(1) #<-- Active with alt+left mouse button.
item1 = ui.CommandMenuItem(parent=tempMM)
item1.setLabel("Amazing")
item1.setRadialPosition("S")
item1.setCommand(pwin.Callback(amazing))
item2 = ui.CommandMenuItem(parent=tempMM)
item2.setLabel("Fantastic")
item2.setRadialPosition("N")
item2.setCommand(pwin.Callback(fantastic))
-Modulok-
|