ArtF
|
 |
« Reply #315 on: July 18, 2019, 07:30:29 AM » |
|
Gary:
As a general guide, if you look in the scripters command list youll see many file functions . To access them you use this syntax..
myfile = system.Fi le(); myfile.Op en("*"); //using a * will open a search dialog. A name will open that file.
you may then use the other file primitive s on the myfile object.
Art
|
|
|
Logged
|
|
|
|
ArtF
|
 |
« Reply #316 on: July 18, 2019, 09:10:24 AM » |
|
Gary:
Here is a sample script using the file system for spirals. It is written by YaNvrNo awhile back during developme nt.
Art
|
|
|
Logged
|
|
|
|
gburk
|
 |
« Reply #317 on: July 18, 2019, 07:57:31 PM » |
|
OK thanks ART
at the moment I just wanted to save text file or read text files..
I am attaching another g code file its pretty busy has pocketing peck drilling and engraving, I did a dry run in auggie and it seemed to run fine but still calls the first m6 twice, maybe you can see something in this one you couldn't see in the other g code file I sent you..
Thanks gary
|
|
|
Logged
|
|
|
|
gburk
|
 |
« Reply #318 on: July 23, 2019, 03:22:11 PM » |
|
Art
Is this a good way to read a file or do you suggest a different approach ?
global next_line = table();
myfile = system.Fi le(); myfile.Op en("*"); line = 0; next_line[line] = myfile.Re adLine(); while (next_line[line] != EOF) { line = line + 1; next_line[line] = myfile.Re adLine(); if (next_line[line] == null) { exit(); } print(next_line[line]); }; Gary
|
|
|
Logged
|
|
|
|
ArtF
|
 |
« Reply #319 on: July 23, 2019, 04:14:07 PM » |
|
Gary:
Looks as efficient as any script ID write. Good job.
Art
|
|
|
Logged
|
|
|
|
gburk
|
 |
« Reply #320 on: July 23, 2019, 05:18:28 PM » |
|
Art
One problem on large files it seems to read the EOF before its read the whole file at least it exits the loop and stops printing
small files its good, don't see any errors popping up is there a buffer limit to a table ?..
Gary
|
|
|
Logged
|
|
|
|
ArtF
|
 |
« Reply #321 on: July 23, 2019, 07:21:44 PM » |
|
Gary:
Im sure a limit may exist, but I dont think in this case, unless one line gets too large it shouldnt run into memory problems.
Your routine will skip the first line though... Id suggest the following change. I might add the the null check may not be necessary as the print routine shouldn't fail on a print(null) and it is possible for readline to return null without being at the end of a file.
line = 0; next_line[line] = myfile.Re adLine(); while (next_line[line] != EOF) { print(next_line[line]); line = line + 1; next_line[line] = myfile.Re adLine(); if (next_line[line] == null) { print("Null line found before end of file"); //can be ignored in many cases.. exit(); } };
Art ]
|
|
|
Logged
|
|
|
|
gburk
|
 |
« Reply #322 on: July 24, 2019, 09:24:42 AM » |
|
Art
I gave it a try same results, it seems its reading the end of file early... It printed part of the file then quit, I assume it thought it read EOF, because it didn't print the null line..
it seems to run for a few second before it starts to print, I have no delays in there.. do you think its looping faster that it can print to screen..?
I will try looping with no print just storing the text lines in the table then print out the table in a loop worth a try..
Gary
|
|
|
Logged
|
|
|
|
ArtF
|
 |
« Reply #323 on: July 24, 2019, 09:44:02 AM » |
|
Gary:
There shouldnt be any buffer limit for the file, but the table may have a line limit. Try replacing the same table line each time and see if it reads the entire file. Im not sure the error, I havent played with files much, just scripting tests early on for putting out point clouds and such.
Art
|
|
|
Logged
|
|
|
|
gburk
|
 |
« Reply #324 on: July 24, 2019, 10:56:45 AM » |
|
Art
Will give that a shot, I added line numbers to the print, one file reaches line 48 before it thinks it is reading a null and the other file stopped at line 46 before nulling out of the loop..
so could be table does have a limit and one file has more char's per line than the other so reads a couple more lines..
tried printing the file and only using a var next_line no table clearing the var each loop but did the same thing.. I wouldn't think there is some sort of looping limit going on?. just a thought
Update I have tried a few different txt files now and seems to make it to line 50 then exits the loop no print output so its not getting the null check just quits looping at or just under 50 lines of text..
Thanks gary
|
|
« Last Edit: July 24, 2019, 03:27:50 PM by gburk »
|
Logged
|
|
|
|
gburk
|
 |
« Reply #325 on: July 25, 2019, 01:30:10 PM » |
|
Art
I tried a loop that should loop 200 times and reading the file but it seems after 50 line read it exits the loop it doesn't print any of my messages like it hit a null or EOF or file closed just exits the loop.. here is a sample..
global next_line = table(); fileload = function() { myfile = system.Fi le(); myfile.Op en("*"); line = 0; next_line[line] = myfile.Re adLine(); dowhile (line !=200) { print("Line # "+line+" "+next_line[line]); line = line + 1; next_line[line] = myfile.Re adLine(); if (next_line[line] == EOF) { print("EOF Reached"); myfile.Cl ose(); print("File Closed"); return; } if (next_line[line] == null) { print("Line = Null"); myfile.Cl ose(); print("File Closed"); exit(); } }; myfile.Cl ose(); print("File Closed"); };
fileload();
this script also only print 49 or 50 lines
x = 0; dowhile( x < 400) { x = x + 1; print("X = "+x); };
gary
|
|
« Last Edit: July 25, 2019, 07:29:28 PM by gburk »
|
Logged
|
|
|
|
gburk
|
 |
« Reply #326 on: July 28, 2019, 04:12:39 PM » |
|
Art
I removed the print during the loops, and only printed the last line read and line number when exiting the loop. Its seems to finish looping this way, so it does seem that the print() is doing something to the loops if printing every line in the loop.. then it doesn't finish the loop or give an error either..
but read a 5000 plus line file not printing the lines only printed the last line on exit of the loop and it printed line 5082..
Gary
|
|
|
Logged
|
|
|
|
Ya-Nvr-No
|
 |
« Reply #327 on: July 29, 2019, 11:04:12 AM » |
|
have you tried a sleep(.04); //of some micro second after or before a line read? sounds like reading of the file or printing is causing a buffer spooling/overload/limit of some kind.
I believe Art is off cruising on vacation.
|
|
|
Logged
|
|
|
|
gburk
|
 |
« Reply #328 on: July 29, 2019, 03:25:14 PM » |
|
Ya-Nvr-No
Thanks that seemed to fix it I thought there was a buffer problem but had no errors, I wouldn't use the print while loading a file normally but was testing to make sure the entire file was loaded, and it is..
Thanks gary
|
|
|
Logged
|
|
|
|
ArtF
|
 |
« Reply #329 on: July 30, 2019, 05:39:33 PM » |
|
Hi Gary:
Sorry I missed that one, luckily YaNvrNo was around, he knows Auggie pretty much as well as I and somewhat better in scripting . He was instrumen tal in its developme nt. Im deep into serious math learning for an upcoming (perhaps) module Im writing so Im a bit intermitt ant. When the math gets too deep for me I tend to lose track and hadnt checked in a few days to see how this thread was doing (for some reason it no longer sends me notificat ions on this thread.).
Glad the fix helped, probably the print buffer was filled and waiting for a sleep or yield to get time to finish its work.
Art
|
|
|
Logged
|
|
|
|
|