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.
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