Message 1 of 11
noob question: loop not working - eof error when reading a txt file

Not applicable
08-09-2009
09:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to write a script that will read in two component codes from each line of a text file and edit the corresponding components.
The code works for the first line of the text file and edits the components correctly(whithout the loop). However when i tried to get it to loop through the rest of the lines in the file it fails and i get end of file errors.
I cant seem to find a loop that works properly
here is the code i am working on:
global fileUnderTest = "c:\\test1.txt"
--fn overlapHighlight dirString=
--(
max select all
$.xray = on
--fileUnderTest = dirString
fs = openFile fileUnderTest
seek fs #eof -- couldnt get a while loop to work so i tried this instead
maxlen=filepos fs
seek fs 0
count = 1
while count != maxlen do (
count = filepos fs
skipToString fs "Component "
obj1 = readChars fs 6
skipToString fs "Component "
obj2 = readChars fs 6
myObj1 = getNodeByName obj1
myObj1.xray = False
myObj2 = getNodeByName obj2
myObj2.xray = False
selectionSets = #(myObj1, myObj2)
)
close fs
--)
This is a sample from the text file i am trying to read
!! Component ab1001 OVERLAPS Component ab1002 !!
!! Component ab1003 OVERLAPS Component ab1004 !!
!! Component ab1001 OVERLAPS Component ab1001 !!
!! Component ab1001 OVERLAPS Component ab1004 !!
!! Component ab1001 OVERLAPS Component ab1002 !!
!! Component ab1003 OVERLAPS Component ab1004 !!
!! Component ab1001 OVERLAPS Component ab1001 !!
!! Component ab1007 OVERLAPS Component ab1007 !!
The code works for the first line of the text file and edits the components correctly(whithout the loop). However when i tried to get it to loop through the rest of the lines in the file it fails and i get end of file errors.
I cant seem to find a loop that works properly
here is the code i am working on:
global fileUnderTest = "c:\\test1.txt"
--fn overlapHighlight dirString=
--(
max select all
$.xray = on
--fileUnderTest = dirString
fs = openFile fileUnderTest
seek fs #eof -- couldnt get a while loop to work so i tried this instead
maxlen=filepos fs
seek fs 0
count = 1
while count != maxlen do (
count = filepos fs
skipToString fs "Component "
obj1 = readChars fs 6
skipToString fs "Component "
obj2 = readChars fs 6
myObj1 = getNodeByName obj1
myObj1.xray = False
myObj2 = getNodeByName obj2
myObj2.xray = False
selectionSets = #(myObj1, myObj2)
)
close fs
--)
This is a sample from the text file i am trying to read
!! Component ab1001 OVERLAPS Component ab1002 !!
!! Component ab1003 OVERLAPS Component ab1004 !!
!! Component ab1001 OVERLAPS Component ab1001 !!
!! Component ab1001 OVERLAPS Component ab1004 !!
!! Component ab1001 OVERLAPS Component ab1002 !!
!! Component ab1003 OVERLAPS Component ab1004 !!
!! Component ab1001 OVERLAPS Component ab1001 !!
!! Component ab1007 OVERLAPS Component ab1007 !!