ace2011
02-24-2011, 07:34 PM
Hello,
I've been working on a project that involves using Maya and MEL scripting. The code I have currently reads a text file with 3 translation coordinates and 3 rotation coordinates, which are arranged in 6 columns and many rows. The idea is to read through the first row, getting the x,y,z translation and then x,y,z rotation, moving the selected object. However, my code will only read down the first column, and doesn't even read the other 5 columns. The code is shown below, can anyone tell me why it's only reading down the first column and not across the rows? Thanks.
{
float $joint1Angle, $xVal, $yVal, $zVal, $xRot, $yRot, $zRot;
int $fileid;
// need to load the robot (needs to be in current directory)
file -o -f "C:/MayaPolaris/arm6.mb";
refresh -f;
// in order to test the robot, will read in points from a file
$fileid = fopen("C:/MayaPolaris/new.txt","r");
if ($fileid == 0)
print("ERROR: Problem reading in text file.\n");
// iterate through text file, collecting each set of x,y,z coordinates
// pass coordinates to Maya to show planned robot trajectory
string $nextWord = fgetword($fileid," \n");
while (size($nextWord) > 0) {
// each iteration of this while loop corresponds to one robot position
$xVal = $nextWord;
$yVal = fgetword($fileid," \n");
$zVal = fgetword($fileid," \n");
$xRot = fgetword($fileid," \n");
$yRot = fgetword($fileid," \n");
$zRot = fgetword($fileid," \n");
// this is all the code that is needed to get the robot in the correct
// position
setAttr "r_humerus.translateX" $xVal;
setAttr "r_humerus.translateY" $yVal;
setAttr "r_humerus.translateZ" $zVal;
setAttr "r_humerus.rotateX" $xRot;
setAttr "r_humerus.rotateY" $yRot;
setAttr "r_humerus.rotateZ" $zRot;
// delay by 1 second for visualization
refresh -f;
pause -sec 0.5;
$nextWord = fgetword($fileid," \n");
}
}
I've been working on a project that involves using Maya and MEL scripting. The code I have currently reads a text file with 3 translation coordinates and 3 rotation coordinates, which are arranged in 6 columns and many rows. The idea is to read through the first row, getting the x,y,z translation and then x,y,z rotation, moving the selected object. However, my code will only read down the first column, and doesn't even read the other 5 columns. The code is shown below, can anyone tell me why it's only reading down the first column and not across the rows? Thanks.
{
float $joint1Angle, $xVal, $yVal, $zVal, $xRot, $yRot, $zRot;
int $fileid;
// need to load the robot (needs to be in current directory)
file -o -f "C:/MayaPolaris/arm6.mb";
refresh -f;
// in order to test the robot, will read in points from a file
$fileid = fopen("C:/MayaPolaris/new.txt","r");
if ($fileid == 0)
print("ERROR: Problem reading in text file.\n");
// iterate through text file, collecting each set of x,y,z coordinates
// pass coordinates to Maya to show planned robot trajectory
string $nextWord = fgetword($fileid," \n");
while (size($nextWord) > 0) {
// each iteration of this while loop corresponds to one robot position
$xVal = $nextWord;
$yVal = fgetword($fileid," \n");
$zVal = fgetword($fileid," \n");
$xRot = fgetword($fileid," \n");
$yRot = fgetword($fileid," \n");
$zRot = fgetword($fileid," \n");
// this is all the code that is needed to get the robot in the correct
// position
setAttr "r_humerus.translateX" $xVal;
setAttr "r_humerus.translateY" $yVal;
setAttr "r_humerus.translateZ" $zVal;
setAttr "r_humerus.rotateX" $xRot;
setAttr "r_humerus.rotateY" $yRot;
setAttr "r_humerus.rotateZ" $zRot;
// delay by 1 second for visualization
refresh -f;
pause -sec 0.5;
$nextWord = fgetword($fileid," \n");
}
}
