In my super move tool I was planning to use vcb input to place multiple components. I would have liked to do the action right after the x is entered into vcb without requiring enter to be pressed. I can trigger that using the onKeyDown method, but I can’t get the vcb value from onKeyDown. I found Sketchup.vcb_value, but it is a write only method.
when 106, 88 # * or x
#add n number of openings spaced out evenly
text = Sketchup.vcb_value # <-- this doesn't work!
num = text.gsub('x', '').gsub('*', '').to_i
num = 1 if num < 1
p "#{num} openings added (not implemented)"
return
end
Does anyone know of a way to get the vcb value at a given time? If not I’ll file an issue in the tracker.
Unfortunatly I couldn’t get the onebox to change even though the spelling is corrected in the issue tracker.
I’m not really sure how that would make a difference. Currently the events are fires when the modifier is pressed, and then again when another key is pressed. So for example if the user presses Ctrl+C there are two events fired. First Ctrl and then C.
Thinking aloud, It’s just a concept idea (for Windows):
class MyToolKeyTest
def activate
clear_my_vcb
end
def clear_my_vcb
@my_vcb =""
end
def num_decode(key)
case key
when 49, 97
return "1"
when 50, 98
return "2"
when 51, 99
return "3"
when 52, 100
return "4"
# etc...do it for e.g. all numeric keys
else
return ""
end
end
def enableVCB?
return true
end
def onKeyUp(key, repeat, flags, view)
puts "onKeyUp: key = #{key}"
# you can use the "recorded" @my_vcb on other method
@my_vcb += num_decode(key)
puts "my_vcb = #{@my_vcb}"
case key
when 106, 88 # * or x
num = @my_vcb.to_i
num = 1 if num < 1
p "#{num} openings added (not implemented)"
clear_my_vcb
# optional : Sketchup.vcb_value = ""
return
end
return true
end
def onLButtonDoubleClick(flags, x, y, view)
#just an example to clear my_vcb...
puts "DoubleClick"
clear_my_vcb
puts "my_vcb = #{@my_vcb}"
end
end
Sketchup.active_model.select_tool(MyToolKeyTest.new)
I had thought of that but decided to stick with the vcb onUserText which requires an additional enter key press. If you took the route you proposed you would also need to handle back space, and cases where the vcb_value was set at other places in the tool.
The additional enter key press required in order to use vcb text is the current complaint. In addition, if the user is entering text in the vcb you might want to disable some of the modifiers in the tool. Currently there is no way to detect if the user is in the process of entering text in vcb.