Project Directory with Python?

Project Directory with Python?

Anonymous
Not applicable
11,671 Views
6 Replies
Message 1 of 7

Project Directory with Python?

Anonymous
Not applicable
Hi,

I'm currently working on a Python based simulation project for my university degree. Part of this project involves saving a proprietary file in the user's current project directory. Now I've searched high and low to find the answer, but as of yet cannot: is there any way to query the Maya API and return the currently selected project directory?

os.getcwd() only ever returns the Maya binary folder (since that's where the OS is running Maya from) and whilst a setProject command exists, there's no getProject alternative.

It seems a bit odd that there's no exisiting commands to bring up the project directory, as I'd imagine thats a fairly obvious step for a lot of custom tools...

Any ideas?

Thanks!
0 Likes
11,672 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Message 3 of 7

Anonymous
Not applicable
Genius, thanks.

I can't believe it was as simple as that, I feel a little bit dumber for not finding that now!
0 Likes
Message 4 of 7

Anonymous
Not applicable
Actually, having tested out this command, cmds.workspace( q=True, dir=True ) only returns the directory at which Maya expects to find projects (i.e /username/documents/maya/projects) rather than the actual set project directory (for example in this case /username/my projects/project_name).

Any other suggestions?
0 Likes
Message 5 of 7

Anonymous
Not applicable
import maya.cmds as cmds
import os.path

projectDirectory = cmds.workspace(q=True, rd=True)
currentScene = os.path.abspath(cmds.file(q=True, sn=True))
if 'scene' in cmds.workspace(q=True, frl=True):
sceneDirectory = os.path.join(projectDirectory, cmds.workspace(fre='scene'))
Message 6 of 7

Anonymous
Not applicable
Is there any other way? cause the workspace command, when it's called in python code without Maya GUI, doesn't give back any other workspace beside the default one?
0 Likes
Message 7 of 7

Anonymous
Not applicable
when you say without maya GUI is you're doing stuff with maya batch? you could always setup an optionvar with your working directory and synchronize it whenever the workspace changes
0 Likes