sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Toolbars

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 5 Posters 672 Views 5 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.
    • sdmitchS Offline
      sdmitch
      last edited by

      I'm not a newbie to Sketchup but I truly am where toolbars are concerned. Is it my imagination or do you only get one shot at getting it right for a toolbar with a given name. It seems to me that once I have created a toolbar, the only way to change it is to create it with a new name otherwise none of the changes or additions take place.

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        you can certainly modify toolbars...

        you may need to turn the toolbar off before restarting sketchup then turn it back on.

        or you may even have to do an additional start without the plugin loading at all [disable or move it], before the changes take effect...

        but you can modify toolbars

        john

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 Reply Last reply Reply Quote 0
        • sdmitchS Offline
          sdmitch
          last edited by

          driven,

          OK, just how does one turn toolbars off and on? Why do you have to specify both large and small icons before they will display? Why does tb=UI.toolbar "" return a toolbar entity?

          The following example comes from the Ruby API Toolbar section. As is, it will display a toolbar with only one button because the second .add_item is missing. When you add it and rerun, the second button is still missing. Now if you change the name of the toolbar and rerun it, you get what you expect.

          toolbar = UI::Toolbar.new "Test" # This command displays Hello World
          cmd = UI::Command.new("Test 1") { UI.messagebox("Hello World 1") }
          toolbar.add_item cmd
          toolbar = toolbar.add_separator
          cmd = UI::Command.new("Test 2") { UI.messagebox("Hello World 2") }
          toolbar.show

          Nothing is worthless, it can always be used as a bad example.

          http://sdmitch.blogspot.com/

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by

            hi

            you should probably ask in dev forum, I don't write plugins, I just try and fix some to use on my mac.

            if I paste that code into Ruby console, initially I get 'one' button and one action, if I then turn it off using 'view menu>>last item' or with the toolbar button and re-paste, I then get a second button, but it's for the same action.

            what's missing is a wrapper that you add separate items to...

            try this

             # list commands
              
              cmd_Test_1 = UI;;Command.new("Test 1") { UI.messagebox("Hello World 1") }
              cmd_Test_2 = UI;;Command.new("Test 2") { UI.messagebox("Hello World 2") }
              cmd_Test_3 = UI;;Command.new("Test 3") { UI.messagebox("Hello World 3") }
              cmd_Test_4 = UI;;Command.new("Test 4") { UI.messagebox("Hello World 4") }
              
              multi_test_toolbar = UI;;Toolbar.new 'Multi_Toolbar_Test'
            
              # Create and populate the Toolbar
              multi_test_toolbar.add_item cmd_Test_1
              multi_test_toolbar.add_item cmd_Test_2 
              multi_test_toolbar.add_item cmd_Test_3
              multi_test_toolbar.add_item cmd_Test_4 
              # Tell the toolbar to show itself.
              multi_test_toolbar.show
            

            learn from the mistakes of others, you may not live long enough to make them all yourself...

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

              @sdmitch said:

              OK, just how does one turn toolbars off and on?

              View > Toolbars menu, or click the X button at the top=right of a toolbar (to close it.)

              @sdmitch said:

              Why do you have to specify both large and small icons before they will display?

              It's a Microsoft Windows API thang... not Google's fault. You can:
              cmd.small_icon = cmd.large_icon = "images/mybutton.png"
              but one of them will be stretched and a bit blurry.
              (The image path is relative to the file being run, not the "Plugins" dir. You can also use an absolute path.)

              @sdmitch said:

              Why does tb=UI.toolbar "" return a toolbar entity?

              API bug. Poorly written API code.
              This bug has been reported, but wasn't fixed for v8. It actually, creates a new toolbar, if the given "title" is not the name of a current toolbar. Mistakes can result in 'orphan' toolbars on the View>Toolbars menu, (and meaningless extra registry entries.)

              @sdmitch said:

              The following example comes from the Ruby API Toolbar section.

              The examples in the API suck. Full of typos, often don't make sense.

              Be sure to check the comments at the bottom of each API page, for corrections.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                Thanks John & Dan,

                John, your sample code works perfectly the first time but if but if you close the existing toolbar and make a change to the toolbar definition and recreate the toolbar, it is the same as the first time. I find that restarting Sketchup and recreating the toolbar solves that problem however.

                Dan, I had been just "X-ing" out of the toolbar but took a look at View>Toolbars and, as you said, there was a reference to a mis-named attempt to load just created toolbar using UI.toolbar. I totally agree about the API. It is in serious need of a rewrite.

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

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

                  @sdmitch said:

                  I find that restarting Sketchup and recreating the toolbar solves that problem however.

                  You need to keep a persistent reference to the toolbar object, inside a namespace that will not clash with other code.

                  module Sdmitch
                    @@toolbar = nil
                  
                    def self.toolbar()
                      @@toolbar
                    end
                  end
                  

                  Sdmitch.toolbar = UI::Toolbar.new("Learn")

                  So that your singleton method returns your toolbar object, and the module var keeps a reference to it.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by

                    What's the differece between an @variable and a @@variable in the previous post's scope?

                    I've always just used class variables ( @variable) since they are "global" in a module's scope.

                    Hi

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

                      @jim said:

                      What's the differece between an @variable and a @@variable in the previous post's scope?

                      I've always just used class variables ( @variable) since they are "global" in a module's scope.

                      AN @@variable is a class (or module) variable.

                      AN @variable is an instance variable. Yes it has global scope within the module, because there is (and can only be,) only one instance of the module.

                      I use both. @@ var for things you might otherwise use a global var for. (Settings and the like.)
                      And then I use @ vars for values that change a lot, but need to be available to all methods.

                      The big difference comes when it's a Mixin module. @ vars can be mixed into the target class or module. Not sure about the class vars.

                      I'm not here much anymore.

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

                        And since a toolbar reference is not going to change during the session, I prefer to use an @@var.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          driven
                          last edited by

                          hi
                          I'm re-jigging my plugins on_off ruby that's part of a larger toolset and I split of the SU auto-reload as a separate button.
                          This lets me make a few choices, then reload SU.

                          On using I thought, 'what if I change my mind', so I only show the current state button to start then turn on it's counterpart when it runs.
                          because I can't remove the first button, I turn it's command to nil, and have a rescue smart alex puts.
                          so you only ever get two buttons and they only switch on first click.

                          is there a better way?

                          @rtb = UI;;Toolbar.new("mac Dev Tools")
                          @path = Sketchup.find_support_file("Tools/on_off") #if your ruby's are OFF this still shows up
                          #----------------------------------------------------------------------------
                          roncmd = nil
                          roffcmd = nil
                          roncmd = UI;;Command.new("rbON") {Sketchup.plugins_disabled = false;
                          roncmd = nil
                          begin
                          @rtb.add_item(roffcmd)
                          rescue
                          puts "I'm one shot per session"
                          end
                           }
                          roffcmd = UI;;Command.new("rbOFF") {Sketchup.plugins_disabled = true;
                          roffcmd = nil
                          begin
                          @rtb.add_item(roncmd)
                          rescue
                          puts "I'm one shot per session"
                          end
                           }
                          # button image paths
                          onicon=(@path + "/images/on.png")
                          officon=(@path + "/images/off.png")
                          
                          roncmd.large_icon = roncmd.small_icon = onicon
                          roffcmd.large_icon = roffcmd.small_icon = officon
                          
                          roncmd.tooltip  = %q(Plugins will be "ON" at next StartUp)
                          roffcmd.tooltip = %q(Plugins will be "OFF" at next StartUp)
                          
                          if !Sketchup.plugins_disabled? === true
                          @rtb.add_item(roffcmd);
                          else
                          @rtb.add_item(roncmd);
                          end #if
                          
                          #----------------------------------------------------------------------------
                          
                          

                          can toolbars buttons be disabled?
                          you need an image folderif you want to test

                          learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                            @driven said:

                            can toolbars buttons be disabled?

                            http://www.sketchup.com/intl/en/developer/docs/ourdoc/menu#set_validation_proc

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

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

                              And unfortunately .. currently we cannot change via the API, the button image that a UI::Command instance is associated with, although doing so is and has long been, a basic feature of Windows Microsoft Foundation Classes (MFC) UI programming. (So we could do it with system calls, using Win32API, etc.)

                              I do believe this is or has been logged as an API feature request.

                              So for now, you are limited to graying them out.

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                driven
                                last edited by

                                TT + Dan,

                                I can't seem to get that to work on a mac.
                                do I need to create a menu item as well, grey it out, and the button follows?
                                Error: #<NoMethodError: undefined methodset_validation_proc' for #UI::Toolbar:0x113cb6ec>`
                                I have a menu entry for the 'master' toolbar, but don't really want/need lots of submenu items.
                                john

                                learn from the mistakes of others, you may not live long enough to make them all yourself...

                                1 Reply Last reply Reply Quote 0
                                • D Offline
                                  driven
                                  last edited by

                                  @dan rathbun said:

                                  (So we could do it with system calls, using Win32API, etc.)

                                  I have an applescript 'somewhere' that tracks the toolbar's window position then positions a replacement window in the exact spot, can't remember why I stopped pursuing that approach, Maybe I switched to a webDialog for that one... I'll dig it up
                                  john

                                  learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                                    @John: set_validation_proc is an instance method of your UI::Command class object (which can be assigned to BOTH a menu item, AND a toolbar button, at the same time, or only one or the other, as you desire.)

                                    If you are not using UI::Command objects for menus (some don't,) then set_validation_proc is an instance method of the submenu object ( Sketchup::Menu class,) that is the parent of the menu item.

                                    For a menu NOT using a UI::Command:

                                    @item = @submenu.add_item("My Task") { do_my_task() }
                                    @submenu.set_validation_proc(@item) {
                                      @task_allowed ? MF_ENABLED ; MF_GRAYED
                                    }
                                    

                                    For a UI::Command, that can be used for menu item AND/OR toolbar button:

                                    @my_task_cmd = UI;;Command("My Task") { do_my_task() }
                                    @my_task_cmd.set_validation_proc {
                                      @task_allowed ? MF_ENABLED ; MF_GRAYED
                                    }
                                    @submenu.add_item @my_task_cmd
                                    @toolbar.add_item @my_task_cmd
                                    

                                    Notice how one of the calls to set_validation_proc has an argument (a menu item,) and the other (when used with a UI::Command,) does not.

                                    πŸ’­

                                    I'm not here much anymore.

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

                                      @driven said:

                                      @dan rathbun said:

                                      (So we could do it with system calls, using Win32API, etc.)

                                      I have an applescript 'somewhere' that tracks the toolbar's window position then positions a replacement window in the exact spot, can't remember why I stopped pursuing that approach, Maybe I switched to a webDialog for that one... I'll dig it up

                                      Because it's an ugly Hack? πŸ˜›

                                      Because it creates too many entries in the View > Toolbar menu ?

                                      Because it clutters the plist with too many toolbar entries ? (This current is a big issue on Windows as toolbar entries go into the Registry.. and slows SU loading way down the more there are!)

                                      I'm not here much anymore.

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

                                        @driven said:

                                        TT + Dan,

                                        I can't seem to get that to work on a mac.
                                        do I need to create a menu item as well, grey it out, and the button follows?
                                        Error: #<NoMethodError: undefined methodset_validation_proc' for #UI::Toolbar:0x113cb6ec>`
                                        I have a menu entry for the 'master' toolbar, but don't really want/need lots of submenu items.
                                        john

                                        Sorry, wrong link.
                                        http://www.sketchup.com/intl/en/developer/docs/ourdoc/command#set_validation_proc

                                        Use it on the Command object.

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

                                        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