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

    How is this possible ?

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 3 Posters 558 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.
    • thomthomT Offline
      thomthom
      last edited by

      hm... am I making stuff up again... πŸ˜•

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

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        Thanks thomthom,
        and while we are at it, another weird thing:

        def test()
        case Sketchup.active_model.selection[0].class
        		  when Sketchup;;Face
        			puts "face"
        		  when Sketchup;;ComponentInstance
        			puts "instance"
        		  when Sketchup;;Group
        			puts "group"
        		  when Sketchup;;Image
        			puts "image"
        		  when Sketchup;;Edge
        			puts "edge"
        		  else
        			puts "something else"
        		end
        end
        

        This always outputs "something else" in the Console. Case with 'class' as switch isn't allowed or not effective ? 😲

        DB

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

          This comparison weirdness doesn't happen for me.
          Do you have a script that's loading and resetting == for 'equality comparisons' in the Float class?
          I ran a BareGrep on my ../Plugins folder and found no likely culprits for ' class Float' matches - although I did find I have a Float def =~ in my Roof.rb tools which takes Floats to within 1/1000 as being equal - as in 0.0001==0 >>> false BUT 0.0001=~0 >>> true - but I don't suspect that...
          This is what I get

          y=9.09494701772928e-013
          9.09494701772928e-013
          y==0
          false
          y<0
          false
          y>0
          true
          y==0.001
          false
          y>0.001
          false
          y<0.001
          true
          (y*1000000).to_i/1000000.0
          0.0
          (y*10000000000000).to_i/10000000000000.0
          9.0e-013
          
          

          So you can see how to test for nearness to zero with the differing accuracies as the last two examples...
          BUT all == return correct results otherwise πŸ˜•

          TIG

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

            @didier bur said:

            Thanks thomthom,
            and while we are at it, another weird thing:

            def test()
            > case Sketchup.active_model.selection[0].class
            > 		  when Sketchup;;Face
            > 			puts "face"
            > 		  when Sketchup;;ComponentInstance
            > 			puts "instance"
            > 		  when Sketchup;;Group
            > 			puts "group"
            > 		  when Sketchup;;Image
            > 			puts "image"
            > 		  when Sketchup;;Edge
            > 			puts "edge"
            > 		  else
            > 			puts "something else"
            > 		end
            > end
            

            This always outputs "something else" in the Console. Case with 'class' as switch isn't allowed or not effective ? 😲

            I found this out when writing my SKMtools class

            case v.class.to_s
              when 'Fixnum'
            

            was my fix... it returns the class name as a string and compares it with another string in the 'when'... so your method WILL work thus

                def test()
                case Sketchup.active_model.selection[0].class.to_s
                        when 'Sketchup;;Face'
                         puts "face"
                        when 'Sketchup;;ComponentInstance'
                         puts "instance"
                        when 'Sketchup;;Group'
                         puts "group"
                        when 'Sketchup;;Image'
                         puts "image"
                        when 'Sketchup;;Edge'
                         puts "edge"
                        else
                         puts "something else"
                      end
                end
            

            TIG

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

              @tig said:

              This comparison weirdness doesn't happen for me.
              Do you have a script that's loading and resetting == for 'equality comparisons' in the Float class?

              The object type you get from Boundingbox is Length - not Float. This is why you see this difference. Length has that tolerance built in. Something one need to be aware of when you compare data in Ruby SU. Always check if you have a Float or Length.

              @tig said:

              was my fix... it returns the class name as a string and compares it with another string in the 'when'... so your method WILL work thus

              But will be very slow - same performance issue like using .typename.

              I don't know why one can't use class for switch cases - but instead you should use if,elsif along with .class or .is_? in order to maintain performance. As string operations while iterating entities is just all too big of an performance hit.

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

              1 Reply Last reply Reply Quote 0
              • Didier BurD Offline
                Didier Bur
                last edited by

                Thanks tt & tig for yur answers;
                I'm aware of the "strings comparison time killer" that's why i want to use the class for the switch.
                i'll use "elseif" instead 😞

                DB

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

                  I really don't understand why switch own't work - since face1.class == face2.class work fine...

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

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

                    Ah - so then we can just do this:

                    
                    def test()
                    case Sketchup.active_model.selection[0]
                            when Sketchup;;Face
                             puts "face"
                            when Sketchup;;ComponentInstance
                             puts "instance"
                            when Sketchup;;Group
                             puts "group"
                            when Sketchup;;Image
                             puts "image"
                            when Sketchup;;Edge
                             puts "edge"
                            else
                             puts "something else"
                          end
                    end
                    
                    

                    ❓ Right?

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

                    1 Reply Last reply Reply Quote 0
                    • Didier BurD Offline
                      Didier Bur
                      last edited by

                      Partial answer here: http://www.postal-code.com/mrhappy/blog/2007/02/01/ruby-comparing-an-objects-class-in-a-case-statement/
                      and here http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/3d83faf049160e58

                      This works:

                      case Sketchup.active_model.selection[0]
                                  when 'Sketchup;;Face'
                                   puts "face"
                      ...
                      

                      The simplest the best !

                      DB

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

                        @didier bur said:

                        Partial answer here: http://www.postal-code.com/mrhappy/blog/2007/02/01/ruby-comparing-an-objects-class-in-a-case-statement/
                        and here http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/3d83faf049160e58

                        This works:

                        case Sketchup.active_model.selection[0]
                        >             when 'Sketchup;;Face'
                        >              puts "face"
                        > ...
                        

                        The simplest the best !

                        So in your case

                            def test()
                            case Sketchup.active_model.selection[0]
                                    when Sketchup;;Face
                                     puts "face"
                                    when Sketchup;;ComponentInstance
                                     puts "instance"
                                    when Sketchup;;Group
                                     puts "group"
                                    when Sketchup;;Image
                                     puts "image"
                                    when Sketchup;;Edge
                                     puts "edge"
                                    else
                                     puts "something else"
                                  end
                            end
                        

                        should work ??? Avoiding the .to_s step πŸ˜„

                        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