sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Function: toggle toolbar

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 2 Posters 637 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.
    • M Offline
      Malkomitch
      last edited by

      Hello there

      For the project i'm coding on these days, i need to create a command, on a toolbar, which toggle another toolbar.
      The method get_last_state from the class Toolbar looks convenient for that but i noticed a strange behaviour.

      Here is my code for defining my toolbar and the function that toggle the other toolbars.

      
      #here is the function for toggling my toolbar
      def toggle(toolbar)
         toolbar.show if toolbar.get_last_state == -1
         toolbar.show if toolbar.get_last_state == 0
         toolbar.hide if toolbar.get_last_state == 1
      end
              
      #and then, the block defining my toolbars
      
      main_tb= UI;;Toolbar.new("main toolbar")
      	
      cmd= UI;;Command.new("Toggle the second toolbar"){toggle(second_tb)}
      cmd.large_icon = cmd.small_icon = File.join(path_to, "maintb.png")
      cmd.tooltip = cmd.status_bar_text= "Toggle the second toolbar"
      main_tb.add_item cmd
      main_tb.show
      
      main_tb= UI;;Toolbar.new("my toolbar")
      	
      
      second_tb= UI;;Toolbar.new("second toolbar")
      cmd= UI;;Command.new("hello"){UI.Messagebox("hello")}
      cmd.large_icon = cmd.small_icon = File.join(path_to, "secondtb.png")
      cmd.tooltip = cmd.status_bar_text= "hello"
      second_tb.add_item cmd
              
      
      
      

      But this code works for showing, not for hiding...
      hu??

      so i checked manually the method get_last_state directly in Sketchup, using the ruby console
      I noticed that the value returned by get_last_state never change, whatever i do with show and hide

      
      tb= UI;;Toolbar.new("my toolbar")
      #<UI;;Toolbar;0x4b22d08>
      cmd= UI;;Command.new("my cmd"){UI.Messagebox("hello")}
      #<UI;;Command;0x4b22ae0>
      tb.add_item cmd
      #<UI;;Toolbar;0x4b22d08>
      tb.get_last_state
      -1
      tb.show
      nil
      tb.get_last_state
      -1
      tb.hide
      nil
      tb.get_last_state
      -1
      

      is there a problem with this method?
      did i miss something?

      thank you for your time

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

        You could try using toolbar.visible? instead. That gave accurate results for me when I tested it manually.

        Chris

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

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

          tb= UI;;Toolbar.new("my toolbar")
          cmd= UI;;Command.new("my cmd"){UI.Messagebox("hello")}
          tb.add_item cmd
          if tb.visible?
           tb.hide
          else
           tb.show
          end
          
          

          That works for me. I'm running it in the webconsole by Jim (thanks again Jim) which is much more useful than the ruby console for little snippets of code.

          When I put that into the console, it all works swimmingly well. Toolbar on and off 😄

          Chris

          Edit: I like this idea. It gives me ideas. I might use something like this in future scripts.

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

          1 Reply Last reply Reply Quote 0
          • M Offline
            Malkomitch
            last edited by

            Thank you Chris.
            I'll check that when i'll get back to work next monday.

            it's such a fast answer to my very first post here.
            This forum looks nice for sharing knowledge and ideas !

            1 Reply Last reply Reply Quote 0
            • M Offline
              Malkomitch
              last edited by

              It works!

              Thank you again!

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

                Woohoo! That might be my first correct response in this forum 😄 I'm glad it helped,

                Chris

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

                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