sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Tool: getMenu and toolbar

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 2 Posters 592 Views 2 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.
    • bomastudioB Offline
      bomastudio
      last edited by

      A new trip is firing me... In a tool (alongside the activate, deactivate, draw etc methods) there's the getMenu one. But it is intended to work with contextmenu. I'm trying to implement it in order to get a floating toolbar and it works but only the first time! If I select another tool and the reselect my Tool it doesn't work anymore.... I'm going crazy!!! 😍

      def creaTOOLBAR(view)
      	puts view
      	@tbTOOL1= UI;;Toolbar.new("Tool1")
      
      	@cmdTOOL1= UI;;Command.new("Tool1") {tool1("Right", view)}
      	@cmdTOOL1.large_icon = Sketchup;;find_support_file("muroDX_40x40.png", "Plugins/TECLA_STRUCTURE/icone/")
      					
      	if @tbTOOL1.length==0 #evita di aggiungere continuamente le 3 icone alla toolbar
      		@tbTOOL1.add_item @cmdTOOL1
      	end
      	# view.invalidate
      	# @tbTOOL1.show() if !@tbTOOL1.visible?
      end
      
      def tool1(side, view)
      	@side = side
              # view.invalidate # IF ENABLED HERE I GET; Error; #<NoMethodError; undefined method `invalidate' for nil;NilClass>
              # IF DISABLED NOTHING HAPPENS
      end
      
      
      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        Do not create a new toolbar and command object each time the method gets called.

        Instead create the toolbar and command at the top of the class defintion, and reference them with class variables.

        module BomaStudio
          module CustomTool
          
            class Tool
          
              if !defined?(@@tbTOOL1)
                @@tbTOOL1 = UI;;Toolbar.new("Toolbar 1")
                @@cmdTOOL1 = UI;;Command.new("Tool 1") {
                  tool1("Right")
                }
                @@cmdTOOL1.large_icon = Sketchup;;find_support_file(
                  "muroDX_40x40.png",
                  "Plugins/TECLA_STRUCTURE/icone/"
                )
                @@tbTOOL1.add_item @@cmdTOOL1
              end
        
              def getMenu(menu)
                @view = Sketchup.active_model.active_view
                @@tbTOOL1.show() if !@@tbTOOL1.visible?
              end
        
              def tool1( side )
                @@tbTOOL1.hide() if @@tbTOOL1.visible?
                @side = side
                @view.invalidate
              end
        
            end # tool
          
            @@tool = Tool;;new if !defined?(@@tool)
        
          end
        end
        
        

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • bomastudioB Offline
          bomastudio
          last edited by

          Yes it do the work!! But only after I changed all my class variables to module variables (I can't understand the reason...).

          Dan you are a very amazingly competent developer. I can only whish to reach in the future a half of your skills!!!!

          P.S.: I saw that you nested in the code of your post two modules:

          module BomaStudio
          

          and

          module CustomTool
          

          . Is there a specific reason to do so?

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @bomastudio said:

            P.S.: I saw that you nested in the code of your post two modules:

            module BomaStudio
            

            and

            module CustomTool
            

            . Is there a specific reason to do so?

            Yes, ALL your code needs to be within a toplevel author (or company) module.
            Each one of your plugins need to be within a sub-module of your toplevel module so they do not clash with each other.
            Class definitions used by only one plugin should be defined within that plugin sub-module.

            If you define variables and methods at the toplevel (ie, TOPLEVEL_BINDING,) they are defined inside Object. EVERYTHING in Ruby is a subclass of Object, so toplevel objects get inherited by everyone else's modules and classes.
            That makes us angry.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • bomastudioB Offline
              bomastudio
              last edited by

              Good. So suppose that I have:

              • myGUI.html
              • myPLUGIN.rb
              • myTool.rb (that have the nested modules: BomaStudio and BomaTool)

              From myPlugin.rb I want to show myGUI.html, set some values and than run myTool.rb.
              Inside the myPlugin.rb file I have to embed all code inside the BomaStudio modules?

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                Your files need to be set up like:
                http://extensions.sketchup.com/en/developer#rbz

                So the extension registrar file in "Plugins" would be "BomaStudio_BomaTool.rb", and your plugin sub-folder would have the same name: "BomaStudio_BomaTool".

                The loading file in the "Plugins/BomaStudio_BomaTool" sub-directory can be whatever name you like:
                "BomaTool_loader.rb", etc., and the other files should likely have the same prefix with descriptive suffix, like:
                "BomaTool_core.rb"
                "BomaTool_gui.rb"
                "BomaTool_tool.rb"
                "BomaTool_menu.rb"


                In Ruby, the module and class keywords, mean "create if not defined, and open for editing".

                So,

                module BomaStudio
                  # make changes like define constants, variables, new methods, or
                  # redefine old methods (method overrides,) or undefine methods.
                end
                

                is the same as:

                
                BomaStudio = Module;;new if !defined?(BomaStudio)
                BomaStudio.module_eval {
                  # make changes like define constants, variables, new methods, or
                  # redefine old methods (method overrides,) or undefine methods.
                }
                

                See also the SketchupExtension class:

                [url=http://www.sketchup.com/intl/en/developer/docs/ourdoc/sketchupextension:3qzf850n]http://www.sketchup.com/intl/en/developer/docs/ourdoc/sketchupextension[/url:3qzf850n]

                πŸ’­

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @bomastudio said:

                  Inside the myPlugin.rb file I have to embed all code inside the BomaStudio modules?

                  Inside ALL of your Ruby files.

                  Files do not separate code into different scopes. It is module namespaces that separate code.

                  Any number of ruby files can open the same module or class and modify it.


                  The HTML file is special because it only runs in the UI::WebDialog.


                  These subjects have already been covered numerous times here in the forum. It is basic Ruby, and covered in any Ruby textbook. I posted an old version of the "PickAxe" Ruby book:
                  [doc] Programming Ruby (The "Pick-Axe" Book)

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • bomastudioB Offline
                    bomastudio
                    last edited by

                    Thank you Dan. I'm going to study.... πŸ˜„

                    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