View Full Version : Text file parsing?
01-14-2004, 06:47 PM
Hey y'all, the search function failed me this time so here it goes. I need to make a MEL script that goes searches through a text file and imports coordinates from it for keys. Can someone hook me up with a link or two to any informative sites? thanks
01-14-2004, 09:53 PM
fopen is the mel command to open a text file, and fgetline (among many others) is the command to read stuff from that open file...
check out the docs for a few examples that should help you. :)
01-14-2004, 10:08 PM
To add a little more detail:
1) Use "fopen" to open the file
2) In a loop, read each line, then
2a) use "tokenize" to split up the columns
2b) put the results of tokenize into well-named variables, possibly arrays.
2c) Do whatever you need to do with the results on a per-line basis.
3) Close the file.
01-15-2004, 07:53 AM
wow that is extremely helpful, thanks a lot. When I start turning out some stuff with this i'll let you check it out :thumbsup:
01-15-2004, 08:59 PM
ok one more quicky for you MEL ninjas out there. My ascii data that I am importing looks like this
0.1483E+03 0.1965E+00 0.7972E+00
0.1478E+03 -0.4104E+00 0.3186E+00
0.1474E+03 0.3928E+00 0.7177E+00
it is just x,y,z for a single object over time. Tokenizing it gets me on the right track by separating by spaces and by "E". Right now I am getting syntax errors when I try to implement the order or magnitude:
float $x=$rawAnimArray; //first line = 0.1483
float $xe=$rawAnimArray;//first line = +03
setAttr pCylinder1.tx ($x*(10 pow $xe));
And Maya is not pleased with this. Any easy workaround? should I be using 'int' instead? How can I set it up to recognize the positive or negative sign? Yaaaaaargh
01-15-2004, 09:43 PM
You know, you can just assign 0.1483E+03 to a float. For example
float $a = 0.1483E+03;
is valid MEL syntax, so you can just tokenize using spaces as separators and assign each result to a float.
No reason to deal with the exponents yourself when Maya will do it for you.
01-15-2004, 10:59 PM
holy crap batman that is a huuuuuge timesaver. I finally got everything working just right, I owe you big
01-17-2006, 01:00 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.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.