sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    โš ๏ธ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    [QUESTION] Reading Text From TXT

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 170 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Dave RD Offline
      Dave R
      last edited by

      A friend of mine is working on a script that generates a file for printing. He is interested in being able to add some user-supplied text from a TXT file. Would one of the gurus be so kind as to give an idea about how that is done so I can pass it on to him? Thanks in advance.

      Etaoin Shrdlu

      %

      (THERE'S NO PLACE LIKE)

      G28 X0.0 Y0.0 Z0.0

      M30

      %

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        To read text from a file he needs to have the path to it as a string, he then needs to 'open' the file for reading and then read it and then close it.
        If he is adding stuff into another file he should already be aware of several similar methods - so something like...
        infile="C:/Temp/In.txt" return unless File.exist?(infile) fi=File.open(infile, "r") txt=fi.read fi.close outfile="C:/Temp/Out.txt" fo=File.open(outfile, "w") fo.puts("This is text read from '"+infile+"'") fo.puts(txt) fo.puts("That was text read from '"+infile+"'") fo.close
        Of course the files' paths will vary!
        He might already have the 'outfile' open to 'puts' into...

        TIG

        1 Reply Last reply Reply Quote 0
        • Dave RD Offline
          Dave R
          last edited by

          Thank you very much, TIG. I'll pass that on to him. ๐Ÿ‘

          Etaoin Shrdlu

          %

          (THERE'S NO PLACE LIKE)

          G28 X0.0 Y0.0 Z0.0

          M30

          %

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            I'd just write:

            text = IO.read("path/to/file.txt")

            Hi

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement