Writing to a text file

Home Forums Problems and solutions in GDL GDL add-ons Writing to a text file

This topic contains 6 replies, has 4 voices, and was last updated by  Joachim Sühlo 3 weeks, 4 days ago.

  • Author
    Posts
  • #4263

    James Goode
    Participant

    Hello,

    I want to be able to write parameter values to a text document and then read those values in another object. Is this possible? If so, how can I achieve this. I have found the OPEN, INPUT, OUTPUT functions in the GDL Reference Guide but they don’t really go into specifics and a bit more guidance would be much appreciated.

    Thanks

  • #4264

    Michael Herse
    Participant

    A good starting point would be to have a look at the example script and files here http://gdl.graphisoft.com/tips-and-tricks/how-to-read-and-write-text-files.

    Cheers,
    Michael.

  • #4265

    James Goode
    Participant

    I’ve had a go using that as a base but I can’t get my write code to work. Here it is;

    ch1 = OPEN ("TEXT", "TEST123", "separator = ' ', MODE = WO")
    
    string = "12345"
    OUTPUT ch1, 1, 0, string 
  • #4266

    Péter Baksa
    Participant

    Hi,

    reading and writing to files from GDL is only good for communication with external programs.

    The problem with communication between library parts is that the order in which the scripts run is not deterministic. There is no guarantee that the current parameters will be written to the file before the other libpart will try to read it.

    The only way for communication between library parts is to write an Add-on that sets and reads parameters of the library parts based on their subtype.
    This is beyond GDL, C++ programming experience is required. You can join the API developer community at http://archicadapi.graphisoft.com/start.

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

  • #4267

    James Goode
    Participant

    I understand that it isn’t a perfect solution but it’s something that may be suitable for what we need. Can you point me in the right direction in terms of my code and why it’s not writing to the file?

  • #4268

    Péter Baksa
    Participant

    Try adding close ch1, maybe the data will be written only then. I haven’t tried it, just guessing.

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

  • #4269

    Joachim Sühlo
    Participant

    James, with your script the file is written into a special folder, which differs from Mac to Windows.
    Maybe you did not find it (on Mac it is placed within the Library Folder). You could try to wrie the file in a special directory (use the keyword FULLPATH).
    Some good examples of writing and raeding text files you can find in the GDL Cookbook 3, including the saving of parameter values.

    GDL Object Developer
    b-prisma
    MAC OSx 10.11

You must be logged in to reply to this topic.