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

      
      ["{\n", "  \"principalPoint\"; {\n", "    \"x\"; 3.4919929866069115,\n", "    \"y\"; -0.017301744356540385\n", "  },\n", "  \"viewTransform\"; {\n", "    \"rows\"; [\n", "      [\n", "        -0.9075910551963806,\n", "        0.4198243379864999,\n", "        -0.005099192261283809,\n", "        -31.940051338855746\n", "      ],\n", "      [\n", "        0.00419330408856825,\n", "        -0.003080616899800699,\n", "        -0.9999864629085424,\n", "        -0.10391287329462531\n", "      ],\n", "      [\n", "        -0.4198343634438959,\n", "        -0.9076001515170179,\n", "        0.0010354892297866703,\n", "        -17.250974969132418\n", "      ],\n", "      [\n", "        0,\n", "        0,\n", "        0,\n", "        1\n", "      ]\n", "    ]\n", "  },\n", "  \"cameraTransform\"; {\n", "    \"rows\"; [\n", "      [\n", "        -0.9075910551963807,\n", "        0.00419330408856825,\n", "        -0.41983436344389585,\n", "        -36.23062125433451\n", "      ],\n", "      [\n", "        0.41982433798650004,\n", "        -0.0030806168998006997,\n", "        -0.9076001515170179,\n", "        -2.2480967029645083\n", "      ],\n", "      [\n", "        -0.005099192261283809,\n", "        -0.9999864629085424,\n", "        0.0010354892297866703,\n", "        -0.24891673044480064\n", "      ],\n", "      [\n", "        0,\n", "        0,\n", "        0,\n", "        1\n", "      ]\n", "    ]\n", "  },\n", "  \"horizontalFieldOfView\"; 0.9813963064459168,\n", "  \"verticalFieldOfView\"; 0.6616350540688956,\n", "  \"vanishingPoints\"; [\n", "    {\n", "      \"x\"; -0.5541295463355106,\n", "      \"y\"; 0.0013923823242965234\n", "    },\n", "    {\n", "      \"x\"; 4.357757655415969,\n", "      \"y\"; -0.02365461394665286\n", "    },\n", "    {\n", "      \"x\"; 12.708844850226638,\n", "      \"y\"; 1807.4703594352652\n", "    }\n", "  ],\n", "  \"vanishingPointAxes\"; [\n", "    \"xPositive\",\n", "    \"yPositive\",\n", "    \"zPositive\"\n", "  ],\n", "  \"relativeFocalLength\"; 1.8716593429474995,\n", "  \"imageWidth\"; 5000,\n", "  \"imageHeight\"; 3214\n", "}"]
      "[\"{\\n\", \"  \\\"principalPoint\\\"; {\\n\", \"    \\\"x\\\"; 3.4919929866069115,\\n\", \"    \\\"y\\\"; -0.017301744356540385\\n\", \"  },\\n\", \"  \\\"viewTransform\\\"; {\\n\", \"    \\\"rows\\\"; [\\n\", \"      [\\n\", \"        -0.9075910551963806,\\n\", \"        0.4198243379864999,\\n\", \"        -0.005099192261283809,\\n\", \"        -31.940051338855746\\n\", \"      ],\\n\", \"      [\\n\", \"        0.00419330408856825,\\n\", \"        -0.003080616899800699,\\n\", \"        -0.9999864629085424,\\n\", \"        -0.10391287329462531\\n\", \"      ],\\n\", \"      [\\n\", \"        -0.4198343634438959,\\n\", \"        -0.9076001515170179,\\n\", \"        0.0010354892297866703,\\n\", \"        -17.250974969132418\\n\", \"      ],\\n\", \"      [\\n\", \"        0,\\n\", \"        0,\\n\", \"        0,\\n\", \"        1\\n\", \"      ]\\n\", \"    ]\\n\", \"  },\\n\", \"  \\\"cameraTransform\\\"; {\\n\", \"    \\\"rows\\\"; [\\n\", \"      [\\n\", \"        -0.9075910551963807,\\n\", \"        0.00419330408856825,\\n\", \"        -0.41983436344389585,\\n\", \"        -36.23062125433451\\n\", \"      ],\\n\", \"      [\\n\", \"        0.41982433798650004,\\n\", \"        -0.0030806168998006997,\\n\", \"        -0.9076001515170179,\\n\", \"        -2.2480967029645083\\n\", \"      ],\\n\", \"      [\\n\", \"        -0.005099192261283809,\\n\", \"        -0.9999864629085424,\\n\", \"        0.0010354892297866703,\\n\", \"        -0.24891673044480064\\n\", \"      ],\\n\", \"      [\\n\", \"        0,\\n\", \"        0,\\n\", \"        0,\\n\", \"        1\\n\", \"      ]\\n\", \"    ]\\n\", \"  },\\n\", \"  \\\"horizontalFieldOfView\\\"; 0.9813963064459168,\\n\", \"  \\\"verticalFieldOfView\\\"; 0.6616350540688956,\\n\", \"  \\\"vanishingPoints\\\"; [\\n\", \"    {\\n\", \"      \\\"x\\\"; -0.5541295463355106,\\n\", \"      \\\"y\\\"; 0.0013923823242965234\\n\", \"    },\\n\", \"    {\\n\", \"      \\\"x\\\"; 4.357757655415969,\\n\", \"      \\\"y\\\"; -0.02365461394665286\\n\", \"    },\\n\", \"    {\\n\", \"      \\\"x\\\"; 12.708844850226638,\\n\", \"      \\\"y\\\"; 1807.4703594352652\\n\", \"    }\\n\", \"  ],\\n\", \"  \\\"vanishingPointAxes\\\"; [\\n\", \"    \\\"xPositive\\\",\\n\", \"    \\\"yPositive\\\",\\n\", \"    \\\"zPositive\\\"\\n\", \"  ],\\n\", \"  \\\"relativeFocalLength\\\"; 1.8716593429474995,\\n\", \"  \\\"imageWidth\\\"; 5000,\\n\", \"  \\\"imageHeight\\\"; 3214\\n\", \"}\"]"
      
      
      
      1 Reply Last reply Reply Quote 0
      • 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