fileBrowserDialog in mode 4 syntax error

3 views
Skip to first unread message

jamsession

unread,
Oct 22, 2008, 2:07:09 PM10/22/08
to python_inside_maya
I am trying to get the (user chosen) directory path from a browse
function, but I keep getting a syntax error. This technique works
perfectly in MEL but throws a syntax error in python. Is this a bug,
or is there a better way of doing this in python

Thanks
Jared

[code]

import maya.cmds as cmds
win = "myWindow"
def dirPath(filePath, fileType):
cmds.textFieldButtonGrp('Dir', edit=True, text=str(filePath))
return 1
def gui():
#Creates the window.
if(cmds.window(win, q=1, ex=1)):
cmds.deleteUI(win)
if(cmds.windowPref(win, q=1, ex=1)):
cmds.windowPref(win, r=1)

cmds.window(win, t="Test Window", w=350, h=150)
cmds.columnLayout("colLyt")
cmds.textFieldButtonGrp('Dir',label='Directory Path', text='Browse
for Directory', buttonLabel='browse', buttonCommand=browseIt)
cmds.showWindow(win)
def browseIt():
cmds.fileBrowserDialog( m=4, fc=dirPath, ft='directory',
an='Choose Directory')
return
gui()

[/code]

Paul Molodowitch

unread,
Oct 22, 2008, 3:29:08 PM10/22/08
to python_in...@googlegroups.com
Odd, your code worked perfectly for me... or at least it did once I
removed the line breaks which were (I assume) introduced in the email
formatting.

Ie, this ran just fine for me:

http://pastebin.com/f1369e0f2

Perhaps you could give the exact syntax error?

- Paul

jamsession

unread,
Oct 23, 2008, 1:38:31 AM10/23/08
to python_inside_maya
That python pastebin is awesome! Never seen that before (My day is
complete, I learned something new ;) ) Hearing that the code works
for you makes me feel a little better, I thought I was losing my mind.

The error I am getting is:

<function dirPath at 0x0A83BFB0> "C:/Documents and Settings/
HP_Administrator/My Documents" "directory";
# Error: <function dirPath at 0x0A83BFB0> "C:/Documents and Settings/
HP_Administrator/My Documents" "directory"; #
# Error: Syntax error #

In this case I choose "My Documents" as the directory.
I am using Maya 8.5.

Thanks
Jared

On Oct 22, 2:29 pm, "Paul Molodowitch" <elron...@gmail.com> wrote:
> Odd, your code worked perfectly for me... or at least it did once I
> removed the line breaks which were (I assume) introduced in the email
> formatting.
>
> Ie, this ran just fine for me:
>
> http://pastebin.com/f1369e0f2
>
> Perhaps you could give the exact syntax error?
>
> - Paul
>

Paul Molodowitch

unread,
Oct 23, 2008, 1:18:06 PM10/23/08
to python_in...@googlegroups.com
You're right - when I run it on 8.5, I get the error.

Given that it works on 2008 (or, at least, 2008 ext 2), it seems it's
simply a bug with 8.5.

This seems even more likely if you exam the line it was trying to
execute when it got a syntax error:

<function dirPath at 0x...> "C:/.../My Documents" "directory";

...in other words, it's formatting the function (using it's string
representation!) and it's arguments as though they're a mel command,
and trying to run the result... in python.

Only workaround I can think of would be a quick dip back into mel,
using maya.mel.eval...

- Paul

PS - Yeah, pastebin rocks... thank Farsheed for turning me onto that
one. =) Can you believe I questioned it's usefulness at first? =P

Reply all
Reply to author
Forward
0 new messages