PDA

View Full Version : Python Help - paneLayout(setpane = [(string,int)])


sushirom
11-03-2011, 04:54 AM
First let me refer you to...

http://autodesk.com/us/maya/2011help/CommandsPython/paneLayout.html#flagsetPane

Me and a friend have spent many hours of days looking for an answer, but nothing shows up online. How do you use setPane? It says it can be used during creation, edit or multi argument. Essentially our understanding was that the setPane flag allows you to re-order the controls in the panes. Out problem is, when we set up a window command > a paneLayout command > and then its buttons; it says the button's can't be found. If we try and make the button's before hand, it says the button's can't be made without a layout. So does anyone have an idea of how this is supposed to be set up? I tried finding some references on possibly setting up classes or definitions for buttons alone but I can't find anything where someone doesn't spawn a columnlayout or something first. Admittedly I'm not terribly familiar with python, so classes and definitions have been a bit troublesome for me. Also, declaring the button's as variables before the window and the paneLayout returns the same "button can't be found" error.

The exact error being "RuntimeError: Object 'button3' not found."

And our simple script being...


import maya.cmds as cmds

cmds.window()

cmds.paneLayout( configuration='quad', sp= [("button3",1), ("button2", 2), ("button1",3), ("button0",4)])

cmds.button(l="button0")

cmds.button(l="button1")

cmds.button(l="button2")

cmds.button(l="button3")

cmds.showWindow()

NaughtyNathan
11-03-2011, 11:05 AM
you can't use the sp flag during create in this example, because your buttons don't yet exist. You don't create them until after the paneLayout, so of course it will say it can't find them...

For this particular scenario you would NOT use the sp flag on creation. Presumably it's only in there on create in case you are moving some managed or unmanaged controls or layouts that do already exist somewhere else. Just make your pane layout, then create the buttons in the right order. They will automatically be placed into the right panes, and if they are not you then use the sp flag in edit mode to sort them out.

:nathaN

sushirom
11-03-2011, 11:27 AM
We've got the gist that it can't be made in this order, but so far this is the only format we've gotten any results. We tried forcibly spawning buttons before hand in classes, or definitions. I've tried putting them in a prior layout and then loading them into the next, but with no result. Maybe if someone has an example of the formatting, because I can't imagine many other ways to "bank" the button's in another layout. It all seems to give the same, "can not find" error.





import maya.cmds as cmds

#Clearing the names...


if cmds.window("testing", q=True, ex=True):

cmds.deleteUI("testing")

if cmds.window("testing2", q=True, ex=True):

cmds.deleteUI("testing2")


#Making the first pane...

cmds.window("testing")

cmds.paneLayout("test", configuration='quad')

cmds.button("button0")

cmds.button("button1")

cmds.button("button2")

cmds.button("button3")

#Spawning extra buttons?...

cmds.button("button4")

cmds.button("button5")

cmds.button("button6")

cmds.button("button7")


cmds.showWindow("testing")





#Just to test the parent paths...


self = cmds.button("button4",query = True, parent = True)

self2 = cmds.button("button5",query = True, parent = True)

self3 = cmds.button("button6",query = True, parent = True)

self4 = cmds.button("button7",query = True, parent = True)

print self

print self2

print self3

print self4



#Trying to figure out how to call full paths?...Not sure how, I'm assuming the quotations are just reading it as strait text and not the parental root...so if someone could enlighten me....



print "testing|test|button4"





#Attempt to use previously spawned buttons...


cmds.window("testing2")

cmds.paneLayout("test2", configuration='quad', sp= [('testing|test|button4',1), ('testing|test|button5', 2), ('testing|test|button6',3), ('testing|test|button7',4)])

cmds.showWindow("testing2")



I'm gonna assume I'm missing some break. Like I can't spawn two windows consecutively without some kind of class set up or something.

Azrail
11-03-2011, 11:38 AM
import maya.cmds as cmds
cmds.window()
cmds.paneLayout('panelll', configuration='quad')
cmds.button('button0', l="button0")
cmds.button('button1',l="button1")
cmds.button('button2',l="button2")
cmds.button('button3',l="button3")
cmds.paneLayout('panelll', e=1, sp= [("button3",1), ("button2", 2), ("button1",3), ("button0",4)])
cmds.showWindow()


This way it works. However there is one fundamental thing in UI building which I think you've missed:
the name of the control and it's label are very different things. You're creating a button with label 'button1' and you presume that the actual control will be called the same way, which in 99.9% of the cases aint gonna happen. So either way you name your controls while creating them, like the sample I gave you, or (the better practice to avoid non-unique names) is just to capture the name of the control into a variable upon creation, like this:
btn = cmds.button('button3',l="button3")
print btn
#Result: window2|panelll|button3

sushirom
11-03-2011, 11:58 AM
Okay cool~ I forgot I wrote the label tag earlier. This was my first night with python, and I had learned shortly after studying my friends mini script that there was a difference between the two. So now I get how you use it for edits, but my issue with this is how to use it for an initial create which the documentation claims it can do.

CGTalk Moderation
11-03-2011, 11:58 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.