sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Passing arguements

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 244 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        class My_Tool
          def initialize(selection)
            # do something 'selection' is now a variable
          end
        end
        
        my_very_own_tool = My_Tool.new(menu_selection)
        

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • honoluludesktopH Offline
          honoluludesktop
          last edited by

          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
          
          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Yes. πŸ˜„ You got it!

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • Chris FullmerC Offline
              Chris Fullmer
              last edited by

              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

              Lately you've been tan, suspicious for the winter.
              All my Plugins I've written

              1 Reply Last reply Reply Quote 0
              • honoluludesktopH Offline
                honoluludesktop
                last edited by

                Guys, thanks for the help. Chris, I will look very carefully at your example.

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement