Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Create small sized buttons in the panel

swapnil_lokam
Enthusiast

Create small sized buttons in the panel

swapnil_lokam
Enthusiast
Enthusiast

Hi,

I am working on a project and I'm running out of space for creating buttons in a custom tab. I want to create buttons in a dropdown so that after clicking the dropdown, the buttons become visible.

Please refer to the attached screenshot for more clarity.

swapnil_lokam_0-1722432649369.png

 

swapnil_lokam_2-1722432739028.png

I want to create similar buttons that are highlighted in the red block in the attached snap which should be visible after clicking the draw dropdown 

A sample code would a great help 
Thank you 

0 Likes
Reply
430 Views
4 Replies
Replies (4)

Ed__Jobe
Mentor
Mentor

Just look at the CUI editor and see how the Draw Panel is created. See the image below and note the types of controls that are used. There's a sub-panel, drop-down and Slide-out.

acad cui panel.png

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes

swapnil_lokam
Enthusiast
Enthusiast

I am using this sample code 


 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Windows;
using System;

[assembly: CommandClass(typeof(MyRibbonApp.MyCommands))]

namespace MyRibbonApp
{
   public class MyCommands : IExtensionApplication
   {
      public void Initialize()
      {
         CreateRibbonPanel();
      }

      public void Terminate()
      {
      }

      private void CreateRibbonPanel()
      {
         RibbonControl ribbonControl = ComponentManager.Ribbon;
         if (ribbonControl != null)
         {
            RibbonTab ribbonTab = ribbonControl.FindTab("CustomTab");
            if (ribbonTab == null)
            {
               ribbonTab = new RibbonTab
               {
                  Title = "Custom Tab",
                  Id = "CustomTab"
               };
               ribbonControl.Tabs.Add(ribbonTab);
            }

            RibbonPanelSource panelSource = new RibbonPanelSource
            {
               Title = "Custom Panel"
            };

            RibbonPanel ribbonPanel = new RibbonPanel
            {
               Source = panelSource
            };

            ribbonTab.Panels.Add(ribbonPanel);

            // Create the dropdown button named "Earthing Layout"
            RibbonSplitButton earthingLayoutDropdown = new RibbonSplitButton
            {
               Text = "Earthing Layout",
               ShowText = true
            };

            // Create individual buttons
            RibbonButton verticalStripButton = new RibbonButton
            {
               Text = "Vertical Strip",
               CommandParameter = "VerticalStripCommand",
               CommandHandler = new RibbonCommandHandler()
            };

            RibbonButton horizontalStripButton = new RibbonButton
            {
               Text = "Horizontal Strip",
               CommandParameter = "HorizontalStripCommand",
               CommandHandler = new RibbonCommandHandler()
            };

            // Add buttons to the dropdown
            earthingLayoutDropdown.Items.Add(verticalStripButton);
            earthingLayoutDropdown.Items.Add(horizontalStripButton);

            // Add the dropdown to the panel
            panelSource.Items.Add(earthingLayoutDropdown);
         }
      }
   }

   public class RibbonCommandHandler : System.Windows.Input.ICommand
   {
      public event EventHandler CanExecuteChanged;

      public bool CanExecute(object parameter)
      {
         return true;
      }

      public void Execute(object parameter)
      {
         string command = parameter as string;
         if (!string.IsNullOrEmpty(command))
         {
            Application.DocumentManager.MdiActiveDocument.SendStringToExecute(command + " ", true, false, true);
         }
      }
   }
}

 


I want to create a main button named "Earthing" and then this button should contain the dropdown and this dropdown should contain two more buttons name "Vertical strip" and "Horizontal strip"

but instead of "Earthing" button, there is again a "Vertical strip" button 
What modifications should I make in attached code

refer the attached snap for better clarity

swapnil_lokam_0-1722519790006.png

Thanks in advance!!!

 

0 Likes

Ed__Jobe
Mentor
Mentor

The picture shows what  you created, but is that what you want? Or are you still trying to create what is in the first post?

 

In lines 72 and 73, you simply add both vertical and horizontal controls to the RibbonSplitButton. In post 2, I showed you that the Home_Draw menu uses a SLIDEOUT, followed by two rows. In .NET this is the Autodesk.Windows.RibbonPanelBreak class. Add two rows to this container and then add buttons to each row container.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes

swapnil_lokam
Enthusiast
Enthusiast

Sorry for the misunderstanding 
I am still trying to create that I mentioned in the first post 

A sample code related to the first post would be of a great help 

Thankyou 

0 Likes