• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

[QUESTION] Reading Text From TXT

Scheduled Pinned Locked Moved Developers' Forum
4 Posts 3 Posters 155 Views
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.
  • D Offline
    Dave R
    last edited by 29 Apr 2012, 11:04

    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
    • T Offline
      TIG Moderator
      last edited by 29 Apr 2012, 11:17

      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
      • D Offline
        Dave R
        last edited by 29 Apr 2012, 11:23

        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 29 Apr 2012, 11:39

          I'd just write:

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

          Hi

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

          Advertisement