Search code examples
pythonmaya

Whats the best way to set relatives paths in Maya 2022


Im currently creating a tool to be used within Maya 2022 and to define where the tool needs to grab the icons from I'm currently using this code:

icon_path = "C:/example/path/here/example.png"

However if I ever want to share my tool to others the file path with have to be relative. What would be the best way to do this?

To note: I'm currently keeping the code for this tool outside of maya's script folder. I assume this will either have to be moved to my scripts folder or added to my environment variables?


Solution

  • You can try different approaches. The most convenient way (and the one I recommend) is to use a maya module for distributing tools. If you define a module, maya automatically searches for icons in the modules icon directory or scripts in the scripts directory. Or you can use a path relative to your source file which you can get with file in python. And from this starting point you can e.g. search for a icons directory one level above the source file.