PDA

View Full Version : Editing the project path with python/MEL


molgamus
10-11-2011, 10:57 PM
Today I got involved with a collaborative project here on CGTalk. Devils, Angels & Dating.
http://forums.cgsociety.org/showthread.php?f=73&t=749944

We use dropbox to share files, everyone has their cloned dropbox in the same directory so that the paths is the same for everyone. (c:/devils_angels_dating/My Dropbox).

Enter me. A mac user. My path is obviously different.
/Users/eliaserikssonrydberg/Dropbox

What I want to do is to temporarily substitute the windows path with the osx path. I don't want to change the paths to the referenced files as that may mess things up for everyone else on the project.

My first thoughts were environment variables, then I thought about python and smiled.

import pymel.core as pm
currentPath = pm.workspace.path
print currentPath

Now I would like to determine if the path needs to changed or not. How is this done in maya?

martin8910
10-15-2011, 11:04 PM
Hi Elias!

If the project is setup correctly, all path should be local. They should all begin in the project folder themselves, rather then going through the whole harddrive.

For ex, the project im working on here, my reference path to the rig is:

scenes/3D/02_Jade/publish/cameras/jade_shot03_cameras.ma

Is that helpful?

/Martin

molgamus
10-15-2011, 11:55 PM
Hi Martin nice to see you,

No! The paths are not relative to the project root. :/

The easiest solution is to install windows7 via BootCamp, but I would like to avoid it. I'm told that I can't have an OS dependent solution as it would require all users to implement it. If I could create a virtual drive/directory of some sort that allows maya to access files in that folder while they in reality is somewhere else, that would be good. Do you have any experience with this Martin? :)

WesHowe
10-16-2011, 12:21 AM
Now I would like to determine if the path needs to changed or not.

I would venture a guess that if it contains the string "eliaserikssonrydberg" then it is the wrong path. Python is not one of my strongest skill sets, but I know that you can call MEL from python.
string $mypath=`workspace -q -dir`;
if(gmatch($mypath, "eliaserikssonrydberg")) { // wrong space
workspace -e -dir "C:/Devils_Angels_Dating/My Dropbox/";
}


Now I am not sure that this works on a Mac, because I don't have one. And it may be a little more complex that I cited, because the lighting file is in "C:/Devils_Angels_Dating/My Dropbox/030_Lighting/Master/". So take this as a framework, rather than a finalized solution.

I think you should be able to manage nicely with manual methods, though. You only actually need to save a Maya file for your finished work, so you can change any paths needed in the reference editor (only needed if the unresolved name is changed) prior to saving. A quick copy and a few pastes should take care of that. I would guess you are doing lighting/rendering, since most of the animation is done or assigned, so most of your production will be image files anyway, and they should not cause any path issues.

<* Wes *>

p.s. If you need any further special help, send me a message at the devilsangelsanddating.ning.com site. Or to iskander, he is good at scripting.

molgamus
10-16-2011, 12:28 AM
You are correct, if the string contains my name it would be the mac path. And yes, I could connect the references manually. I've already done this just to try it out, the drawback is that if someone else opens my scenes after I'm done. They will have to set the references back the original settings again. Not really production proof.

I'm leaning towards having my computer pretend it's a windows machine (at least for this specific directory) and leave the paths as they are. Could this be done?

I would like to have the following directory "C:\Documents_and_settings\Angels_Devils_Dating\My Dropbox" in my root and have "My Dropbox" sync through a symbolic link if thats possible.

Edit: nevermind that, I can't create folders with the name "C:". The best plan so far is Win7 via Bootcamp.

WesHowe
10-16-2011, 01:52 AM
Well, what I have been trying to say is that if you can open the files from Dropbox, then somewhere in Dropbox or Maya is some code that already switched the path names. For lighting, you would just need to save the edited lighting file with the unresolved name field still pointing to C:/Devils_Angels_Dating/My Dropbox. Maya on Windows should then be able to find all the files.

Oh, and I do not use any "Project" for this. My current project folder for Maya is on "C:/Users/WesHowe/Documents/", but I just use File->Open Scene... and navigate to the dropbox. I save temp stuff on my regular project folder, the one that the "workspace -q -rd;" command returns. I only save to the Dropbox folder when I have something to upload.

Because I don't have a Mac, I cannot see what the Reference Editor says on your machine. But I would be happy to test a file on a Windows 7 machine with Maya 2011 for you, if you want to see if your solutions work. I wrote the lightingSetup.mel script used on the project, so I am all set up here.

<* Wes *>

martin8910
10-16-2011, 02:42 AM
Yeah Elias, I just found out that the references indeed cant be relative for some reason. MAYA DOC (http://download.autodesk.com/us/maya/2010help/index.html?url=File_referencing_Edit_reference_paths_in_the_Reference_Editor.htm,topicNumber=d0e125457).
How is your references path looking right now in the editor?

You can point to a string from MEL(or python i guess) with your disired filepath. Maybe this could be determed on startup what machine is in use with the about tag in MEL.

So you use this tag in the reference:
$myProject/scenes/street.ma

And execute this lines of code in MEL:
string $checkOs = `about -os`;
string $myProject;
//Declare mac
if ($checkOs == "mac") {
$myProject = "/Users/eliaserikssonrydberg/Dropbox"; }
//Check windows
else if ($checkOs == "windows") {
$myProject = "C:/Devils_Angels_Dating/My Dropbox/"; }

print $myProject;



Then it should be work on both a windows and mac machine, right!?
I dont have any windows to test this out myself.

molgamus
10-16-2011, 09:03 PM
Wesley, are you saying that I should edit the reference paths while working on it and then edit the back when uploading to Dropbox? I'm sure this can be done, but it's a lot of manual labour. :)

Thanks Martin, that's what I need to figure out what path to use based on what OS I'm running. What I was asking for in the original post.

This could be going somewhere! With an expression the script could be executed when the scene is opened and closed. If OS is mac, change "C:\Docum..." to "Users/el...". If not, do nothing. When scene is saved change all paths to C:\Docum..." again.

martin8910
10-16-2011, 09:18 PM
Yeah, that should work. Although then you cant save the scene when you are working in it. Is it not easier for you then to just have two script buttons in your shelf, on you execute when you open the scene and one when you save and close it.

molgamus
10-16-2011, 09:42 PM
That would work too. Could do that for now.

If the paths are edited every open/close it would be completely transparent to the artist. Allowing work to be done on whatever OS is most suitable for the task at hand. And yes, it seems like expressions can be run while maya is shutting down, before the scene is closed an expression executes a MEL procedure (before saving I would hope!). :D

WesHowe
10-16-2011, 11:25 PM
Wesley, are you saying that I should edit the reference paths while working on it and then edit the back when uploading to Dropbox? I'm sure this can be done, but it's a lot of manual labour. :)


While the count varies based on how many assets are used in each scene, I counted a total of 13 references in scene 0400. That's one type, one copy and 12 pastes. That would not take me very long to do... for the few times you would be uploading files, it is less work than writing and testing a script.

But choosing whether you want to stick with OSX or use parallels is your choice, all I was trying to do was to put this in some perspective.

<* Wes *>

molgamus
10-17-2011, 12:15 AM
Yeah, you are correct, manual labour is sometimes faster than scripting.

The quickest way is to open the Light master in a text editor and replacing the windwos path with the OSX path. I would have to do this for the master and the shot scene to have all (?) references to work properly.

molgamus
10-17-2011, 01:00 AM
string $checkOs = `about -os`;
string $user = `getenv "USER"`;
string $myProject;
string $windowsPath = "C:/Devils_Angels_Dating/My Dropbox/";
//OSX path
if ($checkOs == "mac")
{
$myProject = "/Users/"+$user+"/Dropbox";
}
//Windows path
else if ($checkOs == "windows")
{
$myProject = $windowsPath;
}

print ("My Path:" + $myProject + "\n");

string $referenceSelection[] = `ls -references`;
print ("\n" + "References:" + "\n");
print $referenceSelection;

for ($each in $referenceSelection)
{
string $referenceDir = `referenceQuery -filename $each`;
print ("\n"+$referenceDir);

python( "path = maya.mel.eval('referenceQuery -filename $each')" );
python( "path=path.split('/',4)" );
string $python = `python( "path[4]" )`;
string $myProject = ($windowsPath + $python);
print ( "\n" + $myProject + "\n");
}

Did some quick scripting. If I don't get my hands on a W7 tomorrow I will continue development.

Please note how the script utilizes the user environment variable, proud of it! :D

WesHowe
10-17-2011, 05:49 AM
Pretty good work on researching the getenv command, making your script more portable, or usable with different user accounts there.

I'm not sure that you can do this project of yours in a single script, if your objective is to just run on a Mac instead of Windows, because the script should always detect the OS as "mac". You may need to have the "To Mac" and "To Windows" just broken into two different scripts.

But maybe I misunderstood your plan, and you are going to use Maya on Windows to get your files, convert them to use on your Mac OS, and convert back to Windows before uploading. It should work for that.

<* Wes *>

molgamus
10-17-2011, 09:51 AM
At this point, my goal is to write two scripts to change the paths from OSX->Windows and vice versa. I could have these on my shelf and use before saving and uploading.

If I can I want to run a Windows->OSX script while the scene is opening, so that the references are correct for my OS and won't give an error like:
"the references was not found. (Browse/Skip/Abort file read)"

The alternative is to open the file with "Selective preload" checked, unload all references, run script and load them. Preferably this would be done automatically. But maybe I should split it into several scripts.

My plan was to never leave OSX unless necessary. If I get my hands on a W7 disk I can run it through bootcamp and won't have to edit the paths at all.

CGTalk Moderation
10-17-2011, 09:51 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.