I’m having some problems with relative paths in Maya and PySide2.
I understand all Maya’s buttons are bundled in a file,
but since I don’t understand exactly how it works
why doesn’t using relative paths work for my own custom icons?
My custom icons that are inside custom defined icon paths works with maya.cmds
import maya.cmds as cmds
window = cmds.window()
cmds.rowColumnLayout( adjustableColumn=True )
cmds.iconTextButton( style='iconAndTextVertical', image1='orient_top.png', label='top' )
cmds.iconTextButton( style='iconAndTextVertical', image1='orient_front.png', label='front' )
cmds.iconTextButton( style='iconAndTextVertical', image1='orient_side.png', label='side' )
cmds.showWindow( window )
PySide2 example
does not work with my custom icon
btn1 = MyPushButton("my_icon.png")
or
btn1 = MyPushButton(":/my_icon.png")
works with Maya native icons
btn1 = MyPushButton(":/cube.png")
my solution in PySide2
get the path to the file itself
path = os.path.dirname(os.path.abspath(__file__))
# because I’m using modules I have an icon folder in every collection
btn1 = MyPushButton(path+"/icons/my_icon.png")
and while I am on the topic. Why is it that when I create a new shelf button, navigate to my button that is in an icon folder that I’ve added to Maya, it still shows the full absolute path so I manually have to go in and remove the whole folder path to just have the icon name left. I do this with a script, but anyway. Is there any other workaround for this?