Simple program with complicated problem! InternalVar issue?

59 views
Skip to first unread message

Kate Sendall

unread,
Aug 9, 2015, 10:47:21 AM8/9/15
to Python Programming for Autodesk Maya
Here is my script. Nice and simple. It's not perfect yet and it's still being 'built, but I'm eager to learn even though as a beginner I suck more than most! :P

import maya.cmds as mc

#checking to see if window already exists and deleting to make room for new window

if mc.window('myWin', exists=True):
    mc.deleteUI('myWin')

#creating new window
    
windowID = mc.window('myWin', rtf=True, t='StairCase', mnb=False, mxb=False, sizeable=True)
mc.columnLayout(w=400, h=600)
imagePath = mc.internalVar(userPrefDir=True) +'ícons/stairIcon.jpg'
mc.image(image=imagePath)

mc.button(l= 'Make a Step!', w=400, h=50, c='singleStair(10, 1, 2)')
mc.intSlider(h=300, w=200, step=5)
mc.showWindow('myWin')



The bold red text is the issue - when I delete it and run the script it all works fine and my window pops up with its button and slider. When I run it WITH the red text, it comes up with this error message: 

#Error: UnicodeDecodeError: file <maya console> line 19: ascii

Could someone please tell me what is going on? It's driving me mad. All I want to do is have a nice image header/banner for my window. 

Help me I'm DYING here.

Thanks

Kate S.

ABHIRAJ KK

unread,
Aug 9, 2015, 11:41:43 AM8/9/15
to Python Programming for Autodesk Maya
Hi, kate 

check the icons "i" in ur code i think u have used some special characters 

imagePath = mc.internalVar(userPrefDir=True) +'icons/stairIcon.jpg'
mc.image(image=imagePath)

Kate Sendall

unread,
Aug 10, 2015, 12:13:50 PM8/10/15
to Python Programming for Autodesk Maya
Are you kidding me? That's it! Thank you so much, haha. I was using an american set keyboard and a small screen. The two obviously don't mix well.

Perfect answer.

noah mizrahi

unread,
Aug 10, 2015, 4:49:34 PM8/10/15
to python_in...@googlegroups.com
I would use python string formatting instead of the  "+" operator.

Try something like:

imagePath="%sicons/staircon.jpg"%mc.internalVar(userPrefDir=True)

instead of:

imagePath = mc.internalVar(userPrefDir=True) +'icons/stairIcon.jpg'

--
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/8d601779-da77-4d79-9c5c-704583697a91%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Robert White

unread,
Aug 10, 2015, 5:54:46 PM8/10/15
to Python Programming for Autodesk Maya
Or, if you're like me and don't ever remember how the %s formatting works:

imagePath="{pth}icons/staircon.jpg".format(pth=mc.internalVar(userPrefDir=True))

or better yet, because it's a file path:

import os
imagePath= os.path.join(mc.internalVar(userPrefDir=True), 'icons', 'staircon.jpg')

That last one is often best, because it will handle os specific things like whether directories are split by '/' or by '\'.


On Monday, August 10, 2015 at 3:49:34 PM UTC-5, larry wrote:
I would use python string formatting instead of the  "+" operator.

Try something like:

imagePath="%sicons/staircon.jpg"%mc.internalVar(userPrefDir=True)

instead of:

imagePath = mc.internalVar(userPrefDir=True) +'icons/stairIcon.jpg'


More info:

On Mon, Aug 10, 2015 at 9:13 AM, Kate Sendall <kate.alic...@googlemail.com> wrote:
Are you kidding me? That's it! Thank you so much, haha. I was using an american set keyboard and a small screen. The two obviously don't mix well.

Perfect answer.

On Sunday, August 9, 2015 at 4:41:43 PM UTC+1, ABHIRAJ KK wrote:
Hi, kate 

check the icons "i" in ur code i think u have used some special characters 

imagePath = mc.internalVar(userPrefDir=True) +'icons/stairIcon.jpg'
mc.image(image=imagePath)

--
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_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages