.NET

Reply
Valued Contributor
SMachado
Posts: 98
Registered: ‎11-19-2009
Message 1 of 25 (13,885 Views)

Create custom ribbon tab and buttons for Autocad mechanical 2011?

13885 Views, 24 Replies
11-23-2010 10:42 AM

Hi everyone!

 

How do i create a ribbon tab and button for my application, can anyone give a sample code?

 

How do i interact the button click with my application?

 

Thanks.

Active Member
Mikanikal
Posts: 6
Registered: ‎10-11-2010
Message 2 of 25 (13,846 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

11-24-2010 03:47 PM in reply to: SMachado
Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 3 of 25 (13,808 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

11-25-2010 07:36 AM in reply to: SMachado

Hi there,

 

I've created a sample om how to create a ribbon pannels buttons, splitbuttons, and ribboncombos + event handler.

The images are using the project resources. Two acadcommandline functions MyRibbon to create te ribbon

and MyribbonComboTest to add a button to a ribboncombo control.

 

It should look somthing like this:

 

2133i7D85D40B5859E04A

 

Here  is the code:

 

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Media.Imaging;
using System.Reflection;

using Autodesk.Windows;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace RibbonSample
{
    public class Ribbon
    {
        public RibbonCombo pan1ribcombo1 = new RibbonCombo();
        public RibbonCombo pan3ribcombo = new RibbonCombo();
        

        public Ribbon()
        {
            pan3ribcombo.CurrentChanged +=new EventHandler<RibbonPropertyChangedEventArgs>(pan3ribcombo_CurrentChanged);
        }

        private void pan3ribcombo_CurrentChanged(object sender, RibbonPropertyChangedEventArgs e)
        {
            RibbonButton but = pan3ribcombo.Current as RibbonButton;
            acadApp.ShowAlertDialog(but.Text);
        }
        
        [CommandMethod("MyRibbonCombotest")]
        public void RibbonSplitButtontest()
        {
            RibbonButton commandlinebutton = new RibbonButton();
            commandlinebutton.Text = "Newly Added Button with command: MyRibbonTestCombo";
            commandlinebutton.ShowText = true;
            commandlinebutton.ShowImage = true;
            commandlinebutton.Image = Images.getBitmap(Properties.Resources.Small);
            commandlinebutton.LargeImage = Images.getBitmap(Properties.Resources.large);
            commandlinebutton.CommandHandler = new RibbonCommandHandler();
            pan1ribcombo1.Items.Add(commandlinebutton);
            pan1ribcombo1.Current = commandlinebutton;
        }

        [CommandMethod("MyRibbon")]
        public void MyRibbon()
        {
            Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;
            RibbonTab Tab = new RibbonTab();
            Tab.Title = "Autodesk .NET forum Ribbon Sample";
            Tab.Id = "RibbonSample_TAB_ID";

            ribbonControl.Tabs.Add(Tab);

            // create Ribbon panels
            Autodesk.Windows.RibbonPanelSource panel1Panel = new RibbonPanelSource();
            panel1Panel.Title = "Panel1";
            RibbonPanel Panel1 = new RibbonPanel();
            Panel1.Source = panel1Panel;
            Tab.Panels.Add(Panel1);

            RibbonButton pan1button1 = new RibbonButton();
            pan1button1.Text = "Button1";
            pan1button1.ShowText = true;
            pan1button1.ShowImage = true;
            pan1button1.Image = Images.getBitmap(Properties.Resources.Small);
            pan1button1.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan1button1.Orientation = System.Windows.Controls.Orientation.Vertical;
            pan1button1.Size = RibbonItemSize.Large;
            pan1button1.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan1button2 = new RibbonButton();
            pan1button2.Text = "Button2";
            pan1button2.ShowText = true;
            pan1button2.ShowImage = true;
            pan1button2.Image = Images.getBitmap(Properties.Resources.Small);
            pan1button2.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan1button2.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan1button3 = new RibbonButton();
            pan1button3.Text = "Button3";
            pan1button3.ShowText = true;
            pan1button3.ShowImage = true;
            pan1button3.Image = Images.getBitmap(Properties.Resources.Small);
            pan1button3.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan1button3.CommandHandler = new RibbonCommandHandler();

            // Set te propperties for the RibbonCombo
            // Te ribboncombo control does not listen to the command handler
            pan1ribcombo1.Text = " ";
            pan1ribcombo1.ShowText = true;
            pan1ribcombo1.MinWidth = 150;

            RibbonRowPanel pan1row1 = new RibbonRowPanel();
            pan1row1.Items.Add(pan1button2);
            pan1row1.Items.Add(new RibbonRowBreak());
            pan1row1.Items.Add(pan1button3);
            pan1row1.Items.Add(new RibbonRowBreak());
            pan1row1.Items.Add(pan1ribcombo1);

            panel1Panel.Items.Add(pan1button1);
            panel1Panel.Items.Add(new RibbonSeparator());
            panel1Panel.Items.Add(pan1row1);

            RibbonPanelSource panel2Panel = new RibbonPanelSource();
            panel2Panel.Title = "Panel2";
            RibbonPanel panel2 = new RibbonPanel();
            panel2.Source = panel2Panel;
            Tab.Panels.Add(panel2);

            RibbonSplitButton pan2splitButton = new RibbonSplitButton();
            pan2splitButton.Text = "SplitButton"; //Required not to crash AutoCAD when using cmd locators 
            pan2splitButton.CommandHandler = new RibbonCommandHandler();
            pan2splitButton.ShowText = true;
            pan2splitButton.ShowImage = true;
            pan2splitButton.Image = Images.getBitmap(Properties.Resources.Small);
            pan2splitButton.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan2splitButton.IsSplit = true;
            pan2splitButton.Size = RibbonItemSize.Large;

            RibbonButton pan2button1 = new RibbonButton();
            pan2button1.Text = "Button1";
            pan2button1.ShowText = true;
            pan2button1.ShowImage = true;
            pan2button1.Image = Images.getBitmap(Properties.Resources.Small);
            pan2button1.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan2button1.Size = RibbonItemSize.Large;
            pan2button1.Orientation = System.Windows.Controls.Orientation.Vertical;
            pan2button1.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan2button2 = new RibbonButton();
            pan2button2.Text = "Button2";
            pan2button2.ShowText = true;
            pan2button2.ShowImage = true;
            pan2button2.Image = Images.getBitmap(Properties.Resources.Small);
            pan2button2.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan2button2.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan2button3 = new RibbonButton();
            pan2button3.Text = "Button3";
            pan2button3.ShowText = true;
            pan2button3.ShowImage = true;
            pan2button3.Image = Images.getBitmap(Properties.Resources.Small);
            pan2button3.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan2button3.CommandHandler = new RibbonCommandHandler();

            pan2splitButton.Items.Add(pan2button1);
            pan2splitButton.Items.Add(pan2button2);

            RibbonRowPanel pan2row1 = new RibbonRowPanel();
            pan2row1.Items.Add(pan2button2);
            pan2row1.Items.Add(new RibbonRowBreak());
            pan2row1.Items.Add(pan2button3);
            pan2row1.Items.Add(new RibbonRowBreak());
            pan2row1.Items.Add(new RibbonCombo());

            panel2Panel.Items.Add(pan2splitButton);
            panel2Panel.Items.Add(pan2row1);

            RibbonPanelSource panel3Panel = new RibbonPanelSource();
            panel3Panel.Title = "Panel3";
            RibbonPanel panel3 = new RibbonPanel();
            panel3.Source = panel3Panel;
            Tab.Panels.Add(panel3);

            RibbonButton pan3button1 = new RibbonButton();
            pan3button1.Text = "Button1";
            pan3button1.ShowText = true;
            pan3button1.ShowImage = true;
            pan3button1.Image = Images.getBitmap(Properties.Resources.Small);
            pan3button1.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan3button1.Size = RibbonItemSize.Large;
            pan3button1.Orientation = System.Windows.Controls.Orientation.Vertical;
            pan3button1.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan3button2 = new RibbonButton();
            pan3button2.Text = "Button2";
            pan3button2.ShowText = true;
            pan3button2.ShowImage = true;
            pan3button2.Image = Images.getBitmap(Properties.Resources.Small);
            pan3button2.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan3button2.Size = RibbonItemSize.Large;
            pan3button2.Orientation = System.Windows.Controls.Orientation.Vertical;
            pan3button2.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan3button3 = new RibbonButton();
            pan3button3.Text = "Button3";
            pan3button3.ShowText = true;
            pan3button3.ShowImage = true;
            pan3button3.Image = Images.getBitmap(Properties.Resources.Small);
            pan3button3.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan3button3.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan3button4 = new RibbonButton();
            pan3button4.Text = "Button4";
            pan3button4.ShowText = true;
            pan3button4.ShowImage = true;
            pan3button4.Image = Images.getBitmap(Properties.Resources.Small);
            pan3button4.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan3button4.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan3button5 = new RibbonButton();
            pan3button5.Text = "Button5";
            pan3button5.ShowText = true;
            pan3button5.ShowImage = true;
            pan3button5.Image = Images.getBitmap(Properties.Resources.Small);
            pan3button5.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan3button5.CommandHandler = new RibbonCommandHandler();

            RibbonRowPanel pan3row1 = new RibbonRowPanel();
            pan3row1.Items.Add(pan3button3);
            pan3row1.Items.Add(new RibbonRowBreak());
            pan3row1.Items.Add(pan3button4);
            pan3row1.Items.Add(new RibbonRowBreak());
            pan3row1.Items.Add(pan3button5);

            panel3Panel.Items.Add(pan3button1);
            panel3Panel.Items.Add(pan3row1);

            RibbonPanelSource pan4Panel = new RibbonPanelSource();
            pan4Panel.Title = "Panel4";
            RibbonPanel Panel4 = new RibbonPanel();
            Panel4.Source = pan4Panel;
            Tab.Panels.Add(Panel4);

            RibbonButton pan4button1 = new RibbonButton();
            pan4button1.Text = "Button1";
            pan4button1.ShowText = true;
            pan4button1.ShowImage = true;
            pan4button1.Image = Images.getBitmap(Properties.Resources.Small);
            pan4button1.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan4button1.Size = RibbonItemSize.Large;
            pan4button1.Orientation = System.Windows.Controls.Orientation.Vertical;
            pan4button1.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan4button2 = new RibbonButton();
            pan4button2.Text = "Button2";
            pan4button2.ShowText = true;
            pan4button2.ShowImage = true;
            pan4button2.Image = Images.getBitmap(Properties.Resources.Small);
            pan4button2.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan4button2.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan4button3 = new RibbonButton();
            pan4button3.Text = "Button3";
            pan4button3.ShowText = true;
            pan4button3.ShowImage = true;
            pan4button3.Image = Images.getBitmap(Properties.Resources.Small);
            pan4button3.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan4button3.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan4button4 = new RibbonButton();
            pan4button4.Text = "Button4";
            pan4button4.ShowText = true;
            pan4button4.ShowImage = true;
            pan4button4.Image = Images.getBitmap(Properties.Resources.Small);
            pan4button4.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan4button4.Size = RibbonItemSize.Large;
            pan4button4.Orientation = System.Windows.Controls.Orientation.Vertical;
            pan4button4.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan4ribcombobutton1 = new RibbonButton();
            pan4ribcombobutton1.Text = "Button1";
            pan4ribcombobutton1.ShowText = true;
            pan4ribcombobutton1.ShowImage = true;
            pan4ribcombobutton1.Image = Images.getBitmap(Properties.Resources.Small);
            pan4ribcombobutton1.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan4ribcombobutton1.CommandHandler = new RibbonCommandHandler();

            RibbonButton pan4ribcombobutton2 = new RibbonButton();
            pan4ribcombobutton2.Text = "Button2";
            pan4ribcombobutton2.ShowText = true;
            pan4ribcombobutton2.ShowImage = true;
            pan4ribcombobutton2.Image = Images.getBitmap(Properties.Resources.Small);
            pan4ribcombobutton2.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan4ribcombobutton2.CommandHandler = new RibbonCommandHandler();

            pan3ribcombo.Width = 150;
            pan3ribcombo.Items.Add(pan4ribcombobutton1);
            pan3ribcombo.Items.Add(pan4ribcombobutton2);
            pan3ribcombo.Current = pan4ribcombobutton1;

            RibbonRowPanel vvorow1 = new RibbonRowPanel();
            vvorow1.Items.Add(pan4button2);
            vvorow1.Items.Add(new RibbonRowBreak());
            vvorow1.Items.Add(pan4button3);
            vvorow1.Items.Add(new RibbonRowBreak());
            vvorow1.Items.Add(pan3ribcombo);

            pan4Panel.Items.Add(pan4button1);
            pan4Panel.Items.Add(vvorow1);
            pan4Panel.Items.Add(new RibbonSeparator());
            pan4Panel.Items.Add(pan4button4);
            
            Tab.IsActive = true;
        }

        public class RibbonCommandHandler : System.Windows.Input.ICommand
        {
            public bool CanExecute(object parameter)
            {
                return true;
            }

            public event EventHandler CanExecuteChanged;

            public void Execute(object parameter)
            {
                Document doc = acadApp.DocumentManager.MdiActiveDocument;

                if (parameter is RibbonButton)
                {
                    RibbonButton button = parameter as RibbonButton;
                    doc.Editor.WriteMessage("\nRibbonButton Executed: " + button.Text + "\n");
                }
            }
        }

        public class Images
        {
            public static BitmapImage getBitmap(Bitmap image)
            {
                MemoryStream stream = new MemoryStream();
                image.Save(stream, ImageFormat.Png);
                BitmapImage bmp = new BitmapImage();
                bmp.BeginInit();
                bmp.StreamSource = stream;
                bmp.EndInit();

                return bmp;
            }
        }
    }
}

 Project file is attached. It's a visual Studio 2010 Solution.

 

Kind regards,

 

Irvin

The Netherlands,

Valued Contributor
SMachado
Posts: 98
Registered: ‎11-19-2009
Message 4 of 25 (13,802 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

11-25-2010 08:36 AM in reply to: Irvin

Hi Irvin!

 

Thanks a lot for your help, i have another question that you might know the answer.

 

The question is when i create a tollbar for the mechanical classic worspace, how do i put the toolbar in the menu bar of the Autocad workspace?

 

I'm using the helloworld sample from the objectarx 2011 to create the toolbars.

 

Thanks once again.

Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 5 of 25 (13,793 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

11-25-2010 11:12 AM in reply to: SMachado

Try to download the objectarx sdk for autocad 2009 in the sample folder there is an folder dotnet wich has the cui sample in it. This sample creates a pop menu toolbar and a workspace.

 

Ik think it has al your needs.

 

Kind regards,

 

Irvin

Valued Contributor
SMachado
Posts: 98
Registered: ‎11-19-2009
Message 6 of 25 (13,717 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

11-30-2010 03:58 AM in reply to: SMachado

Hi everyone!

 

i have  converted the above code from c# to vb.net, and there is some erros in the following lines:

 

1) Imports

acadApp = Autodesk.AutoCAD.ApplicationServices.Application

Error 1 Imports alias 'acadApp' conflicts with 'Structure AcadApp' declared in the root namespace. 

 

2) pan3ribcombo.CurrentChanged += New EventHandler(Of RibbonPropertyChangedEventArgs)(AddressOf pan3ribcombo_CurrentChanged)

Error 2 'Public Event CurrentChanged(sender As Object, e As Autodesk.Windows.RibbonPropertyChangedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

What do i have to do to the code work in vb.net????

 thanks.

 

 

here is the full convert  code from C# to vb.net:

 

Imports Autodesk.Windows
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports System.Drawing
Imports System.Drawing.Imaging

Namespace RibbonSample

    Public Class Ribbon
        Public pan1ribcombo1 As New RibbonCombo()
        Public pan3ribcombo As New RibbonCombo()

        Public Sub New()
            pan3ribcombo.CurrentChanged += New EventHandler(Of RibbonPropertyChangedEventArgs)(AddressOf pan3ribcombo_CurrentChanged)
        End Sub

        Private Sub pan3ribcombo_CurrentChanged(ByVal sender As Object, ByVal e As RibbonPropertyChangedEventArgs)
            Dim but As RibbonButton = TryCast(pan3ribcombo.Current, RibbonButton)
            acadApp.ShowAlertDialog(but.Text)
        End Sub

        <CommandMethod("MyRibbonCombotest")> _
        Public Sub RibbonSplitButtontest()
            Dim commandlinebutton As New RibbonButton()
            commandlinebutton.Text = "Newly Added Button with command: MyRibbonTestCombo"
            commandlinebutton.ShowText = True
            commandlinebutton.ShowImage = True
            commandlinebutton.Image = Images.getBitmap(My.Resources.Small)
            commandlinebutton.LargeImage = Images.getBitmap(My.Resources.large)
            commandlinebutton.CommandHandler = New RibbonCommandHandler()
            pan1ribcombo1.Items.Add(commandlinebutton)
            pan1ribcombo1.Current = commandlinebutton
        End Sub

        <CommandMethod("MyRibbon")> _
        Public Sub MyRibbon()
            Dim ribbonControl As Autodesk.Windows.RibbonControl = Autodesk.Windows.ComponentManager.Ribbon
            Dim Tab As New RibbonTab()
            Tab.Title = "Autodesk .NET forum Ribbon Sample"
            Tab.Id = "RibbonSample_TAB_ID"

            ribbonControl.Tabs.Add(Tab)

            ' create Ribbon panels
            Dim panel1Panel As Autodesk.Windows.RibbonPanelSource = New RibbonPanelSource()
            panel1Panel.Title = "Panel1"
            Dim Panel1 As New RibbonPanel()
            Panel1.Source = panel1Panel
            Tab.Panels.Add(Panel1)

            Dim pan1button1 As New RibbonButton()
            pan1button1.Text = "Button1"
            pan1button1.ShowText = True
            pan1button1.ShowImage = True
            pan1button1.Image = Images.getBitmap(My.Resources.Small)
            pan1button1.LargeImage = Images.getBitmap(My.Resources.large)
            pan1button1.Orientation = System.Windows.Controls.Orientation.Vertical
            pan1button1.Size = RibbonItemSize.Large
            pan1button1.CommandHandler = New RibbonCommandHandler()

            Dim pan1button2 As New RibbonButton()
            pan1button2.Text = "Button2"
            pan1button2.ShowText = True
            pan1button2.ShowImage = True
            pan1button2.Image = Images.getBitmap(My.Resources.Small)
            pan1button2.LargeImage = Images.getBitmap(My.Resources.large)
            pan1button2.CommandHandler = New RibbonCommandHandler()

            Dim pan1button3 As New RibbonButton()
            pan1button3.Text = "Button3"
            pan1button3.ShowText = True
            pan1button3.ShowImage = True
            pan1button3.Image = Images.getBitmap(My.Resources.Small)
            pan1button3.LargeImage = Images.getBitmap(My.Resources.large)
            pan1button3.CommandHandler = New RibbonCommandHandler()

            ' Set te propperties for the RibbonCombo
            ' Te ribboncombo control does not listen to the command handler
            pan1ribcombo1.Text = " "
            pan1ribcombo1.ShowText = True
            pan1ribcombo1.MinWidth = 150

            Dim pan1row1 As New RibbonRowPanel()
            pan1row1.Items.Add(pan1button2)
            pan1row1.Items.Add(New RibbonRowBreak())
            pan1row1.Items.Add(pan1button3)
            pan1row1.Items.Add(New RibbonRowBreak())
            pan1row1.Items.Add(pan1ribcombo1)

            panel1Panel.Items.Add(pan1button1)
            panel1Panel.Items.Add(New RibbonSeparator())
            panel1Panel.Items.Add(pan1row1)

            Dim panel2Panel As New RibbonPanelSource()
            panel2Panel.Title = "Panel2"
            Dim panel2 As New RibbonPanel()
            panel2.Source = panel2Panel
            Tab.Panels.Add(panel2)

            Dim pan2splitButton As New RibbonSplitButton()
            pan2splitButton.Text = "SplitButton"
            'Required not to crash AutoCAD when using cmd locators 
            pan2splitButton.CommandHandler = New RibbonCommandHandler()
            pan2splitButton.ShowText = True
            pan2splitButton.ShowImage = True
            pan2splitButton.Image = Images.getBitmap(My.Resources.Small)
            pan2splitButton.LargeImage = Images.getBitmap(My.Resources.large)
            pan2splitButton.IsSplit = True
            pan2splitButton.Size = RibbonItemSize.Large

            Dim pan2button1 As New RibbonButton()
            pan2button1.Text = "Button1"
            pan2button1.ShowText = True
            pan2button1.ShowImage = True
            pan2button1.Image = Images.getBitmap(My.Resources.Small)
            pan2button1.LargeImage = Images.getBitmap(My.Resources.large)
            pan2button1.Size = RibbonItemSize.Large
            pan2button1.Orientation = System.Windows.Controls.Orientation.Vertical
            pan2button1.CommandHandler = New RibbonCommandHandler()

            Dim pan2button2 As New RibbonButton()
            pan2button2.Text = "Button2"
            pan2button2.ShowText = True
            pan2button2.ShowImage = True
            pan2button2.Image = Images.getBitmap(My.Resources.Small)
            pan2button2.LargeImage = Images.getBitmap(My.Resources.large)
            pan2button2.CommandHandler = New RibbonCommandHandler()

            Dim pan2button3 As New RibbonButton()
            pan2button3.Text = "Button3"
            pan2button3.ShowText = True
            pan2button3.ShowImage = True
            pan2button3.Image = Images.getBitmap(My.Resources.Small)
            pan2button3.LargeImage = Images.getBitmap(My.Resources.large)
            pan2button3.CommandHandler = New RibbonCommandHandler()

            pan2splitButton.Items.Add(pan2button1)
            pan2splitButton.Items.Add(pan2button2)

            Dim pan2row1 As New RibbonRowPanel()
            pan2row1.Items.Add(pan2button2)
            pan2row1.Items.Add(New RibbonRowBreak())
            pan2row1.Items.Add(pan2button3)
            pan2row1.Items.Add(New RibbonRowBreak())
            pan2row1.Items.Add(New RibbonCombo())

            panel2Panel.Items.Add(pan2splitButton)
            panel2Panel.Items.Add(pan2row1)

            Dim panel3Panel As New RibbonPanelSource()
            panel3Panel.Title = "Panel3"
            Dim panel3 As New RibbonPanel()
            panel3.Source = panel3Panel
            Tab.Panels.Add(panel3)

            Dim pan3button1 As New RibbonButton()
            pan3button1.Text = "Button1"
            pan3button1.ShowText = True
            pan3button1.ShowImage = True
            pan3button1.Image = Images.getBitmap(My.Resources.Small)
            pan3button1.LargeImage = Images.getBitmap(My.Resources.large)
            pan3button1.Size = RibbonItemSize.Large
            pan3button1.Orientation = System.Windows.Controls.Orientation.Vertical
            pan3button1.CommandHandler = New RibbonCommandHandler()

            Dim pan3button2 As New RibbonButton()
            pan3button2.Text = "Button2"
            pan3button2.ShowText = True
            pan3button2.ShowImage = True
            pan3button2.Image = Images.getBitmap(My.Resources.Small)
            pan3button2.LargeImage = Images.getBitmap(My.Resources.large)
            pan3button2.Size = RibbonItemSize.Large
            pan3button2.Orientation = System.Windows.Controls.Orientation.Vertical
            pan3button2.CommandHandler = New RibbonCommandHandler()

            Dim pan3button3 As New RibbonButton()
            pan3button3.Text = "Button3"
            pan3button3.ShowText = True
            pan3button3.ShowImage = True
            pan3button3.Image = Images.getBitmap(My.Resources.Small)
            pan3button3.LargeImage = Images.getBitmap(My.Resources.large)
            pan3button3.CommandHandler = New RibbonCommandHandler()

            Dim pan3button4 As New RibbonButton()
            pan3button4.Text = "Button4"
            pan3button4.ShowText = True
            pan3button4.ShowImage = True
            pan3button4.Image = Images.getBitmap(My.Resources.Small)
            pan3button4.LargeImage = Images.getBitmap(My.Resources.large)
            pan3button4.CommandHandler = New RibbonCommandHandler()

            Dim pan3button5 As New RibbonButton()
            pan3button5.Text = "Button5"
            pan3button5.ShowText = True
            pan3button5.ShowImage = True
            pan3button5.Image = Images.getBitmap(My.Resources.Small)
            pan3button5.LargeImage = Images.getBitmap(My.Resources.large)
            pan3button5.CommandHandler = New RibbonCommandHandler()

            Dim pan3row1 As New RibbonRowPanel()
            pan3row1.Items.Add(pan3button3)
            pan3row1.Items.Add(New RibbonRowBreak())
            pan3row1.Items.Add(pan3button4)
            pan3row1.Items.Add(New RibbonRowBreak())
            pan3row1.Items.Add(pan3button5)

            panel3Panel.Items.Add(pan3button1)
            panel3Panel.Items.Add(pan3row1)

            Dim pan4Panel As New RibbonPanelSource()
            pan4Panel.Title = "Panel4"
            Dim Panel4 As New RibbonPanel()
            Panel4.Source = pan4Panel
            Tab.Panels.Add(Panel4)

            Dim pan4button1 As New RibbonButton()
            pan4button1.Text = "Button1"
            pan4button1.ShowText = True
            pan4button1.ShowImage = True
            pan4button1.Image = Images.getBitmap(My.Resources.Small)
            pan4button1.LargeImage = Images.getBitmap(My.Resources.large)
            pan4button1.Size = RibbonItemSize.Large
            pan4button1.Orientation = System.Windows.Controls.Orientation.Vertical
            pan4button1.CommandHandler = New RibbonCommandHandler()

            Dim pan4button2 As New RibbonButton()
            pan4button2.Text = "Button2"
            pan4button2.ShowText = True
            pan4button2.ShowImage = True
            pan4button2.Image = Images.getBitmap(My.Resources.Small)
            pan4button2.LargeImage = Images.getBitmap(My.Resources.large)
            pan4button2.CommandHandler = New RibbonCommandHandler()

            Dim pan4button3 As New RibbonButton()
            pan4button3.Text = "Button3"
            pan4button3.ShowText = True
            pan4button3.ShowImage = True
            pan4button3.Image = Images.getBitmap(My.Resources.Small)
            pan4button3.LargeImage = Images.getBitmap(My.Resources.large)
            pan4button3.CommandHandler = New RibbonCommandHandler()

            Dim pan4button4 As New RibbonButton()
            pan4button4.Text = "Button4"
            pan4button4.ShowText = True
            pan4button4.ShowImage = True
            pan4button4.Image = Images.getBitmap(My.Resources.Small)
            pan4button4.LargeImage = Images.getBitmap(My.Resources.large)
            pan4button4.Size = RibbonItemSize.Large
            pan4button4.Orientation = System.Windows.Controls.Orientation.Vertical
            pan4button4.CommandHandler = New RibbonCommandHandler()

            Dim pan4ribcombobutton1 As New RibbonButton()
            pan4ribcombobutton1.Text = "Button1"
            pan4ribcombobutton1.ShowText = True
            pan4ribcombobutton1.ShowImage = True
            pan4ribcombobutton1.Image = Images.getBitmap(My.Resources.Small)
            pan4ribcombobutton1.LargeImage = Images.getBitmap(My.Resources.large)
            pan4ribcombobutton1.CommandHandler = New RibbonCommandHandler()

            Dim pan4ribcombobutton2 As New RibbonButton()
            pan4ribcombobutton2.Text = "Button2"
            pan4ribcombobutton2.ShowText = True
            pan4ribcombobutton2.ShowImage = True
            pan4ribcombobutton2.Image = Images.getBitmap(My.Resources.Small)
            pan4ribcombobutton2.LargeImage = Images.getBitmap(My.Resources.large)
            pan4ribcombobutton2.CommandHandler = New RibbonCommandHandler()

            pan3ribcombo.Width = 150
            pan3ribcombo.Items.Add(pan4ribcombobutton1)
            pan3ribcombo.Items.Add(pan4ribcombobutton2)
            pan3ribcombo.Current = pan4ribcombobutton1

            Dim vvorow1 As New RibbonRowPanel()
            vvorow1.Items.Add(pan4button2)
            vvorow1.Items.Add(New RibbonRowBreak())
            vvorow1.Items.Add(pan4button3)
            vvorow1.Items.Add(New RibbonRowBreak())
            vvorow1.Items.Add(pan3ribcombo)

            pan4Panel.Items.Add(pan4button1)
            pan4Panel.Items.Add(vvorow1)
            pan4Panel.Items.Add(New RibbonSeparator())
            pan4Panel.Items.Add(pan4button4)

            Tab.IsActive = True
        End Sub

        Public Class RibbonCommandHandler
            Implements System.Windows.Input.ICommand

            Public Function CanExecute(ByVal parameter As Object) As Boolean
                Return True
            End Function

            Public Event CanExecuteChanged As EventHandler

            Public Sub Execute(ByVal parameter As Object)
                Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument

                If TypeOf parameter Is RibbonButton Then
                    Dim button As RibbonButton = TryCast(parameter, RibbonButton)
                    doc.Editor.WriteMessage(vbLf & "RibbonButton Executed: " + button.Text & vbLf)
                End If
            End Sub

            Public Function CanExecute1(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute

            End Function

            Public Event CanExecuteChanged1(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged

            Public Sub Execute1(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute

            End Sub
        End Class

        Public Class Images
            Public Shared Function getBitmap(ByVal image As Bitmap) As BitmapImage
                Dim stream As New MemoryStream()
                image.Save(stream, ImageFormat.Png)
                Dim bmp As New BitmapImage()
                bmp.BeginInit()
                bmp.StreamSource = stream
                bmp.EndInit()

                Return bmp
            End Function
        End Class
    End Class
End Namespace

 

 

 

 

 

 

 

 

Valued Mentor
Jeffrey_H
Posts: 372
Registered: ‎01-20-2010
Message 7 of 25 (13,713 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

11-30-2010 04:42 AM in reply to: SMachado

AddHandler pan3ribcombo.CurrentChanged , AddressOf pan3ribcombo_CurrentChanged

acApp = Autodesk.AutoCAD.ApplicationServices.Application

 

You can also find your answers @ TheSwamp
Valued Contributor
SMachado
Posts: 98
Registered: ‎11-19-2009
Message 8 of 25 (13,700 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

11-30-2010 07:43 AM in reply to: Jeffrey_H

Hi Jeffrey!

 

Ok i have another question, after build the code, netloaded the code, the ribbon shows up, but all the buttons in the ribbon are disabled, how do i enable them?? 

 

Thanks a lot for you help.

Valued Contributor
SMachado
Posts: 98
Registered: ‎11-19-2009
Message 9 of 25 (13,638 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

12-01-2010 02:26 PM in reply to: SMachado

Anyone can help me with my las question??

Valued Contributor
deathman20
Posts: 55
Registered: ‎11-08-2010
Message 10 of 25 (13,131 Views)

Re: Create custom ribbon tab and buttons for Autocad mechanical 2011?

01-18-2011 02:34 PM in reply to: SMachado

Irvin,

 

Being a total newbie to this all I was trying your code to test it out, but I ran into 2 issues.

 

1) I get an error at line 306 Column 39

    Description:  The event 'RibbonSample.Ribbon.RibbonCommandHandler.CanExecuteChange' is never used

 

2) I can't get it to load into autocad no matter what I try, not sure if that error is holding me back or not.

 

The only 2 things I added to the project was the Reference Paths, both in my case

C:\Program Files\Autodesk\ACADM 2010
C:\Program Files\Common Files\Autodesk Shared

 

As well changed the acad exe and working directory to run from C:\Program Files\Autodesk\ACADM 2010

 

Not sure what im doing wrong but here is a snip it of the output code I get from running it. 

 

Edit: Sorry would put the output window in but its long and garbled.   Instead I attached it as a text file.

 

Any help is apperciated with this one.

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community