sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Trapping error messages

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 363 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.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by

      When I group = entities.add_face (my_face_points), and my_face_points are not coplanar, the application crashes. The API indicates that:

      
      if (group)
        puts "OK"
      else
        puts "Failed"
      end
      

      But that didn't work for not coplanar. Is there any way to trap the error message, and continue running the application?

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

        
        begin
          ### try to do something
          group = entities.add_face(my_face_points)
          result="OK."
        rescue
          ### what to do if it fails
          result="MISERABLE FAILURE!"
        end
        UI.messagebox(result)
        
        

        πŸ€“

        TIG

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @honoluludesktop said:

          group = entities.add_face (my_face_points)

          1. why are you naming the variable group when you get a face in return?
          2. avoid space between method name and brackets.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • honoluludesktopH Offline
            honoluludesktop
            last edited by

            Thanks fellows, I will try to run with those tomorrow. Tom, perhaps I should have written my_faces in place of group.

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @honoluludesktop said:

              Thanks fellows, I will try to run with those tomorrow. Tom, perhaps I should have written my_faces in place of group.

              It's much easier to follow the code when the variables aren't ambiguously named.

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • honoluludesktopH Offline
                honoluludesktop
                last edited by

                You are right, at the time it seemed OK, sorry:-(

                1 Reply Last reply Reply Quote 0
                • honoluludesktopH Offline
                  honoluludesktop
                  last edited by

                  TIG, Works great. I guess I now have to be careful not to bypass any errors that destroy the data base, and crash SU or the plugin:-)

                  I tried the following to aid debugging, but the failed command would not run after the Ruby panel opened.

                  begin
                    group = @entities.add_group(@my_entities)
                  rescue #comes here when @my_entities is not a "add_group" entity
                    result = Sketchup.send_action "showRubyPanel;"
                    group = @entities.add_group(@my_entities)#this did not run
                  end
                  

                  But I have lots of other uses for it, Thanks.

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

                    This is a fuller example using multi-rescues

                    
                    begin
                      # .. the process
                    rescue SyntaxError, NameError => ex
                      print "String doesn't compile; " + ex
                      # .. tidy up
                    rescue SystemCallError => ex
                      print "System Call Error; " + ex
                      # .. tidy up
                    rescue StandardError => ex
                      print "Error running script: " + ex
                      # .. tidy up
                    ensure
                      # .. this is for a 'tidy up' when there's something 'wrong' 
                      # .. BUT it's NOT an 'error' per se
                      # .. e.g. f.close unless f.nil?
                    end
                    

                    If you are using it for 'testing' code then just keep the Ruby Console open...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • honoluludesktopH Offline
                      honoluludesktop
                      last edited by

                      TIG, Thanks, is there a way to open SU with the Ruby Console open? Or, do you debug by keeping SU open, then cut and paste to the Web Console?

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

                        Add Sketchup.send_action "showRubyPanel:"
                        into the start of your script just after require 'sketchup.rb'
                        BUT remember to ### it out when you are done!

                        TIG

                        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