PDA

View Full Version : Relative path file import mel


revilo3D
03-17-2009, 02:12 PM
hey guys, probably quite a simple one I can't seem to figure out.

Wrote a toolset about 2 years ago now... and recently fired it back up... however the import file mel seems to be not working. I have a scene file in the same location as the toolset script, which is defined by a module file. I want this to freely work across machines so relative path is a must. Here is the script as it was... now it just says "file not found"

file -import -type "mayaBinary" -ra true -namespace "Shot1" -options "v=0;p=17" "camToolsRig.mb";

I figured it worked in the past by having it defined in the module file specifically - letting it find the file named camToolsRig.mb. However this does not seem to work now. How do I build a string pointing to that directory - and does the use of the module complicate the matter?

Suggestions?

PS. This is the absolute path that works fine...

file -import -type "mayaBinary" -ra true -namespace "Shot1" -options "v=0;p=17" "C:/Documents and Settings/ohilbert/My Documents/maya/2009-x64/packs/camTools/scripts/camToolsRig.mb";

HapG
03-19-2009, 03:50 PM
if the maya scene is always in the same folder as the script, you can use whatIs to find the location of the script, then use that directory as the path for the scene.


string $melPath = `whatIs "yourMelScript"`;
string $path = `match "[^ ]*$" $melPath`;
$path = dirname($path);
$path += "/mayaScene.mb";

I used the match to pull the path out of the end of the whatIs return.
Then dirname to pull off the name of the script.

revilo3D
03-19-2009, 06:44 PM
Sounds perfect :)

I'll give that a go and let ya know if that does the trick!

revilo3D
03-26-2009, 06:21 PM
mmm still a bit stuck on this...

So far I have >>

string $melPath = `whatIs "camTools.mel"`;
string $path = `match "[^ ]*$" $melPath`;
$path = dirname($path);
$camPath = $path += "/camToolsRig.mb";

file -import -type "mayaBinary"
-ra true -rdn
-namespace "shot1"
-options "v=0;p=17"
-pr "$camPath";

I noticed that the the path is stripped off a fair bit... but am unsure how to modify match to try and retain it, if this is perhaps a problem. I've read the mel ref on 'match' and can't figure out how it's even doing what it does haha. Removing it obviously leaves "Script found in:" in the next string and does not pass just purely the path.

Even after all that, I don't know if putting $camPath like that is even supported...

HapG
03-27-2009, 06:00 PM
the 'match' command is returning the part of the 'whatIs' string which matches the specified pattern. This command's pattern ( "[^ ]*$" ) starts from the end of the string and goes back until it finds a whitespace and stops. If your file path has a space in it, this method will fail.
Try this command:
string $path = `substitute "Script found in:" $melPath ""`;
This will just replace "Script found in:" with nothing, making the string a usable path.

BTW: 'match' syntax is tricky to learn but VERY useful and well worth the headache

revilo3D
03-27-2009, 10:53 PM
Awesome man... thanks for this.

Dig the substitute command too. Simple stuff but really useful and unless on sees it used somewhere it's not easy to figure this stuff out - short of having a long hard read through the mel ref :P

Greatly appreciated :)

CGTalk Moderation
03-27-2009, 10:53 PM
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.