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!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    Error checking routine issue?

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 550 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.
    • T
      tomot
      last edited by

      The following statement works!

      if (@width < 2) 
      UI.messagebox( "A Width of less than 2 is not allowed ")
      return nil
      end
      

      Question: How do I combine less than and more than into one statement using Ruby?
      The Ruby API is not very clear on this. Neither of the 2 statements below work!

      if (@width < 2 > 12)
      UI.messagebox( "A Width of less than 2 or greater than 12 is not allowed ")
      return nil
      end
      
      if ( 2 < @width > 12)
      UI.messagebox( "A Width of less than 2 or greater than 12 is not allowed ")
      return nil
      end
      

      Tia!

      my plugins
      tomot

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

        Use the OR operator: ||

        <span class="syntaxdefault">if </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">width </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> 2 </span><span class="syntaxkeyword">||</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">width </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> 12<br />  UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">"A Width of less than 2 or greater than 12 is not allowed "</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  return nil<br />end</span>
        

        http://www.techotopia.com/index.php/Ruby_Operators#Ruby_Comparison_Operators

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

        1 Reply Last reply
        Reply Quote 0
        • T
          tomot
          last edited by

          Thanks thomthom, I also just noticed I should have posted this in Developers' Forum ....my bad!

          my plugins
          tomot

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

            Moved it. Didn't notice it was in the Plugins section.

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

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

              @tomot said:

              Question: How do I combine less than and more than into one statement using Ruby?
              The Ruby API is not very clear on this.

              Nor would it be !

              The Google SketchUp Ruby API, consists of only 3 modules (and a lot of classes inside them.) Also a few additions to a couple of standard Ruby classes.

              This API, only extends standard Ruby, so we can work with Sketchup and it's models.

              You need to use the standard Ruby reference to understand what methods are available to the standard Ruby modules and classes.

              You need to read a good book on standard Ruby programming, to understand how to program in Ruby, before you can effectively know how to employ the SketchUp Ruby API's extensions. (This book is also distributed as a CHM, in the full Ruby install. See the "C:\Ruby186\doc" directory.)

              I'm not here much anymore.

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

                You can also use the between? method:

                unless @width.between?(2,12)
                  UI.messagebox( "A Width of less than 2 or greater than 12 is not allowed ")
                  return nil
                end
                

                .. or you could use a literal Range object, and it's include? method:

                unless (2..12).include?(@width)
                  UI.messagebox( "A Width of less than 2 or greater than 12 is not allowed ")
                  return nil
                end
                

                You can also use a Range object's === method:

                unless (2..12) === @width
                  UI.messagebox( "A Width of less than 2 or greater than 12 is not allowed ")
                  return nil
                end
                

                I'm not here much anymore.

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

                  And you can also create referenced Range objects:

                  @valid_width = 2..12

                  @valid_width.class

                  Range

                  so..

                  return nil unless @valid_width === @width

                  I'm not here much anymore.

                  1 Reply Last reply
                  Reply Quote 0
                  • T
                    tomot
                    last edited by

                    Thanks Dan! for raking me over the coals.... I needed that ...ouch! 😄

                    my plugins
                    tomot

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

                      I just want you to understand where the information you need is at. (And that it is readily available.) Will save you a lot of grief.

                      Not a day goes by, without me opening both of these CHM references (they are both open right now, in fact, but minimized to the taskbar.)

                      I'm not here much anymore.

                      1 Reply Last reply
                      Reply Quote 0
                      • T
                        tomot
                        last edited by

                        I understand fully! and that's why your 1 of 3 of my favorite "SU Ruby API goto guys"
                        I also have to include TIG! & thomthom!

                        my plugins
                        tomot

                        1 Reply Last reply
                        Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement