PDA

View Full Version : Reading Text Files . . . ?


AtrusDni
09-14-2005, 05:54 PM
Hey guys, I know its possible to have Maya read a text file and display its contents in maya, but I am still new to Mel, and am unsure on how I should go about creating this . . . I saw a thread on here that says use the fopen tag to open the file or something like that and create a loop to read each line, but im unsure exactly how to create this. I guess I am asking for an example, or at least a step by step explanation on how to go about making this. If anyone could give a working example for me to pick apart, I would be mucho greateful.

Robert Bateman
09-14-2005, 07:08 PM
from the mel documentation for fgetword and fgetline respectively....

$fileId=`fopen "C:/somefile.txt" "r"`;
string $nextWord = `fgetword $fileId`;
while ( size( $nextWord ) > 0 ) {
print ( $nextWord + "\n" );
$nextWord = `fgetword $fileId`;
}
fclose $fileId;
$fileId=`fopen "C:/somefile.txt" "r"`;
string $nextLine = `fgetline $fileId`;
while ( size( $nextLine ) > 0 ) {
print ( $nextLine );
$nextLine = `fgetline $fileId`;
}
fclose $fileId;

AtrusDni
09-14-2005, 07:14 PM
Thank you Robert! You rock. This will help out alot. Thanks again.

AtrusDni
09-14-2005, 07:37 PM
Ok, i dont want to sound completely stupid, but now I have the code to read and output the text file in maya, how would I make it so it shows up in a custom window? I am assuming you assign it to an array or something like that, but I dont know how to set that up. Like what im trying to do is have a custom window open and have the text piped into the window to give info about the scene, and instead of changing the actual code, someone could just type in the text file any changes or additions to the scene they have made, so when someone loads the scene it reads from the text file and shows them what has been changed.

Robert Bateman
09-15-2005, 09:47 AM
// declare this first
string $text;


// then replace the "print ($nextLine)" with
$text += $nextLine;


// after file read,
window;
$f = `formLayout`;
$s = `scrollField -tx $text`;
formLayout -e -attachForm $s "left" 0
-attachForm $s "right" 0
-attachForm $s "top" 0
-attachForm $s "bottom" 0 $f;
showWindow;

for things like this, i use the text tool in maya to create a big bit of text saying "Readme" and save all changes into the attribute editor 'notes' section....

AtrusDni
09-19-2005, 08:30 PM
Thank you very much Robert. You have been a great help. Thanks again.

CGTalk Moderation
09-19-2005, 08:30 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.