6 Replies Latest reply on Mar 21, 2019 7:12 AM by peter_festesen

    How to add a "Custom" Button-Toolbar (not Button itself, but a new Toolbar)

    juergen.hinterleitner

      Hi,

      I'm able to add new popup menues and so on.

      Also I'm able to add user custom Buttons, but only to existing Button-Toolbars!

       

      like:

      Set Button1 = CommandBars("Standard").Add(cmdControlButton,,,-1)

      here you see my example user button "Readme Datei" - but in the "Standard" Toolbar! ...

      ButtonBar1.jpg

      ...how to create with Automation a new own Button Toolbar?

      (for where I can add my Custom Buttons)

        • 1. Re: How to add a "Custom" Button-Toolbar (not Button itself, but a new Toolbar)
          peter_festesen

          Hi Jürgen

          I did something like this for a customer a looong time ago, but it seems to work even with VX.2.5.
          The desire was to have a custom toolbar (called 'Quickview' where they could switch on of stuff, but as you will see, the code is quite generic (Button is custom toolbar calls a vbs script):

          In the code below, a Env. Variable 'CustUwPath' is used, it holds the bitmaps for the buttons and the vbs scripts to be called.

           

          'Build and Initialize QuickView Toolbar and buttons

          Set CustomBars = Application.Gui.CommandBars

          Set CustomBar = CustomBars.Create(1, "QuickView")

          'Plane Data button

          Set CustomIcon = CustomBar.Controls.Add(cmdControlButton,,,-1)

          CustomIcon.TooltipText = "Plane Data"

          CustomIcon.BitmapFile = CustUwpath & "\QV\PD_On.bmp"

          CustomIcon.OnAction = "Run " & CustUwpath & "\QV\PlaneDataOnOff.vbs"

           

           

          'Active Layer Only button

          Set CustomIcon = CustomBar.Controls.Add(cmdControlButton,,,-1)

          CustomIcon.TooltipText = "ActiveLayer"

          CustomIcon.BitmapFile = CustUwpath & "\QV\AL_On.bmp"

          CustomIcon.OnAction = "run " & CustUwpath & "\QV\ActiveLayerOnlyOnOff.vbs"

           

           

          'Selected Only button

          Set CustomIcon = CustomBar.Controls.Add(cmdControlButton,,,-1)

          CustomIcon.TooltipText = "Selected Only"

          CustomIcon.BitmapFile = CustUwpath & "\QV\SO_On.bmp"

          CustomIcon.OnAction = "run " & CustUwpath & "\QV\SelectedOnlyOnOff.vbs"

           

          ' Add your own

          'Set CustomIcon = CustomBar.Controls.Add(cmdControlButton,,,-1)

          ' CustomIcon.TooltipText = "Selected Only"

          ' CustomIcon.BitmapFile = CustUwpath & "\QV\My_Own.bmp"

          ' CustomIcon.OnAction = "run " & CustUwpath & "\QV\MyOwnOnOff.vbs"

          '

           

          Have fun !

           

          /Peter

          1 of 1 people found this helpful
          • 2. Re: How to add a "Custom" Button-Toolbar (not Button itself, but a new Toolbar)
            phiet

            Hi Peter,

            Your code is for layout, while from the picture posted, I beleive he is looking for Designer.

            but I designer, they have stripped down commandbars object and dont allow any other command then usually work in layout. Another inconsistency from Mentor.

             

            the only thing I can achieve is cycle through their different existing commandbars to see that they use othe menu bar for in context menu ....

            • 3. Re: How to add a "Custom" Button-Toolbar (not Button itself, but a new Toolbar)
              peter_festesen

              Good catch with this being for Designer, phiet !

               

              For Designer I found this (old) thread : DxDesinger 7.9.2: Adding a new "customer" toolbar using automation

               

              It talks about an 'undocumented' CreateToolbar method....

              • 4. Re: How to add a "Custom" Button-Toolbar (not Button itself, but a new Toolbar)
                phiet

                Thanks,

                Cool, the example shown in the User2User2008 presentation works.

                if CreateToolbar ("MyToolbar") then

                   set tb= application.CommandBars("MyToolbar")

                   set btn = tb.COntrols.Add  

                end if

                I wonder why they don't document this ...is it a lack in documentation or ..they intentionally skip this ?

                • 5. Re: How to add a "Custom" Button-Toolbar (not Button itself, but a new Toolbar)
                  juergen.hinterleitner

                  I give that up for now. Because of the following problems:

                   

                  Yes, I also found yesterday (anywhere inside the aatk-tools) the command "CommandBars.CreateToolbar("xxx")" - BUT ...

                  This command create really a new Toolbar. So, but now...

                  • you cannot change the position for this toolbar.
                  • this toolbar does later not appear in the "Customize Toolbars"- window. (so it seems to be a pure temporary Toolbar)
                  • and this temporary created Toolbar, you cannot find in the Automation CommandBars -Collection
                    • of course ... you get the Object when you create it, and you can add your Buttons, BUT ...
                  • when you have done this, the User moves the Toolbar to his/her prefered Position!
                  • but, when you close and reopen the Designer later, the Menu was gone (dissolved in air).
                    • so the Script will add the Toolbar again ... at the "not User-Position".

                   

                  further... but when you create the Toolbar with the "Customize Toolbars"- window, then the Toolbar is NOT Temporary, and Mentor saves the Position and Toolbar on exit! --> that's a big difference to the Automation command.

                   

                  more further... when you create the Toolbar with the regular "Customize Toolbars"- window... is this Toolbar not temporary - BUT ...

                  this Toolbar you can also NOT find in the CommandBars Collection...

                   

                  So - I forget this for now. Had lost to much time with this senseless action.

                  • 6. Re: How to add a "Custom" Button-Toolbar (not Button itself, but a new Toolbar)
                    peter_festesen

                    Yes, I found that to work as well....my modified code from the Xpedition example (I know the buttons don't make sense, but I see that even the bitmap stuff works) - see below. It looks as if this is intentional, since the CreateToolbar method is hidden, meaning it's unsupported...

                     

                     

                     

                    If CreateToolbar("QuickView") Then

                    Set CustomBar = Application.CommandBars("QuickView")

                     

                    'Plane Data button

                    Set CustomIcon = CustomBar.Controls.Add(cmdControlButton,,,-1)

                    CustomIcon.TooltipText = "Plane Data"

                    CustomIcon.BitmapFile = CustUwpath & "\QV\PD_On.bmp"

                    CustomIcon.OnAction = "Run " & CustUwpath & "\QV\PlaneDataOnOff.vbs"

                     

                     

                    'Active Layer Only button

                    Set CustomIcon = CustomBar.Controls.Add(cmdControlButton,,,-1)

                    CustomIcon.TooltipText = "ActiveLayer"

                    CustomIcon.BitmapFile = CustUwpath & "\QV\AL_On.bmp"

                    CustomIcon.OnAction = "run " & CustUwpath & "\QV\ActiveLayerOnlyOnOff.vbs"

                     

                     

                    'Selected Only button

                    Set CustomIcon = CustomBar.Controls.Add(cmdControlButton,,,-1)

                    CustomIcon.TooltipText = "Selected Only"

                    CustomIcon.BitmapFile = CustUwpath & "\QV\SO_On.bmp"

                    CustomIcon.OnAction = "run " & CustUwpath & "\QV\SelectedOnlyOnOff.vbs"

                     

                    ' Add your own

                    'Set CustomIcon = CustomBar.Controls.Add(cmdControlButton,,,-1)

                    ' CustomIcon.TooltipText = "Selected Only"

                    ' CustomIcon.BitmapFile = CustUwpath & "\QV\My_Own.bmp"

                    ' CustomIcon.OnAction = "run " & CustUwpath & "\QV\MyOwnOnOff.vbs"

                     

                     

                    End If