[MAYA/Python] formLayout (attachControl) ...broken?

Hello!

I’m creating a UI which basically has 2 elements. The top is always constant (contains buttons and such) and the bottom is dynamically created depending on which of the referenced rigs the user(animator) wants to work on.

On the top part there’s a drop down menu that contains all refrenced rig, when the user selects a different character in the drop down menu, the bottom part of the UI gets re-created.

the two part are split into 2 seperate defs:

  1. def build_window :
  2. def build_child_panel

Here’s what I’m trying to do:
I want to attach the bottom part (of build_window) to the top part (of child_panel), so when I stretch the window vertically the 2 elements stick together.

What happens now:


| element 1 |
|_____________|

crappy spacing


| element 2 |
|_____________|

What I want:


| element 1 |
||
| element 2 |
|
|

I’m using a formLayout in the “build_window” def:
with formLayout(‘fb_mainLayoutForm’,nd=100) as main_form :
blah, blah, build buttons…

At the top of the “build_child_panel” def:
with frameLayout(‘tools_frame’,lv=0,bs=‘etchedOut’,mh=5) as tools_frame :
blah, blah, build check-boxes and such…

Then at the bottom of my “build_child_panel” def:

edit main form

formLayout(main_form, e=1, ac=([tools_frame,‘top’,5,self.icon_buttons]))
–It finds main_form
–but doesn’t find tools_frame

I get this error:

RuntimeError: Object ‘FlipbookCC|tools_frame’ not found.

(FlipbookCC = window name)

I even tried doing:
self.tools_frame = tools_frame
but same error.

I’ve dug into google a bit and people are saying that using “with…as” statements with layouts brake things.

Any help with this would be much appreciated!

It’s possible that the context handler for the ‘with’ is disposing of the formLayout before you try to use it? If you get rid of the ‘with/as’ context manager, does it work?

Your return value suggest that the child frame isn’t a child of the main form - otherwise it would be more like
"FlipbookCC|main_frame|tools_frame’. Perhaps you’re doing something that resets the parenting, so that the second form is not being created as a child of the first. You want something more like


with formLayout('fb_mainLayoutForm',nd=100) as main_form :
    blah, blah, build buttons...

    with frameLayout('tools_frame',lv=0,bs='etchedOut',mh=5 ) as tools_frame :
         blah, blah, build check-boxes and such...
 
    formLayout(main_form, e=1, ac=([tools_frame,'top',5,self.icon_buttons]))

so that the parentage is clear. And you probably want two frames anyway: one for the contents of your main frame, one for the tools frame, and a parent frame that has them attached to the top and bottom respectively

Thanks for your replies!

Theodox: The only problem is, I’m creating the frameLayout in a separate def. so I can’t parent the layouts.
Although in the second def, where I create the frameLayout I specify (parent=main_form).

Example:
Def 1:
main_form = formLayout( nd=100 )
with gridLayout( numberOfColumns=5, cellWidthHeight=(64, 55) ) as icon_buttons :
blah blah buttons…
Def 2:
with frameLayout( ‘tools_frame’, lv=0, bs=‘etchedOut’, mh=5, p=self.main_form ) as tools_frame :
blah blah make stuff…

formLayout( main_form, e=1, ac=( [tools_frame, ‘top’, 5, icon_buttons] ) )

I get this error:

RuntimeError: Object ‘FlipbookCC|fb_mainLayoutForm|columnLayout47|gridLayout11’ not found.

So it seems like maya can find the formlayout but not the gridlayout I want to attach to.

Any suggestions would be awesome! Thanks!

Have you tried it without the with statements? I’ve seen missing layout errors with with statements before; maybe it’s that?

In the example you give, it looks like the gridLayout is not an immediate child of the form.

FlipbookCC|fb_mainLayoutForm|columnLayout47|gridL ayout11

. I’m not sure if FormLayout is smart enough to give you the right error message for that situation.

… or maybe because the frameLayout needs a container layout child? perhaps if you stuck the frame into a columnLayout first and attached that to the form…?