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

    Reading numbers from external text file

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 2 Posters 7.7k 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.
    • PixeroP Offline
      Pixero
      last edited by

      3.4919929866069115
      "x";
      3.4919929866069115,
      "Nil result (no result returned or run failed)"
      
      1 Reply Last reply Reply Quote 0
      • PixeroP Offline
        Pixero
        last edited by

        3.4919929866069115
        3.4919929866069115,
        "Nil result (no result returned or run failed)"
        
        1 Reply Last reply Reply Quote 0
        • PixeroP Offline
          Pixero
          last edited by

          Here is the txt file I'm loading. (It's a json file from the beginning.)

          test1.txt

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

            Are you running this in the Ruby Console, or in some other console extension ?
            Try this without the ' def'

            
            filepath = UI.openpanel("Open File", "C;/", "TXT|*.txt||")
            if filepath ### allows user to Cancel
              settings = File.readlines(filepath)
              puts settings[2].split(' ')[1].to_f
            else
              puts "Canceled!"
            end
            
            

            TIG

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

              Our posts crossed.
              Both my versions of the code work fine with your TXT file, with no error [in Ruby Console].
              So do you use a console-app ?

              TIG

              1 Reply Last reply Reply Quote 0
              • PixeroP Offline
                Pixero
                last edited by

                Interesting.
                Running your latest code in the console works but running it in SketchUp Ruby Code Editor by Alexander Schreyer gives the Nil result also.

                I also tried your first version in the console and it worked without errors.
                So is it safe to continue if it's just something in his Code editor app that causes the Nil result?

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

                  Most of these console-apps are not perfect...
                  I only ever use the Ruby Console.
                  😉

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • PixeroP Offline
                    Pixero
                    last edited by

                    Thanks for all the help so far. I'm sure there will be more later on...
                    If only the Ruby console was multi lines. It's hard to edit in the small window.

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

                      I always edit my code in a Notepad++/TextWrangler window [with Ruby text-highlighting], then I copy/paste it into the Ruby Console's bottom bar + enter, to run it.
                      The Ruby Console accepts multi-line code if pasted, but you can only manually type in one line at a time!

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • PixeroP Offline
                        Pixero
                        last edited by

                        I use Notepad++ as well but use the ruby code editor when testing out snippets without having to restart SketchUp.
                        Now I’ll continue with the main work.

                        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