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

    Create file with accent in the path

    Scheduled Pinned Locked Moved Developers' Forum
    23 Posts 3 Posters 923 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.
    • IltisI Offline
      Iltis
      last edited by

      OK, this code works on SU8 :

      		  begin
      		  File.open(filepath, "w"){ |file|
      			...
      		  }
      		 	UI.messagebox("The file is here ;" + filepath)
      		rescue
      		 	UI.messagebox("Error, the file was not created. Be careful if you are using an older version of SketchUp, the full file path must not contain special or accented characters. The full file path you requested is " + filepath)
      		 end
      

      The "è" looks "è" in the messagebox, but the user know how to fix the problem.

      I try to use it in SketchUp 2014, but I've got an error 😞

      Erreur de chargement du fichier faces2xy.rb
      Error; #<SyntaxError; C;/Users/Tarzan/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/faces2xy.rb;18; syntax error, unexpected ',', expecting ')'
      		  filepath = UI.savepanel ("Export selected faces",nil,"*.f2xy")
      C;/Users/Tarzan/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/faces2xy.rb;18; Can't assign to nil
      		  filepath = UI.savepanel ("Export selected faces",nil,"*.f2xy")
      C;/Users/Tarzan/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/faces2xy.rb;18; syntax error, unexpected ')', expecting ;; or '[' or '.'
      		  filepath = UI.savepanel ("Export selected faces",nil,"*.f2xy")
      
      

      Do you know how to fix this (in all SU versions...)?
      Thanks,
      Renaud

      1 Reply Last reply Reply Quote 0
      • tt_suT Offline
        tt_su
        last edited by

        @iltis said:

        The "è" looks "è" in the messagebox, but the user know how to fix the problem.

        That's odd - if the string is UTF-8 encoded then it should look fine in SketchUp regardless.
        Have you saved your RB files as UTF-8 without BOM?

        @iltis said:

        I try to use it in SketchUp 2014, but I've got an error 😞

        I'm not sure, but I think it could be that space you have between the method name and the parentheses: filepath = UI.savepanel ("Export selected faces",nil,"*.f2xy")

        But the error could be cascading some elsewhere... hard to tell without knowing the source code.

        Btw, it's recommended not to catch all exceptions, but only the ones you expect.
        http://www.skorks.com/2009/09/ruby-exceptions-and-exception-handling/

        1 Reply Last reply Reply Quote 0
        • IltisI Offline
          Iltis
          last edited by

          Bingo! 2/2. It works fine now. Is "UTF-8 without BOM" the best to use? (Default value?)
          Thank you for the quick answer!
          I will see how to catch only the file exception.

          1 Reply Last reply Reply Quote 0
          • IltisI Offline
            Iltis
            last edited by

            Mhh, the error is

            Error; #<Errno;;ENOENT; No such file or directory - C;/Users/Tarzan/Documents/aiR-C2/MiniCut2d/Bibliothèque/test.f2xy>
            

            I don't understand how to only catch this type of exception... (not in the "Ruby Exception Hierarchy"). I'll see this later.

            1 Reply Last reply Reply Quote 0
            • tt_suT Offline
              tt_su
              last edited by

              @iltis said:

              Bingo! 2/2. It works fine now. Is "UTF-8 without BOM" the best to use?

              I recommend that because without the BOM you can load the file in Ruby 1.8. With the BOM Ruby 1.8 will not load it.

              1 Reply Last reply Reply Quote 0
              • tt_suT Offline
                tt_su
                last edited by

                @iltis said:

                Mhh, the error is

                Error; #<Errno;;ENOENT; No such file or directory - C;/Users/Tarzan/Documents/aiR-C2/MiniCut2d/Bibliothèque/test.f2xy>
                

                I don't understand how to only catch this type of exception... (not in the "Ruby Exception Hierarchy"). I'll see this later.

                You should be able to catch Errno::ENOENT - it's a class inherited form StandardError.

                Errno::ENOENT.ancestors [Errno::ENOENT, SystemCallError, StandardError, Exception, Object, PP::ObjectMixin, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]

                Though, it might be system dependant... Maybe catching SystemCallError is a good one to catch for these types of errors.

                1 Reply Last reply Reply Quote 0
                • IltisI Offline
                  Iltis
                  last edited by

                  OK, thank you.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    Like this:

                      begin
                        File.open(filepath, "w"){ |file|
                          #...
                        }
                        UI.messagebox("The file is here ;" + filepath)
                      rescue SystemCallError => e
                        if e.message =~ /(No such file or directory)/
                          UI.messagebox("Error, the file was not created. Be careful if you are using an older version of SketchUp, the full file path must not contain special or accented characters. The full file path you requested is " + filepath)
                        else
                          fail() #re-raise the last exception
                        end
                      end
                    

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • IltisI Offline
                      Iltis
                      last edited by

                      Nice, thank you Dan!

                      1 Reply Last reply Reply Quote 0
                      • tt_suT Offline
                        tt_su
                        last edited by

                        @dan rathbun said:

                        fail() #re-raise the last exception

                        Never seen that method used before. Is that different from just calling raise?

                        1 Reply Last reply Reply Quote 0
                        • Dan RathbunD Offline
                          Dan Rathbun
                          last edited by

                          @tt_su said:

                          @dan rathbun said:

                          fail() #re-raise the last exception

                          Never seen that method used before. Is that different from just calling raise?

                          raise() is an alias for fail()
                          See the doc on the Kernel module:
                          http://www.ruby-doc.org/core-1.8.6/Kernel.html#method-i-fail

                          The best practices guides I have read, suggest that fail be used instead of raise, for readability, I suppose. But I really did not understand the logic in the guide. (I think it was something like "raise" has more meanings as a verb than "fail" ?)

                          I'm not here much anymore.

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

                          Advertisement