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 the def
it 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 def
I 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.show
UI.menu("Plugins").add_item("FG Walls") { fg2walls.init }
end
def 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")
end
mod.entities.each do |entity|
if entity.is_a? Sketchup::Drawingelement
entity.material = my_materials[entity.layer.name] if my_materials[entity.layer.name]
end
end
mod.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