Start Maya with project pre-set

1,239 views
Skip to first unread message

Marcus Ottosson

unread,
Jul 6, 2014, 9:04:00 AM7/6/14
to python_in...@googlegroups.com

Hey,

I’m doing this:

$ maya -proj /my/new/project/dir

But noticed that Maya isn’t creating the default project definition it otherwise would if I instead launched Maya and went with File->Set Project upon which it asks if you’d like to create one.

Is there a better way of starting up Maya to default into a workspace than the command-line flag? Alternatively, is there a command to establish a project definition or otherwise ensure that one exists?

I’ve dabbed my fingers in cmds.workspace, which has the newWorkspace argument, but with no luck. I had a look at the only command spit out by Maya upon clicking the “Create Default Workspace” button when setting a new project, np_getPrimaryProjectFileRules but that seems more a post-script as it merely queries the already existing definitions.

The end result I’m looking for is a Maya directory with the expected directories set up, so that when saving for the first time it brings you to the /scenes directory.

Best,
Marcus

--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Jul 6, 2014, 10:10:31 PM7/6/14
to python_in...@googlegroups.com
Hey Marcus, 

You just want it to create the workspace.mel file that it creates for you when you set a new project from the UI?

If so, this seems to work for me:
import os
import maya.cmds as cmds

root = "~/tmp"
name = "maya_test"

fullpath = os.path.expanduser(os.path.join(root, name))

if not os.path.exists(fullpath):
    os.makedirs(fullpath)
    cmds.workspace(fullpath, n=True)
    cmds.workspace(fullpath, o=True)
    cmds.workspace(fullpath, s=True)
I assume directory creation is part of the Project Manager or other operations that intend to use the directories resolved relative to the workspace root. 



--
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/CAFRtmOBtNu_QUrBHhLrsk_NrH_7JfFC3NLcZHN5q_w%2B87C8%3DgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Jul 7, 2014, 2:48:15 AM7/7/14
to python_in...@googlegroups.com

Hey Justin,

That would make a lot of sense, but unfortunately it doesn’t seem to work. It does create the workspace.mel file but with the following content:

//Maya 2015 Project Definition

workspace -bw "default";

Which effectively silences the “Create new workspace” dialog from the UI, but doesn’t provide the default hierarchy of folders that I’m looking for - mainly the “scenes” directory, so that when the user hit “Save” he’d be taken to it and not to the root of the workspace. Here is some of the definitions I’m looking to have it create.

//Maya 2015 Project Definition

workspace -bw "default";
workspace -fr "images" "images";
workspace -fr "scripts" "scripts";
workspace -fr "mayaAscii" "scenes";
workspace -fr "mayaBinary" "scenes";
workspace -fr "scene" "scenes";
workspace -fr "sourceImages" "sourceimages";

Although ideally it’d create whatever defaults there is, as is the case when creating it via the UI.

I should re-iterate, that “defaults” is the keyword here. I could of course put these commands in and create the hierarchy myself via os.makedirs, but that isn’t what I’m looking for here.




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



--
Marcus Ottosson
konstr...@gmail.com

Fredrik Averpil

unread,
Jul 7, 2014, 4:52:44 AM7/7/14
to python_in...@googlegroups.com
I'm following this topic with interest. I'm doing an ugly workaround by creating a pre-defined set of folders, but ideally I'd like to solve this the "nice" way.

// Fredrik


Anthony Tan

unread,
Jul 7, 2014, 5:28:45 AM7/7/14
to Fredrik Averpil, python_in...@googlegroups.com

Not at my machine right now, but I've set up an artist project manager which sort of does that, I'll fish the code out tomorrow morning when I get back in but from memory I took a brute force approach of firing off the MEL calls that you'd normally trigger in the UI to create a new project.

Marcus Ottosson

unread,
Jul 7, 2014, 5:41:10 AM7/7/14
to python_in...@googlegroups.com, fredrik...@gmail.com
Thanks Anthony, good to know. I'd be fine with setting up a script that fires off to do what Maya does by default, just thought I'd check to see if there was something I was missing first.

@Fredrik: Pre-creating folders is admittedly a bit hacky as you're neither using or customising any defaults, but instead relying on that the defaults are the way that they are. In many cases, it's quite enough and surely reliable as I'm sure most of the basic definitions remain the same between versions, like where to put scenes and images. But once in a while a new definition comes along, such as for bifrost or alembic. Not having them may not break things, but you'd be unable to rely on where they might pop up if you need them.

Ps. Justin, I've been getting a "Delivery to the following recipient failed permanently" a few times the past week or two. Had to re-post this message as it didn't seem to pop up on the list.

Justin Israel

unread,
Jul 7, 2014, 6:37:47 AM7/7/14
to python_in...@googlegroups.com, Fredrik Averpil
On Mon, Jul 7, 2014 at 9:41 PM, Marcus Ottosson <konstr...@gmail.com> wrote:

Ps. Justin, I've been getting a "Delivery to the following recipient failed permanently" a few times the past week or two. Had to re-post this message as it didn't seem to pop up on the list.

Can you check the header/cc list of the mail? I saw that once and noticed a reply all had put a corrupted partial address in there. 
 

Marcus Ottosson

unread,
Jul 7, 2014, 9:38:58 AM7/7/14
to python_in...@googlegroups.com, fredrik...@gmail.com
Hard to tell, but it looks like I've got a thread in my personal inbox looking different from the one here. Fredrik responded to my post above but I can't find it here.

This was Fredrik's reply:

@marcus Yep, that's why I wish to improve that bit in my scripts. :) Triggering the UI command is fine by me too, btw. 

To which I'll respond:

I know, I just felt it relevant to mention the reasoning behind thinking of it as dirty; it may differ between folks and situation and was considering that we're a group doing all things from features to still images.

Anthony Tan

unread,
Jul 7, 2014, 7:45:58 PM7/7/14
to Marcus Ottosson, fredrik...@gmail.com, python_in...@googlegroups.com

Yup, it was as dumb as I remember:

def setProject(projectdir, forceReset = False):
    '''Sets a project directory and simulates three button presses to open
    the Maya Project window, reset the fields to factory default,
    and then pressing Accept to create the directories.
    '''
   
    pm.workspace.mkdir(projectdir)
    pm.workspace.open(projectdir)
    if pm.workspace.fileRules.keys() == [] or forceReset:
        cmds_string = r"ProjectWindow; np_resetAllFileRulesTextFields; np_editCurrentProjectCallback;"
        mel.eval(cmds_string)
    else:
        print ("project partially set up, not resetting dirstrucutres")

On 7 Jul 2014 19:41, Marcus Ottosson <konstr...@gmail.com> wrote:
Thanks Anthony, good to know. I'd be fine with setting up a script that fires off to do what Maya does by default, just thought I'd check to see if there was something I was missing first.

@Fredrik: Pre-creating folders is admittedly a bit hacky as you're neither using or customising any defaults, but instead relying on that the defaults are the way that they are. In many cases, it's quite enough and surely reliable as I'm sure most of the basic definitions remain the same between versions, like where to put scenes and images. But once in a while a new definition comes along, such as for bifrost or alembic. Not having them may not break things, but you'd be unable to rely on where they might pop up if you need them.

Ps. Justin, I've been getting a "Delivery to the following recipient failed permanently" a few times the past week or two. Had to re-post this message as it didn't seem to pop up on the list.

--
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.

Marcus Ottosson

unread,
Jul 8, 2014, 6:52:31 AM7/8/14
to python_in...@googlegroups.com, konstr...@gmail.com, fredrik...@gmail.com
Thanks Anthony, that's good to know.

If anyone else is getting delivery issues, maybe try and re-post it in the groups directly:

I'm keen to hear about your ideas and wouldn't want them to get lost in cyberspace.

Best,
Marcus

Fredrik Averpil

unread,
Jul 8, 2014, 10:27:38 AM7/8/14
to python_in...@googlegroups.com
Yes, thanks for sharing that!

Sent from my iPhone

Fredrik Averpil

unread,
Aug 6, 2014, 3:18:12 AM8/6/14
to python_in...@googlegroups.com

Back from vacation and filtering through some saved email threads… and so, regarding this setting of project via Python…

This is what I currently do:

import maya.cmds as cmds
import maya.mel as mel

def create_folder( directory ):
    if not os.path.exists( directory ):
        os.makedirs( directory )

maya_dir = '//10.0.100.10/some/path/maya'
create_folder( maya_dir )

mel.eval('setProject \"' + maya_dir + '\"')

for file_rule in cmds.workspace(query=True, fileRuleList=True):
    file_rule_dir = cmds.workspace(fileRuleEntry=file_rule)
    maya_file_rule_dir = os.path.join( maya_dir, file_rule_dir)
    create_folder( maya_file_rule_dir )

I thought it was worth posting, as it answers the initial post by Marcus - and it doesn’t rely on pymel (which I don’t use). Also, I find the workspace command unnecessary, as the setProject command creates a workspace.mel file (with defaults).

What do you guys think about this approach?
Should cmds.workspace() be used for some reason? (I can't see why if you want defaults)

/ Fredrik

Reply all
Reply to author
Forward
0 new messages