Possible to use data from external text file as parameters?

Home Forums Problems and solutions in GDL GDL add-ons Possible to use data from external text file as parameters?

Viewing 9 reply threads
  • Author
    Posts
    • #3991
      James Goode
      Participant

      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”
      endif

      even 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 files

      Thanks!

    • #3992
      James Goode
      Participant
      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!

      • #4002
        Péter Baksa
        Keymaster

        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

        • #4003
          James Goode
          Participant

          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

    • #4004
      Péter Baksa
      Keymaster

      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

    • #4005
      James Goode
      Participant

      hmm, I tried this but it just causes ArchiCAD to crash

    • #4006
      James Goode
      Participant

      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?

    • #4008
      Péter Baksa
      Keymaster

      Yes, rewritesarray[j] = var to if pos # 1 then sarray[j] = var

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

    • #4009
      James Goode
      Participant

      This seems to work but when I press check script it crashes ArchiCAD every time. Is this some kind of bug?

    • #4010
      Péter Baksa
      Keymaster

      Sorry, this is an infinite loop if the file doesn’t contain a line starting with “EF-25”.
      use until 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

    • #4011
      James Goode
      Participant

      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
    • #4012
      Péter Baksa
      Keymaster

      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

Viewing 9 reply threads
  • The forum ‘GDL add-ons’ is closed to new topics and replies.