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

Open maya's default windows to a specified directory

Message 1 of 3
198 Views, 2 Replies

Open maya's default windows to a specified directory

This question may sound trivial but I haven't been able to find a way around it. I want to open maya's default Import window (or CreateReference window) using the python api. Now I CAN open the window just find but it's set to the default project that's been set by the user. Here is the command:

import maya.cmds as cmds

The problem is that I don't know if there are any flags for me to set the address. Commands also work in mel BTW.

Labels (2)
Message 2 of 3

Normally, a dialog opens using whatever is the "Current Working Directory", and there are a couple of ways to set this in Maya. However, notice how both of those "commands" start with a capital (uppercase) letter? this means they are not strictly real commands, but "RunTimeCommands", which are like aliases to commands or scripts that take no parameters.

This basically means a) there won't be any params you can add to these to control their behaviour, and b) because they are "shortcuts" to god-only-knows what code, there's no guarentee that setting any configuration (i.e. setting the "current working directory") beforehand will have any effect.


You do have a couple of options. First, just try setting the current working directory, then see what happens when you use those commands.


If that doesn't work, you need to query the underlying code of each of those runTimeCommands to follow what they are doing, and then replicate that yourself. This will probably involve the fileDialog2 command, which you can also set the starting folder with.

code = cmds.runTimeCommand('CreateReference', q=True, command=True)

apologies if the code is not 100% accurate, I'm not at Maya atm so am going from memory. This should help get you started a bit though.

Message 3 of 3

Thank you man, you're a chad! Great explanation. Using the keywords you provided I was able to find the answer I was looking for. The Import or Reference or many window for that matter are in fact modifiable through MEL commands using the fileDialog2 command. Although it takes an expert! It's not yet possible to do the same using python commands because most flags are specifically designed for MEL only. I've provided the link bellow for those enthusiasts seeking similar solutions:

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

Post to forums  

Technology Administrators

Autodesk Design & Make Report