Using layoutDialog in Python

Using layoutDialog in Python

Anonymous
Not applicable
860 Views
5 Replies
Message 1 of 6

Using layoutDialog in Python

Anonymous
Not applicable
Hey all,

I was wondering if anyone had a working example of layoutDialog in Python... I've been trying to rehash the example provided in the documentation but it seems rife with errors, and an "error: Line 1.1: Syntax error" just doesn't help to find the problem.

Anyone had any success with it?

BTW: This is using Maya 2008 Extension 1 with the MayaPy 2.5.1, performing mel replacement scripting in python.
0 Likes
861 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
I am using Maya 2008 extension 2 and the script works fine. I wont post it since its autodesks code, but I copied it exactly and it executes with no errors. Your error is suspect though.

Python errors, give more feedback than MEL like this:

# Error: ('invalid syntax', ('<maya console>', 2, 7, 'pnt foo'))
# File "<maya console>", line 1
# pnt foo
# ^
# SyntaxError: invalid syntax #

A MEL error looks like this:

// Error: Line 3.20: Syntax error //

From your post it sounds like you got a MEL error so I have to ask did you paste the python code into a MEL tab?

Ryan Trowbridge
Character TD
www.rtrowbridge.com/blog
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thank you for your response Ryan. I appreciate any help I can get with this. For the meantime, I'm creating modeless dialogs, but there are a few times a modal dialog would have been preferred.

This is definitely being done in a python tab in the script editor. It creates a tiny window with a close button and pops up a MEL stack trace dialog (tracing is on) with the error "Cannot find procedure "checkboxPrompt""... altering the python to not use the quotations so the command comes up cmds.layoutDialog(ui=checkboxPrompt) avoids this initial problem, but then the problem comes from the buttons... I've tried removing the command= commands from the buttons and it still fails to actually draw a dialog, only giving me the tiny window with the system close button in the title bar.

Since it seemed to be running okay for you, I tried running it by wiping my preferences and no environment variables set... and guess what... I still have the same problems... I cannot for the life of me get the layoutDialog example to work, and since a lot of the parsing happens as an embedded exec call, the direction to the actual problem is elusive.

Also, it is Maya 2008 ext 2, not ext 1 as I originally thought.
0 Likes
Message 4 of 6

Anonymous
Not applicable
It seems to me that the layoutDiolog commands does not recongnize the uiScript command if you define it in python. The workaround is to define the command in MEL. You'd haveto write it in a seperate .mel file and execute it from python. (I tried writing the procedure as a string and evaluating it from within the same python file but you run out of the number of quotes you can escape so you can have problems with button commands that require string arguments to be passed to them) Very messy but possible.
0 Likes
Message 5 of 6

Anonymous
Not applicable
Thanks Serguei... That would seem to be a workaround, I wonder if I can set a generic mel to be called that will call a python class? I know it's a bit of an ugly conundrum, but I'm loving the idea of wrapping my GUI elements in python classes of late... no ugly globals to carry controls through, all wrapped up in a pretty package.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Yes thats how I work as well. You can declare a MEL procedure that simply calls a Python function that actualy does the work. It should work just fine and would save you on a lot of mess.

Something like this (not really proper code):

def doWork ():
print ("Done")

melProcStr = 'global proc tempProc () {python ("doWork ()");} tempProc;' # Define then call the mel procedure

cmds.layoutDiolog (ui = 'eval ("' + melProcStr + '"&#41;'&#41;
0 Likes