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

    Problems with PickHelper

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 3 Posters 1.0k 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.
    • hsmyersH Offline
      hsmyers
      last edited by

      @sdmitch said:

      In the API the ph = view.pick_helper statement does not does not have variables passed to it. Taking off the (x,y) made it work for me.

      class HSM_Picker
      >   def activate
      >     @@picks = []
      >     Sketchup.set_status_text('Select an object', SB_PROMPT)
      >   end
      > 
      >   def deactivate(view)
      >     view.invalidate
      >   end
      > 
      >   def onLButtonUp(_flags, x, y, view)
      >     ph = view.pick_helper
      >     ph.do_pick(x, y)
      >     @@picks << ph.best_picked
      >     if @@picks.length == 2
      >       p 'done'
      >       Sketchup.active_model.select_tool(nil)
      >     end
      >   end
      > 
      >   def onCancel(_flag, _view)
      >     Sketchup.send_action('selectSelectionTool;')
      >   end
      > end # class HSM_Picker
      > Sketchup.active_model.select_tool HSM_Picker.new
      

      Ah! On such screw-ups as this are founded the bugs that plague us! πŸ‘ πŸ‘ πŸ‘ πŸ˜„ Much and many thanks sir.

      1 Reply Last reply Reply Quote 0
      • hsmyersH Offline
        hsmyers
        last edited by

        Back to debugging... The following appears to run without errorβ€”or actually without doing anything other than returning "[]"!

        mod = Sketchup.active_model # Open model
        ent = mod.entities # All entities in model
        sel = mod.selection # Current selection
        
        SKETCHUP_CONSOLE.clear
        
        class HSM_Picker
        
          @@picks = []
          
          def activate
            @@picks = []
            Sketchup.set_status_text('Select an object', SB_PROMPT)
          end
        
          def deactivate(view)
            view.invalidate
          end
        
          def onLButtonUp(_flags, x, y, view)
            ph = view.pick_helper
            ph.do_pick(x, y)
            @@picks << ph.best_picked
            if @@picks.length == 2
              p 'done'
              Sketchup.active_model.select_tool(nil)
            end
          end
        
          def onCancel(_flag, _view)
            Sketchup.send_action('selectSelectionTool;')
          end
          
          def picks
            @@picks
          end
        end # class HSM_Picker
        
        pk = HSM_Picker.new()
        ets = pk.picks
        
        

        Implication clearly being that I don't know what I'm doing (certainly true!) So once again begging for clues here... 😞 In line with previous I had expected

        ph.do_pick(x, y)
        

        to politely wait for the user to make a selection (or two) and then be available for interrogation but I fear that may have been naive. My initial understanding ( or miss in this case ) is often warped by my expectations based on years of building APIs more sigh 😞 😞

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

          What is the value you get from .best_picked?

          That should only return an entity - so I wouldn't expect @@picks.length to work. (Unless you accidentally picked an edge - in which case you are getting the length of the edge.)

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

          1 Reply Last reply Reply Quote 0
          • hsmyersH Offline
            hsmyers
            last edited by

            @thomthom said:

            What is the value you get from .best_picked?

            That should only return an entity - so I wouldn't expect @@picks.length to work. (Unless you accidentally picked an edge - in which case you are getting the length of the edge.)

            Don't know, will find out...oh the joys of print statements! πŸ˜„

            1 Reply Last reply Reply Quote 0
            • sdmitchS Offline
              sdmitch
              last edited by

              The class HSM_Picker works as a Tool but must be envoked by Sketchup.active_model.select_tool HSM_Picker.new. The problem is getting the two selected entities returned since the normal return is the model object.

              Nothing is worthless, it can always be used as a bad example.

              http://sdmitch.blogspot.com/

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

                @hsmyers said:

                @thomthom said:

                What is the value you get from .best_picked?

                That should only return an entity - so I wouldn't expect @@picks.length to work. (Unless you accidentally picked an edge - in which case you are getting the length of the edge.)

                Don't know, will find out...oh the joys of print statements! πŸ˜„

                Try the debugger: https://github.com/SketchUp/sketchup-ruby-debugger
                I prefer RubyMine for debugging: http://forums.sketchup.com/t/please-help-me-to-setup-de-debugger-on-rubymine-for-mac/289

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

                1 Reply Last reply Reply Quote 0
                • hsmyersH Offline
                  hsmyers
                  last edited by

                  @thomthom said:

                  @hsmyers said:

                  @thomthom said:

                  What is the value you get from .best_picked?

                  That should only return an entity - so I wouldn't expect @@picks.length to work. (Unless you accidentally picked an edge - in which case you are getting the length of the edge.)

                  Don't know, will find out...oh the joys of print statements! πŸ˜„

                  Try the debugger: https://github.com/SketchUp/sketchup-ruby-debugger
                  I prefer RubyMine for debugging: http://forums.sketchup.com/t/please-help-me-to-setup-de-debugger-on-rubymine-for-mac/289

                  Hmmm...haven't used any, could be interesting...

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

                    So much nicer to debug - no more editing files to add print statements and reloading.

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

                    1 Reply Last reply Reply Quote 0
                    • hsmyersH Offline
                      hsmyers
                      last edited by

                      As is often the case the problem is simpleβ€”code in question works much better if properly invoked:

                      pk = HSM_Picker.new()
                      mod.select_tool(pk)
                      

                      Thanks all, sorry for the stupidity 😞

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

                        No worries - we all learn. Thanks for posting back your solution.

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

                        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