Passing arguements
-
Can Class My_Tool have the following form? Class My_Tool(menu_selection). If not how can I pass menu_selection, that are outside the Class to it? Hope my question makes sense.
-
class My_Tool def initialize(selection) # do something 'selection' is now a variable end end my_very_own_tool = My_Tool.new(menu_selection)
-
Thanks, Tom. Is this OK, and safe to use?
Class My_IDX_PointTool def initialize(menu_selection) @sel = menu_selection end def program #do somenting with menu_selection puts @sel end end
-
Yes.
You got it!
-
I use this also:
class My_Class def option1(arg, arg2, etc) puts arg my_etc(etc) end def option2(arg, arg2, etc) puts arg2 my_etc(etc) end def my_etc(etc) puts etc end end arg = Sketchup.active_model.selection arg2 = Sketchup.active_model etc = [1,2,3] tool_object = My_Class.new plugins_menu = UI.menu("Plugins") plugins_menu.add_item("Option 1") {Sketchup.active_model.select_tool(tool_object.option1(arg, arg2, etc))} plugins_menu.add_item("Option 2") {Sketchup.active_model.select_tool(tool_object.option2(arg, arg2, etc))}
That is also a way to use the same tool object each time the tool gets called, instead of instantiating a new one each time. And I point diretly to a specific method within the class when I start the tool. It could also be done with a line like this:
Sketchup.active_model.select_tool( My_Class.new.option1(arg,arg2,etc)
See how that instantiantes a new tool object each time its run, but it also points directly to a method of the class.
Hope that made sense,
Chris
-
Guys, thanks for the help. Chris, I will look very carefully at your example.
Advertisement