Attempting to make a button for a toolbar
-

I'm trying to make a toolbar button. I used the webexporter files as my guides. I was able to create the toolbar with the button but the button didn't execute thedefit did nothing. I was messing around with it and now I'm getting "Error Loading File addfg2walls.rb
undefined local variable or method `fg2walls' for main:Object"my addfg2walls.rb file (the one that creates the button)looks like this...
require "Rapidset/fg2walls.rb" def createPlugin() fg2walls.init() end createPlugin()and my fg2walls.rb file (the one that defines the button and the
defI want the button to run) looks like this...` require 'sketchup'
def fg2walls::init()
cmd = UI::Command.new(fg2walls.handleToolbarPress) {handleToolbarButtonPress()}
cmd.small_icon = "FG.png"
cmd.large_icon = "FG.png"
cmd.status_bar_text = cmd.tooltip = "Fox Gray"
cmd.menu_text = "Wall Colors"
wallsToolbar = UI::Toolbar.new("Wall Colors")
wallsToolbar.add_item(cmd)
wallsToolbar.showUI.menu("Plugins").add_item("FG Walls") { fg2walls.init }
enddef fg2walls::handleToolbarButtonPress()
mod = Sketchup.active_model
su_materials = mod.materials
my_materials = Hash.new
my_materials["Wall_surfaces"] = su_materials["FG"]begin
mod.start_operation("Change Walls", true)
rescue ArgumentError
mod.start_operation("Change Walls")
endmod.entities.each do |entity|
if entity.is_a? Sketchup::Drawingelement
entity.material = my_materials[entity.layer.name] if my_materials[entity.layer.name]
end
endmod.commit_operation
end`As I said I was just using the WebExporter files as a guide so I don't even know if these need to be two separate files. You know it's funny as soon as I start to feel confident enough to start putting my own things together, Ruby has a way of reminding me that I know nothing. Below you can download either of the files to edit them.
addfg2Wallsfg2walls -
I only had a chance to barely glance at the code, but the first thing I see is that you want to define the toolbar and the menu AFTER all methods are defined. Because the menu item you create is calling a method that is not yet defined, and I think that might throw an error in SU.
-
Ahh, looking a little close I see other errors in the way.
I'll try to get a beter response put together, unless someone else beats me to it.
Chris
-
Alright it's actually pretty simple. If anybody else needs the same thing here you go...
` toolbar = UI::Toolbar.new "TOOLBAR.NAME"
cmd = UI::Command.new("TOOLBAR.ITEM.NAME") { ###copy everything from the def you want to use here... ###call it... DEF.NAME.call() } cmd.small_icon = "PATH.TO.ICON" cmd.large_icon = "PATH.TO.ICON" cmd.tooltip = "POPUP.TEXT" cmd.status_bar_text = "TEXT" cmd.menu_text = "TEXT" toolbar = toolbar.add_item cmd toolbar.show`
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