Write text file to embedded library

Home Forums Problems and solutions in GDL GDL add-ons Write text file to embedded library

This topic contains 21 replies, has 2 voices, and was last updated by  James Goode 4 days, 20 hours ago.

  • Author
    Posts
  • #4291

    James Goode
    Participant

    Hello,

    is it possible to write a text file to the embedded library?

    Thanks

  • #4292

    Péter Baksa
    Participant

    Hello,

    yes it is possible, with limitations:
    – new files can’t be created
    – writing is only possible after version 17
    – after version 18 writing is only possible from the UI, Parameter or Property scripts

    channel = OPEN ("TEXT", "data.txt", "SEPARATOR = ' ', MODE = WO, LIBRARY")
    OUTPUT channel, row, column, value
    close channel
    

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

  • #4293

    James Goode
    Participant

    For the object I’m creating, I want to be able to output the symb_pos_x & y of that object. Can that be sent to the embedded library?

  • #4294

    James Goode
    Participant

    I also want to then read that value in a different file

  • #4295

    Péter Baksa
    Participant

    Yes, it can. You have to add the “data.txt” (or other filename that you are using) to the embedded library first.

    Another limitation is that in teamwork the user needs to reserve the file to be able to write to it.

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

  • #4296

    James Goode
    Participant

    I can’t seem to get my object to write the symb_pos_x and symb_pos_y to the file at all. My other object can definitely read the file though.

    this is my code for OUTPUT

    chOUT=OPEN ("TEXT", "SurveyPoint.txt", "separator =' ', MODE=WO, LIBRARY")
    	OUTPUT chOUT, 1, 1, symb_pos_x
    	OUTPUT chOUT, 2, 1, symb_pos_y
    	OUTPUT chOUT, 3, 1, symb_pos_z
    close chOUT
  • #4297

    James Goode
    Participant

    I’ve got it reading and writing correctly but I get error reports saying Cannot modify the file in embedded library in 2D script type, Nonexistent channel and Open error while operating on the file

  • #4298

    James Goode
    Participant

    are you able to write to a library from within a pla?

  • #4299

    Péter Baksa
    Participant

    No, in 2D / 3D script you can’t write. Only UI, Parameter or Property scripts.
    .pla should work.

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

  • #4300

    James Goode
    Participant

    Is it possible for me to output the symb_pos_x and y without the output being in the 2D script?

  • #4301

    Péter Baksa
    Participant

    Previously I tested your idea with print commands, all worked nice, but now I see that the values don’t get written to the data file.

    The problem is that even if the parameter script is run when you move the object, or open the settings, it runs in a sandboxed mode, and the changes won’t be applied unless any parameter changes.

    If you change some hidden parameter, eg. increment a counter, it will work – interestingly, toggling a boolean isn’t enough, maybe because the param script runs even number of times.

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

    • #4324

      Péter Baksa
      Participant

      With further inspection I’ve found that this is not an usable solution:
      the parameter script could be run not just for the placed object, but as a mockup-object of the settings dialog. This can overwrite data very easily, eg. changing the library part of the object tool, selecting another object on the floor plan, viewing favorites, or changing to a different tool.

      Péter Baksa
      Software Engineer, Library Team
      GRAPHISOFT SE

  • #4315

    James Goode
    Participant

    Hello,

    I have got this working perfectly apart from the fact that I receive an error when placing my object that writes the file.
    It still works, but the error is stopping us from progressing with it.

  • #4316

    Péter Baksa
    Participant

    Hi, what is the error message?

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

  • #4317

    James Goode
    Participant

    There are several. This issue is that it definitely works.

    Nonexistent channel
     at line 68 in the 2D script of file Survey Point Output.gsm.
    Nonexistent channel
     at line 69 in the 2D script of file Survey Point Output.gsm.
    Nonexistent channel
     at line 70 in the 2D script of file Survey Point Output.gsm.
    Nonexistent channel
     at line 71 in the 2D script of file Survey Point Output.gsm.
    Cannot modify the file (filelog.TXT) in embedded library in 2D script type.
    Open error
    while operating on file 'filelog.TXT'.
    Nonexistent channel
     at line 68 in the 2D script of file Survey Point Output.gsm.
    Nonexistent channel
     at line 69 in the 2D script of file Survey Point Output.gsm.
    Nonexistent channel
     at line 70 in the 2D script of file Survey Point Output.gsm.
    Nonexistent channel
     at line 71 in the 2D script of file Survey Point Output.gsm.
    Cannot modify the file (filelog.TXT) in embedded library in 2D script type.
    Open error
    while operating on file 'filelog.TXT'.
    Cannot modify the file (filelog.TXT) in embedded library in 2D script type.
    Open error
    while operating on file 'filelog.TXT'.
    Cannot modify the file (filelog.TXT) in embedded library in 2D script type.
    Open error
    while operating on file 'filelog.TXT'.
    Cannot modify the file (filelog.TXT) in embedded library in 2D script type.
    Open error
    while operating on file 'filelog.TXT'.
    Cannot modify the file (filelog.TXT) in embedded library in 2D script type.
    Open error
    while operating on file 'filelog.TXT'.
    Cannot modify the file (filelog.TXT) in embedded library in 2D script type.
    Open error
    while operating on file 'filelog.TXT'.
  • #4318

    Péter Baksa
    Participant

    Did you add “filelog.txt” to the embedded library?
    New files cannot be created in the embedded library, you can only modify existing ones.

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

  • #4319

    James Goode
    Participant

    Yes I have
    The error only pops up if I select either the writing or reading gdl object.

  • #4320

    James Goode
    Participant

    I’ve also tried to get the file to write and read from a loaded library that isn’t the embedded but it still seems to try to write/read to the embedded library and throws up an error until I move it and then ctrl+shift+alt+R then it begins to work with both the reading object and the writing object. Here is the writing / reading code that I have in my objects;

    Writing

    chOUT=OPEN ("TEXT", "filelog.TXT", "MODE=WO, LIBRARY")
    	OUTPUT chOUT, 1, 1, symb_pos_x
    	OUTPUT chOUT, 2, 1, symb_pos_y
    	OUTPUT chOUT, 3, 1, symb_pos_z
    close chOUT

    Reading

    chIN=OPEN ("TEXT", "filelog.TXT", "MODE=RO, LIBRARY")
    n = input (chIN,1, 1, zxzx)
    n1 = input (chIN,2, 1, zxzxz)
    n2 = input (chIN,3, 1, zxzxzx)
    close chIN
  • #4321

    Péter Baksa
    Participant

    Sorry, I don’t know what is the problem, your examples work fine for me.

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

    • #4322

      James Goode
      Participant

      Is there any way I would be able to send you my files for you to take a look at?

      Thanks

      • #4323

        James Goode
        Participant

        or do you have an example file that uses my examples that I could take a look at?

        Thanks

  • #4333

    James Goode
    Participant

    Problem solved! As discussed, the issue was that I had the output in both the Parameter script and the 2D script. It was solved by removing the code from the 2D and keeping it in the parameter script.

You must be logged in to reply to this topic.