On Sat, Jun 25, 2016 at 7:29 AM likage <[email protected]> wrote:
> Hi all, pardon my coding as it has really been a while since I have last
> touched on scripting. Currently I am trying to make some stuff work but
> keeps bumping into issues here and there.
> Really in need of some insights
>
> 1. I am unable to return the text value from the selection in showUI
>
There are two ways you can get the value. Either set a "changeCommand"
callback on the menu that will be called when the selection changes. Or
directly ask the menu for the current value on demand, using the query mode
and value=True. In the second option, you will have to know the name of the
menu from when it was created.
> 2. Prior to #1, when I tested without the showUI() function, it works
> where the Ok button does prints some stuff however the window is never
> closed upon clicking on the button. So my question here will be how do I
> close the window upon hitting the Ok button
>
There are a couple things you should address, to fix this behavior.
The "title" attribute of the window is not the same as the object name. You
need the object name to be able to refer to it later and delete it or check
if it exists. That means "win_name" doesn't really work well, in the way
you are doing it. Two possible approaches:
If you are using just functions, like your example, then you will want to
store a global reference to the name of your singleton window:
WINDOW = None
def showUI():
global WINDOW
if WINDOW and cmds.window(WINDOW, exists=True):
cmds.deleteUI(WINDOW)
WINDOW = cmds.window(...)
This would track a global window name, in which you don't really care what
it is called. It will get set by the return value to creating a new window.
The previous value, if set, will cause it to get deleted if it exists.
And for the button callbacks, I would recommend not using the string form.
You already have the ability to create first class functions so you can
just pass the function object and not have to worry about scoping issues:
cmds.button(..., command=defaultButtonPush)
cmds.button(..., command=deleteUI)
These changes should fix your issue with the UI not closing.
> 3. Related to #1, I am trying to get the value - the text value from the
> selection and have it run in my main code - pcikAFormat() in the optionMenu
> command, value flag..
>
That call to showUI isn't going to block, so checking the value right
afterwards isn't going to net you the user selection. You should wire up a
callback on your menu using the "changeCommand". Your "showUI()" command
could even take a callback from the user:
def handleMenuSelection(value):
print "menu selection changed!", value
showUI(handleMenuSelection)
> 4. Just wondering what is the best way that I can select the latest
> created node/item?
>
Can you explain this? Which node/item? UI? Scene?
>
> def defaultButtonPush(*args):
> #valid = ""
> valid = showUI.validFormatsLs.getValue()
> #return valid
>
> def showUI():
> win_name = "Select Camera Format"
> if cmds.window(win_name, exists = True):
> cmds.deleteUI(win_name)
>
> main_win = cmds.window(title = "Select Camera Format", width = 100,
> height = 50)
> cmds.columnLayout()
>
> validFormats = ['itemA-01', 'itemB-02', 'itemC-02', 'itemD-01',
> 'itemE-01', 'itemF-03']
>
> validFormatsLs = pm.optionMenu (label = 'Select a format')
>
> for item in validFormats:
> cmds.menuItem(label = str(item))
>
> cmds.button( label = 'Ok', aop = True, command = (
> 'defaultButtonPush()'))
> cmds.button( label = 'Cancel', command=('cmds.deleteUI(\"' + window + '\",
> window=True)') )
>
>
> cmds.showWindow( main_win )
>
> showUI()
>
> This is my main code
> def pickAFormat():
> ...
> ...
> mel.eval('CBdeleteConnection
> "camera01_cameraFlattenedShape.lensSqueezeRatio";')
>
> showUI()
> cmds.optionMenu('filmbackMenu', edit = True, value = ??? ) # value is
> to take the text selection from the showUI
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/3b07d3e7-ed49-4ede-8993-eefff381a3cb%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/3b07d3e7-ed49-4ede-8993-eefff381a3cb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1jbPkuva8c7Ymm6Q5rADyGwMuPQvexUeB1oMXpnkwB%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.