View Full Version : traversing path up secnes dir using mel
DEVILSAN 01-28-2009, 05:37 AM Hi I am trying to traverse path up using the following method .
string $sf[] =`file -q -l`;
for($eachObj in $sf)
print $eachObj;
string $dir = `match "^.*/" $eachObj`;
print "\n";
print $dir;
but how do i go up path from scene to the project directory
though i did it like this
string $prjDir = `match "^scenes" $dir`
print $prjDir;
but it gives error
// Error: print $prjDir; //
// Error: Syntax error //
secondly i am trying to print the path of $dir to confirm dialog like this ?
confirmDialog -message is this your current"+ $dir +"scene directory?";
gives error
// Error: confirmDialog -message is this your current"+ $dir +"scene directory?"; //
// Error: Syntax error //
where is syntax error ?
|
|
hi,
The command "dirname" is useful for this. To get the scenes catalog, you could do like this:
string $scenes = dirname(`file -q -sceneName`);
There are probably other ways to get the scenes directory, but this is for the general case.
As for the confirmDialog error, you have forgotten a " sign and parenthesis. Should look like this:
confirmDialog -message ("is this your current" + $dir + "scene directory?");
Hope this helps,
Magnus
DEVILSAN
01-28-2009, 07:00 AM
well i sorted out the problem myself what i really wanted but now i have landed to new problem
i.e. to create a directory i am doing system (mkdir $newDir);
but this is giving errors
my code is
string $sf[] =`file -q -l`;
for($eachObj in $sf)
print $eachObj;
string $dir = `match "^.*/" $eachObj`;
print "\n";
print $dir;
print "\n";
string $sdir = `match "scenes/" $dir`;
//print $sdir;
int $num= size($dir)-7;
//print $num;
string $prjDir= startString($dir, $num);
print $prjDir;
print "\n";
string $newDir= $prjDir + "mydir";
print $newDir;
print "\n";
system(mkdir $newDir);
but this gives error
// Error: system(mkdir $newDir); //
// Error: Invalid use of Maya object "mkdir". //
i am printing for testing purpose only
hi again,
when using system command, the command itself should be surrounded by quotes...like
string $dir = "C:\\testfolder\\";
system( "mkdir " + $dir);
Though, if you want to create a directory, simply use the mel command sysFile, like this:
sysFile -makeDir "C:/temp/mayaStuff"; // Windows
/Magnus
DEVILSAN
01-28-2009, 08:36 AM
thanks very much, sysFile is better way, also can you answer my this question
how to find what material is assigned to the object ?
example if i have anisotropic assigned; how do i query ?
i searched in maya help where i got shadingNode that doesnt let me query but i can use it to create
using
string $myShader;
$myShader = `shadingNode -asShader anisotropic`;
though when i right click and choose "Assign material to selection" it is assigned
like this
sets -e -forceElement anisotropic1SG;
if my material is anisotropic1SG then does that mean anisotropic1SG is also a shading group ,
btw what is the difference between shader and material ?
DEVILSAN
01-28-2009, 09:11 AM
one more question regarding the previous subject
before creating directory i want to check if it already exists or not
so i did it like this
string $sf[] =`file -q -l`;
for($eachObj in $sf)
print $eachObj;
string $dir = `match "^.*/" $eachObj`;
print "\n";
print $dir;
print "\n";
string $sdir = `match "scenes/" $dir`;
//print $sdir;
int $num= size($dir)-7;
//print $num;
string $prjDir= startString($dir, $num);
print $prjDir;
print "\n";
string $newDir= $prjDir + "mydir";
print $newDir;
string $compTo = "mydir";
int $compare = `strcmp $newDir, $compTo`; or int $compare = `strcmp $newDir,"myDir"`;
i dont understand where is the syntax error,
so clear my fundamental please
what does it mean when encloesd within `` and or when executing without `` i understand its a string when in inverted commas "".. :confused:
maybe it's easier if you tell me what you are trying to achieve with your script, in that way I could probably help you better.
the sysFile -makeDir command does not overwrite any existing folders, so you actually don't need to check if it exist, right?
the `` signs are used when running commands. When calling other scripts/procedures you don't use those signs. In my earlier post i referred to dirname as a command, but it's actually a script. My bad.
If you want the path to the project, you should use the workspace command. Like this:
workspace -q -fullName
/magnus
DEVILSAN
01-28-2009, 04:35 PM
well man you could have told me about workspace -q -fullName before i developed my own way of returning project directory, though helped me out learning strings, anyway,
i am working in a class project , and few days back guy doing 3d asked me if their could be backup of everything he deletes so, i told him i can write a script for that and i started working on it,
now i thought create a "deleted items" directory in project folder an everytime he presses delete selected object ,i can move that object to that location.
i am almost done now, i was working whole night.
the second question i asked above about material/shaders is not linked to this discussion though sorry for that ,actually i researched for that somewhere else and nobody replied so i though we are already talking so maybe u have an answer.
i do scripting as i am from programming background jumped into CG world but it looks like programming doesnt want to leave me.
DEVILSAN
01-28-2009, 08:51 PM
Though, if you want to create a directory, simply use the mel command sysFile, like this:
sysFile -makeDir "C:/temp/mayaStuff"; // Windows
/Magnus
well Magnus,
now i am done with all the checks when it came to create a directory i have to add $newDir + "My Bin";
but it says syntax error,
so am i making mistake in concatination like this ...
else
{
print "equal";
sysFile -makeDir $prjDir + "Recycle Bin";
print "Project Recycle Bin Created.";
}
as it is giving me syntax error
// Error: sysFile -makeDir $prjDir + "Recycle Bin"; //
// Error: Syntax error //
thanks for all ur help...
hi,
I'm not at work now, so i'm not able to test it myself, but I believe you should use parenthesis. When not doing so, maya thinks you're passing in two arguments for the directory name, which is not valid. Do like this:
sysFile -makeDir ($prjDir + "Recycle Bin");
DEVILSAN
01-29-2009, 01:26 AM
is it wrong way i am exporting the selected object.
string $binObj="filename.mb";
string $RBDirLoc = ($prjDir + "Recycle Bin/" + $binObj);
print $RBDirLoc;
print "\n";
file -es $RBDirLoc;
as it gives error says invalid file type specified.
DEVILSAN
01-29-2009, 02:40 PM
is it wrong way i am exporting the selected object.
string $binObj="filename.mb";
string $RBDirLoc = ($prjDir + "Recycle Bin/" + $binObj);
print $RBDirLoc;
print "\n";
file -es $RBDirLoc;
as it gives error says invalid file type specified.I figured it out myself i used -f and -filetype to save that works fine.
CGTalk Moderation
01-29-2009, 02:40 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.