sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Saving a row of variables into a text-file

    Scheduled Pinned Locked Moved Newbie Forum
    sketchup
    3 Posts 2 Posters 136 Views 2 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.
    • artmusicstudioA Offline
      artmusicstudio
      last edited by

      hi,
      with this code i can save a row of my variables to a text - file, but in one line

      file = File.open("C:/Program Files (x86)/Google/Google SketchUp 8/Plugins/zf/partemp.txt", "w") { |f|
      f << lines[0].to_f
      f << lines[1].to_f
      f << lines[2].to_f
      }

      when i try to separate the values by \n, there is a syntax error:

      file = File.open("C:/Program Files (x86)/Google/Google SketchUp 8/Plugins/zf/partemp.txt", "w") { |f|
      f << lines[0].to_f\n
      f << lines[1].to_f\n
      f << lines[2].to_f\n
      }

      no tips about this on the net.

      any tips for the syntax?

      thanx stan

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

        You don't clarify what lines[0] is??

        f.puts(lines[0].to_f.to_s)

        this adds a line of text, and puts automatically adds the "\n" at the end
        Why make it into a float unless you are trying to format it in some way ?
        The file itself will hold only a string?

        Another way... if the lines in the array are already in strings is:
        string=lines.join("\n")
        then 'sting' is something like:
        "1.2\n3.4\n5.6"
        so then just do one puts into the file with:
        f.puts(string) ?

        You need to do some more reading up on reading/writing files... and numbers versus strings etc...

        TIG

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          hi tig,
          ok, you are right, puts does it automatically.

          the declaration of the variables happens in the beginning of the ruby,
          first loaded from the default file and then possibly changed by the user...

          these settings then create the geometry and are saved to a separate file (later as function : reload last user parameters).

          will just try the puts-version.

          stan

          EDIT: IT WORKS

          parameters are saved at the end of ruby
          and
          automatically reloaded on start

          😄

          wonderful!

          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