I’d like to be able to update the enabled state of the VCB in response to mouse move events, but it seems that SketchUp only calls
Tool::enableVCB? under certain circumstances.
The example below demonstrates the issue (I’m using Sketchup 2021). I’d like to allow the user to move the mouse in a direction and then use the VCB to indicate a length along that vector. Before the mouse has moved, the vector is zero and so an entered length would be ambiguous. So I try to enable the input box only after the mouse is moved.
class LineToolTest def initialize(pt1) @pt1 = pt1 end def activate puts 'LineToolTest.activate' @pt2_ip = Sketchup::InputPoint.new(@pt1) @inference_ip = Sketchup::InputPoint.new(@pt1) Sketchup.vcb_label = 'Distance' end def enableVCB? puts 'LineToolTest.enableVCB?' !@vector.nil? && @vector.length > 0.to_l end def onMouseMove(_flags, x, y, view) puts 'LineToolTest.onMouseMove' if @pt2_ip.pick(view, x, y, @inference_ip) @vector = @pt1.vector_to(@pt2_ip.position) Sketchup.vcb_value = @vector.length view.invalidate end end def onUserText(text, view) puts 'LineToolTest.onUserText' end end Sketchup.active_model.select_tool LineToolTest.new(Geom::Point3d.new(0, 0, 0))
Running this snippet and then moving the mouse results in this output sequence. I notice the VCB value is updated with the distance, but getter is not called again and the enabled state of the box is never changed.
LineToolTest.activate LineToolTest.enableVCB? LineToolTest.onMouseMove LineToolTest.onMouseMove LineToolTest.onMouseMove ...
There are at least a few events that do seem to cause the getter to be invoked. Mouse down and mouse up both trigger it, at least for the left button. (I’ll see the
LineToolTest.enableVCB? log message and then the input box will be enabled.) Key down and key up don’t seem to, and neither does temporarily switching to another tool like orbit.
Is this just a limitation of the implementation? Is there a way to force SketchUp to enable the VCB other than in response to clicks and tool activation?