Problems with PickHelper
-
@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. -
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 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.
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 LoginAdvertisement