Problems with PickHelper
- 
 @hsmyers said: @thomthom said: Can you elaborate to what didn't work and what you expected to see happening? Never having used PickHelper, I really didn't have any expectations other than a vague notion of some indication that the code was in control of the 'pick' process but I saw no such indication during testing. I noticed that what I was printing to the console didn't appear which suggests an error of some sort...which I foolishly failed to save, I clear the console with each run head slap I'm not even all that clear on how I should integrate what I need with the tool under development—roll it into the tool or separate class within? 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
- 
 @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.newAh! On such screw-ups as this are founded the bugs that plague us!        Much and many thanks sir. Much and many thanks sir.
- 
 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.picksImplication 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 In line with previous I had expectedph.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    
- 
 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.) 
- 
 @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!  
- 
 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. 
- 
 @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
- 
 @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/289Hmmm...haven't used any, could be interesting... 
- 
 So much nicer to debug - no more editing files to add print statements and reloading. 
- 
 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  
- 
 No worries - we all learn. Thanks for posting back your solution. 
Advertisement



 
                             
                             
                             
                             
                             
                             
                            