Re: [Maya-Python] Cannot insert characters into textfield

57 views
Skip to first unread message

damon shelton

unread,
Sep 17, 2014, 12:50:24 AM9/17/14
to python_in...@googlegroups.com
maya cmds is not object oriented (as in returning python objects)

self.waveFileAddress = cmds.textField(fileName="", enable=False, width=230) #returns the name of the ui element as a string

to set its text and get its text you have to query and set it with the cmds.textField function
cmds.textField(self.waveFileAddress, q=True, text=True)

cmds.textField(self.waveFileAddress, e=True, text=stringConvert)

also it is deprecated, meaning it will be removed in future releases, they have it around to give people time to update their code before it is removed. It still functions so old code doesn't break but it will in future versions


On Tue, Sep 16, 2014 at 9:33 PM, likage <dissid...@gmail.com> wrote:
I tried replacing the filwBrowserDialog with fileDialog2 but I met with some errors, especially so when I try adding in the file path

Basically what the following code does is that it will browse for this obj file, and once the user has selected, it will insert the file path (full path btw) into the self.waveFileAddress.
However, when the browser is open, there are some warnings logs prompted:
# Warning: Command fileBrowserDialog has been deprecated. Use fileDialog2 instead. #
# Warning: Flag -operationMode is obsolete. #

This is the original code:
def initialWindow(self, *args):
   
...
   
...
   
self.waveFileAddress = cmds.textField(fileName="", enable=False, width=230)
   
self.browseForObj = cmds.symbolButton(image="navButtonBrowse.xpm", command=self.getObjFile, enable=False)

def getObjFile(self, *args):
    cmds
.fileBrowserDialog( mode=0, fileCommand=self.importImage, fileType='OBJ', actionName='Import', operationMode='Import' )  
   
def importImage(self, fileName, fileType):
    cmds
.textField(self.waveFileAddress, edit=True, text=fileName)
   
return 1


And so, I tried it out using fileDialog2 and I took out the importImage function as well, thus the code now becomes like this:
def initialWindow(self, *args):
   
...
   
...
   
self.waveFileAddress = cmds.textField(fileName="", enable=False, width=230)
   
self.browseForObj = cmds.symbolButton(image="navButtonBrowse.xpm", command=self.getObjFile, enable=False)

def getObjFile(self, *args):    objFilter = "OBJ (*.obj)"
    fileList
= cmds.fileDialog2(fileMode=1, fileFilter=objFilter, dialogStyle=2)
    stringConvert
= ''.join(fileList)
    stringConvert
= self.waveFileAddress

However, I got the following error instead;
#     self.waveFileAddress.setText(stringConvert)
# AttributeError: 'unicode' object has no attribute 'setText' #

So how can I insert the file path into this text field? Please do note that the UI is created using the maya UI commands.
Also, one more question would be if
fileBrowserDialog is deprecated, why is it that I can still use it?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/761b9dea-8314-4da5-84eb-d3c170106aa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

likage

unread,
Sep 17, 2014, 12:53:27 AM9/17/14
to python_in...@googlegroups.com
Hi damonshelton,

Thanks for letting me know. I have kind of derived the answer and delete off my post, guess I was slow

The info about the deprecation helps a lot.

 
Reply all
Reply to author
Forward
0 new messages