Home › Forums › Problems and solutions in GDL › GDL add-ons › Possible to use data from external text file as parameters?
Tagged: filter text gdl external array
- This topic has 11 replies, 2 voices, and was last updated 6 years, 5 months ago by Péter Baksa.
-
AuthorPosts
-
-
April 12, 2018 at 14:31 #3991James GoodeParticipant
I am trying to find a way to filter through a large list of data from my text file. As far as I know there is not a way to use values from a dynamic array as variables (please correct me if I am wrong). Is there a function along the lines of
if x contains y then
“do this”
endifeven if it is a bit more complex than the above it would be brilliant to know!
or if there are any other ways to filter data coming in from external text filesThanks!
-
April 12, 2018 at 15:18 #3992James GoodeParticipant
DIM sarray[] var = "" filename = "ProjectNotes.txt" ch1 = OPEN ("text", filename, "MODE=RO, LIBRARY") i = 1 j = 1 y = 1 sarray[j]="" repeat n = INPUT (ch1, y, 1, var) pos = STRSTR (var, "EF-25") L1 = STRSUB (var, 1, pos) sarray[j] = var j=j +1 i=i+1 y=y+1 until var = prefix CLOSE ch1 VALUES "refnote" sarray
This repeats over and over thus causing a crash but I think it’s something along the lines that I am going for. I want it to repeat until one of my lines contains “EF-25” then not include that line. If anyone can help me solve it then I would really appreciate it!
-
April 18, 2018 at 10:54 #4002Péter BaksaKeymaster
This is also a nice solution, you need
until pos = 1
, meaning the string was found at position 1.STRSUB returns the substring from position 1 to pos.
var = prefix
is only true if var is exactly prefix, not longer.Péter Baksa
Library Platform, Software Engineer
GRAPHISOFT SE-
April 18, 2018 at 15:25 #4003James GoodeParticipant
This is also a nice solution, you need
until pos = 1
, meaning the string was found at position 1.STRSUB returns the substring from position 1 to pos.
var = prefix
is only true if var is exactly prefix, not longer.I don’t suppose you would be able to give an example would you?
Thanks
-
-
-
April 19, 2018 at 08:01 #4004Péter BaksaKeymaster
Hi,
the example is just a small modification of your code:
DIM sarray[] var = "" filename = "ProjectNotes.txt" ch1 = OPEN ("text", filename, "MODE=RO, LIBRARY") j = 1 sarray[j]="" repeat n = INPUT (ch1, j, 1, var) pos = STRSTR (var, "EF-25") sarray[j] = var j = j + 1 until pos = 1 CLOSE ch1 VALUES "refnote" sarray
I haven’t tested it, I guess it should work 🙂
The easiest way to debug GDL when you don’t know what is happening is to use PRINT commands. Or, you can use BREAKPOINT with the debugger, as explained here.
Péter Baksa
Library Platform, Software Engineer
GRAPHISOFT SE -
April 19, 2018 at 09:19 #4005James GoodeParticipant
hmm, I tried this but it just causes ArchiCAD to crash
-
April 19, 2018 at 09:21 #4006James GoodeParticipant
okay, update. It seems to almost work however it includes the EF_25 line which I don’t want it to include.
Is there a way to exclude this line? -
April 19, 2018 at 11:00 #4008Péter BaksaKeymaster
Yes, rewrite
sarray[j] = var
toif pos # 1 then sarray[j] = var
Péter Baksa
Library Platform, Software Engineer
GRAPHISOFT SE -
April 19, 2018 at 11:32 #4009James GoodeParticipant
This seems to work but when I press check script it crashes ArchiCAD every time. Is this some kind of bug?
-
April 19, 2018 at 13:05 #4010Péter BaksaKeymaster
Sorry, this is an infinite loop if the file doesn’t contain a line starting with “EF-25”.
useuntil pos = 1 or n = -1
to terminate. INPUT returns -1 when end of file is reached.Péter Baksa
Library Platform, Software Engineer
GRAPHISOFT SE -
April 19, 2018 at 13:38 #4011James GoodeParticipant
Amazing! Thanks very much!
Another problem with it…I need it to follow on from the previous j so instead of the EF_20’s, it’s now EF_25 until EF_30 in the same text document. It currently includes all of the EF_20’s and EF_25’s. It does however stop before EF_30 which is great.
I considered using Vardim on refnote to get the amount but I didn’t know how to correctly implement it.
Thanks in advance!
DIM sarray[] var = "" filename = "ProjectNotes.txt" ch1 = OPEN ("text", filename, "MODE=RO, LIBRARY") sarray[j]="" repeat n = INPUT (ch1, j, 1, var) pos = STRSTR (var, "EF_30") if pos # 1 then sarray[j] = var j = j + 1 until pos = 1 or n = -1 CLOSE ch1 VALUES "refnote2" sarray
-
April 19, 2018 at 16:22 #4012Péter BaksaKeymaster
I don’t clearly understand what is your goal, but it sounds complex.
You could try to read all of the file into an intermediate array, than filter the needed strings in one or more separate loops to another array.Péter Baksa
Library Platform, Software Engineer
GRAPHISOFT SE
-
-
AuthorPosts
- The forum ‘GDL add-ons’ is closed to new topics and replies.