Dashboard_avatar
May 09, 2012
Post id: 310015 Report Item

So currently for a project for school I'm creating my own, VERY BASIC and generic GUI picker.

Concept so far is that a window opens with just the one button --> 'New Button..'

It runs the command to make a new button, with a prompt to ask the name of the button and inserts it back into the GUI. Fantastic.

That's as far as I got. I want to be able to select the objects I want, create a new button and now the objects are associated with that button!
So if I de-select the objects and push the button it will pick them back up! Easy as it sounds that's ALL i need help with but I have a tight deadline. 

But here's a visual shot on what the GUI will look like. And I added right click functionality but even those haven't been programmed yet. I don't want to do more until I figure out this problem!




Image and video hosting by TinyPic











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


import maya.cmds as mc
 
def patelGUI():
if mc.window("patelGUI", exists=True):
mc.deleteUI("patelGUI")
 
winName = mc.window("patelGUI")
mc.frameLayout(label="Create Buttons", collapsable=1)
mc.button(label="New Button...", command='newButton()')
mc.frameLayout(label="Picker", collapsable=1)
 
mc.showWindow(winName)
 
def newButton():
mc.promptDialog(title="Button Name", message="Enter name:", button=['Ok', 'Cancel'], defaultButton='Ok', cancelButton='Cancel',dismissString='Cancel')
text = mc.promptDialog(query=True, text=True)
btn = mc.button(label = text, c="runSelect()")
popup = mc.popupMenu(parent=btn, ctl=False, button=3)
item1 = mc.menuItem(l='Add', c='addSelection')
item2 = mc.menuItem(l='Edit', c='editSelection')
mc.frameLayout(e = 1, visible = 1)



Dashboard_avatar
May 09, 2012
Post id: 310016 Report Item

I added codes like:

mc.ls(selection=True) and even variables.

items = mc.ls(selection=True)

to hold the items even in that one button but to no luck. =/ 

Dashboard_avatar
May 10, 2012
Post id: 310018 Report Item











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34


import maya.cmds as mc
from functools import partial
 
def select(list, *args):
mc.select(list)
 
def addSelection(sel, *args):
sel.extend(mc.ls(sl=True))
 
def newButton(*args):
mc.promptDialog(title="Button Name",
message="Enter name:",
button=['Ok', 'Cancel'],
defaultButton='Ok',
cancelButton='Cancel',
dismissString='Cancel')
text = mc.promptDialog(query=True, text=True)
list = mc.ls(sl=True)
part = partial(select, list)
btn = mc.button(label = text, command=part)
add=partial(addSelection, list)
popup = mc.popupMenu(parent=btn, ctl=False, button=3)
item1 = mc.menuItem(l='Add', c=add)
 
def patelGUI():
if mc.window("patelGUI", exists=True):
mc.deleteUI("patelGUI")
 
winName = mc.window("patelGUI")
mc.frameLayout(label="Create Buttons", collapsable=1)
button = mc.button(label="New Button...", command=newButton)
mc.frameLayout(label="Picker", collapsable=1)
 
mc.showWindow(winName)



Dashboard_avatar
May 11, 2012
Post id: 310037 Report Item

Wow, thank you so much Joojaa!

I've never heard of the *args flag before. I'll have to look it up.

It works briliantly. Time to add further functions now that I'm back on track.
Seriously...THANK YOU! 

Dashboard_avatar
May 13, 2012
Post id: 310042 Report Item

Just so you understand maya has this feature built-in just not the buttons gui (but in fact you get them in outlliner as buttons). So perhaps better to use those instead (quick selection sets), then maya remembers your settings form session to session, scene to scene.

Second you have a hard to find bug in your code, i didnt fix it because frankly its best if you find out by yourself. Basically your neglecting to tell maya where you want the button created, yeah maya does it properly because no outer UI is built interim. But if it is then your gui instantly stops working. And that is why you have the *args there so you can figure it out, or not and then hard code stuff in like yoru doing at the moment (bad programming practice but then your scripting).

Dashboard_avatar
May 14, 2012
Post id: 310052 Report Item

Yeah I have noticed that, I get a runtimeerror everytime I make a button. I'll have to work on this a bit more.

Thanks for getting me going in the right direction! And i would definitely like maya to have things memorized, I'll have to read up on all that. I'll be updating you all over summer.