Array Out Of Textfile

Hi
my problem is not to get data out of a textfile and store it to an array. but it has to do with this ... i guess.

i filled an array witch data of a textfile. so normaly if you print an array u will geht sth. like this:


print $array;
result:
joint_1
joint_2
joint_3
joint_4


so if i now print the array of the textfile it get this:

print $textArray;
result:
joint_1

joint_2

joint_3

joint_4

so after every array item there's a blank line.
so if i now do the following e.g.:

joint -name $textArray[0];
select -cl;
select $textArray[0];

maya says :
// error: No object matches name: joint_1
//

but normally when an object doesn't exist in the scene the error would be:
// error: No object matches name: joint_1 //

so you see ther's something wrong with the array item and i couldn't find out what it is.
may someone of you knows an answer.

looks like you've picked up a newline (or CR or LF or whatever it's called?) at the end of each element of your string array... dunno how this has happened to you though..?

maybe your souce text file is in a weird format.. (UNIX/DOS?) or it actually has some escaped "\n" is it..?!?

you're not adding an "\n" to each element are you?

:nathaN

Hi

no i'm not adding "\n" to any element ... the data in the text file looks like

left_A
left_B
left_C
right_A
right_B
right_C

and its a normal .txt format.
so i really don't know why maya reads the file out this way. i do it with the fgetline command and do not add something else to the data.

so the problem is, that there must be something, because the items i want to work with exist in the scene, but the name chanes because of something.

I've never actually used fgetline but a quick check in the docs reveals that fgetline ADDS a newline onto your string as you are asking it to get a full line..

that's probably the cause of your problem.

hmmm ok .. shit

that's bad ... because i need the name out of this array ... damn ... but thanks for ur help!!!!!

ok, i fixed the problem.

for somebody who want's to know my solution.

match out the strings to leave out the blank line:

for ($currentJoint in $uncleandedMissingJoints)
{
	$i++;
	string $matchingParts = `match "[a-zA-z0-9\_]*" $currentJoint`;
	$missingJoints[$i] = $matchingParts;
     }

Check ou the strip command; it removes whitespace from the start and end of a string. That includes newlines.

sam

hi

y u'r right ... strip command would be easier to filter the whitspaces out.

thanks for this!