Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Open maya's default windows to a specified directory

count.temp20
Contributor

Open maya's default windows to a specified directory

count.temp20
Contributor
Contributor

Hi,
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
cmds.Import()
cmds.CreateReference()

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.

0 Likes
Reply
Accepted solutions (2)
514 Views
2 Replies
Replies (2)

FirespriteNate
Advocate
Advocate
Accepted solution

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.

cmds.workspace(directory='d:/my_projects/props')

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.

count.temp20
Contributor
Contributor
Accepted solution

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:
https://forums.autodesk.com/t5/maya-forum/mel-import-command-documentation/td-p/9070680

0 Likes