New Toolbar button ?
-
I posted earlier about creating a new ruby for reporting.
Ok - I've got that figured now, but for the next step I'd like to add a toolbar button to launch the script (rather than it being done from the plug-ins menu).
Can anyone tell me if this is do-able - and if so, is there any information anywhere explaining how to do it??
TIA
-
Have you looked at the API docs: http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/toolbar.html
The first example on that page shows how to add a toolbar with a button. -
Thanks ThomThom.
I have looked at this and got it working with my own icons and dialog, but can someone tell me what I need to enter in the cmd line to launch a ruby - for example called 'myruby.rb' which is in a plugin subdirectory called 'myruby'.
@unknownuser said:
toolbar = UI::Toolbar.new "Test"
# This toolbar icon simply displays Hello World on the screen
%(#FF0040)[cmd = UI::Command.new("Test") {
UI.messagebox "Hello World"
}]
cmd.small_icon = "ToolPencilSmall.png"
cmd.large_icon = "ToolPencilLarge.png"
cmd.tooltip = "Test Toolbars"
cmd.status_bar_text = "Testing the toolbars class"
cmd.menu_text = "Test"
toolbar = toolbar.add_item cmd
toolbar.show -
You add that code to your 'myruby.rb' itself. Not as a separate script.
Replace
UI.messagebox "Hello World"
with the method call to your script. The same command you used in your menu item. -
Thanks Thomthom.
Forgive my ignorance, but I am not a script writer and have simply cobbled together a couple of scripts by 'hacking' parts of other scripts together to suit my needs, and this particular task is a little bit beyond me at present.
When you said
@unknownuser said:The same command you used in your menu item.
I assumed that you were referring to the part in my 'myruby.rb' where the command is added to the plug-ins menu - ie@unknownuser said:
plugins_menu = UI.menu "Plugins"
plugins_menu.add_item("Generate CSV") {
dcomp_reporter2.generate_attributes_report("report.html", Sketchup.active_model.entities)I tried replacing the UI.messagebox "Hello World"with the third line of the above (which appears to be part that launches the script from the plugins menu), but this does not work.
What have I misunderstood.
TIA
-
You have understood correctly. - think. from what I can see at least.
do you get any errors in the console when it doesn't work? -
This is what I have at the beginning of the script, the part between the toolbar mods is what I added to the original script - did I put it in the wrong place?
@unknownuser said:
require 'sketchup.rb'
Monkeypatching the hash to allow the uniq function of array to work...
class Hash
def hash
to_a.hash
end
alias eql? ==
endclass DCompReporter2
#-----toolbar mod begins-----------
toolbar = UI::Toolbar.new "Reporter"
# This toolbar icon simply displays Hello World on the screen
cmd = UI::Command.new("Reporter") {
dcomp_reporter2.generate_attributes_report("report.html", Sketchup.active_model.entities)
}
cmd.small_icon = "dcreports/Excel16.png"
cmd.large_icon = "dcreports/Excel32.png"
cmd.tooltip = "Produce Report"
cmd.status_bar_text = "Produce Report"
cmd.menu_text = "Report"
toolbar = toolbar.add_item cmd
toolbar.show#-----------------------------toolbar mod ends------------
After that is the script which still works when loaded from the plugins menu.
I get no errors on screen when I start SU, and when I click the icon on the toolbar, nothing happens.
How do I check the console to see if there are any errors when I click the icon?
-
Here are the errors shown in the console when I click the toolbar icon.
@unknownuser said:
Error: #<NameError: undefined local variable or method
dcomp_reporter2' for DCompReporter2:Class> C:/Program Files/Google/Google SketchUp 7/Plugins/DComponentReportercsv.rb:37 C:/Program Files/Google/Google SketchUp 7/Plugins/DComponentReportercsv.rb:36:in
call' -
No worries - I fixed it
-
Modifying Ruby and Sketchup base classes are a big no-no. Some other plugin might require the original behaviour.
Instead of modifying the existing - create your own class which inherit the HAsh class and modify that.
Advertisement