PDA

View Full Version : Mel File Handling


faultymoose
11-02-2006, 10:49 PM
Heya,

Just a couple of questions about file handling:

Is it possible to create folders?

How do I write an array to text file, using an arbitrary separator (say, a comma)?

Thanks for the help :D

tbaypaul
11-03-2006, 02:32 AM
here is a bit on joint orientations I've been playing with..it has the ascii print and fopen, fclose....maybe a bit much for a simple answer, but was easier the picking bits out to share...and you can see how it actually formats the output....

proc pk_jointOutput(float $startFrame, float $endFrame, int $outputWS)
{
string $filename = ( `internalVar -userWorkspaceDir` + "exampleJO1.txt" );

//fileBrowser("fileCallback", "Save", "", 1);

int $fileHnd = `fopen $filename w`;

if($fileHnd == 0 )
{
error ("Unable to open output file " + $filename + " for writing");
return;
}

string $rootNode[] = `ls -sl`;
if(`size($rootNode)` < 1)
error ("Please select the main root!\n");

string $childNodes[] = `listRelatives -fullPath -type joint -children
-allDescendents $rootNode[0]`;
string $rn[] = $rootNode;
string $nodes[] = stringArrayCatenate($childNodes, $rn);

float $cTime = `currentTime -query`;

string $spaceFlag = ($outputWS) ? "-worldSpace" : "-objectSpace";

print "\nOutputting joints...";
float $t;
for($t = $startFrame; $t <= $endFrame; $t++)
{
currentTime -update false $t;
fprint $fileHnd ("\nFrame " + $t + "\n");
print ("\nFrame: " + $t + "\n");

for($node in $nodes)
{
float $pos[] = `xform $spaceFlag -query -translation $node`;
float $rot[] = `xform $spaceFlag -query -rotation $node`;
float $scl[] = `xform $spaceFlag -query -relative -scale $node`;

fprint $fileHnd ("\n" + $node + ".position " + $pos[0] + " " + $pos[1] + " " + $pos[2] + ";");
fprint $fileHnd ("\n" + $node + ".rotation " + $rot[0] + " " + $rot[1] + " " + $rot[2] + ";");
fprint $fileHnd ("\n" + $node + ".scale " + $scl[0] + " " + $scl[1] + " " + $scl[2] + ";\n");
print("Writing orientation output data ");
}
}

currentTime -update false $cTime;

fclose $fileHnd;
}

pk_jointOutput(1, 3, 0);

faultymoose
11-03-2006, 03:19 AM
Thanks for that :)

Also, for any who would like to know and don't:

sysFile -makeDir "/directoryFullPath";

ashishdantu
11-03-2006, 08:02 AM
hi

just in case u'd opt to use the system command - u can do the same like so:


string $primaryDir="d:\\";
string $mydir="testFolder";
system ("mkdir "+$primaryDir+$mydir);


njoi !

CGTalk Moderation
11-03-2006, 08:02 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.