Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Project Directory with Python?

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
10990 Views, 6 Replies

Project Directory with Python?

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!
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

Message 3 of 7
Anonymous
in reply to: Anonymous

Genius, thanks.

I can't believe it was as simple as that, I feel a little bit dumber for not finding that now!
Message 4 of 7
Anonymous
in reply to: Anonymous

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?
Message 5 of 7
Anonymous
in reply to: Anonymous

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
in reply to: Anonymous

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?
Message 7 of 7
Anonymous
in reply to: Anonymous

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report