.NET

Reply
Contributor
Sined99
Posts: 15
Registered: ‎04-26-2013
Message 1 of 8 (1,148 Views)
Accepted Solution

.NET C# Ribbon tab

1148 Views, 7 Replies
05-13-2013 06:09 AM

Hello, I am new in the autodesk customization, I have autocad 2013 and visual studio 2010

 

I am interested in make a custom ribbon tab, where I can put a button.

 

I have found some (incomplete) samples to implement a custom ribbon tab, but I dont know how to "insert" my tab into autocad 2013, and how must I load my tab? with a command?  or it can load automatically?

 

Can someone show me an example?

 

Thank you very much.

 

*Expert Elite*
Jeff_M
Posts: 4,218
Registered: ‎07-22-2003
Message 2 of 8 (1,122 Views)

Re: .NET C# Ribbon tab

05-13-2013 07:28 PM in reply to: Sined99

Here's a simple example of adding a new tab, panel, & button. YOu can have it load automatically by utilizing your Intialize event.

 

using Autodesk.AutoCAD.Runtime;
using Autodesk.Windows;

namespace AutoCADTest
{
    public class Class1
    {
        [CommandMethod("testmyRibbon", CommandFlags.Transparent)]
        public void Testme()
        {
            RibbonControl ribbon = ComponentManager.Ribbon;
            if (ribbon != null)
            {
                RibbonTab rtab = ribbon.FindTab("TESTME");
                if (rtab != null)
                {
                    ribbon.Tabs.Remove(rtab);
                }
                rtab = new RibbonTab();
                rtab.Title = "TEST  ME";
                rtab.Id = "Testing";
                //Add the Tab
                ribbon.Tabs.Add(rtab);
                addContent(rtab);                
            }
        }

        static void addContent(RibbonTab rtab)
        {
            rtab.Panels.Add(AddOnePanel());
        }

        static RibbonPanel AddOnePanel()
        {
            RibbonButton rb;
            RibbonPanelSource rps = new RibbonPanelSource();
            rps.Title = "Test One";
            RibbonPanel rp = new RibbonPanel();
            rp.Source = rps;

            //Create a Command Item that the Dialog Launcher can use,
            // for this test it is just a place holder.
            RibbonButton rci = new RibbonButton();
            rci.Name = "TestCommand";

            //assign the Command Item to the DialgLauncher which auto-enables
            // the little button at the lower right of a Panel
            rps.DialogLauncher = rci;
            
            rb = new RibbonButton();
            rb.Name = "Test Button";
            rb.ShowText = true;
            rb.Text = "Test Button";
            //Add the Button to the Tab
            rps.Items.Add(rb);
            return rp;
        }
    }
}

 

Jeff_M, also a frequent Swamper
Contributor
Sined99
Posts: 15
Registered: ‎04-26-2013
Message 3 of 8 (1,108 Views)

Re: .NET C# Ribbon tab

05-14-2013 12:34 AM in reply to: Sined99

Hello,

 

Thank you for the sample!!, but I have a problem, I am working with autocad 2013 and visual studio 2010, I can't find the reference(.dll) for the Ribbon Controls, I have attached a picture of the errors, I dont know if the Ribbon control can be include in autocad 2013...

 

-Which is the reference for the ribbon controls??

-Autocad 2013 accept the ribbon controls?

 

Thank you so much!

*Expert Elite*
norman.yuan
Posts: 966
Registered: ‎04-27-2009
Message 4 of 8 (1,096 Views)

Re: .NET C# Ribbon tab

05-14-2013 06:24 AM in reply to: Sined99

You not only need to set references to AcWindows.dll and AdWindows.dll coming from AutoCAD, you also need to set reference to PresentationFramework.dll, PresentationCore.dll, System.Xaml.dll and Windows.Base.dll from .NET framework, because acwindows/adwindows.dll depend on them.

Contributor
Sined99
Posts: 15
Registered: ‎04-26-2013
Message 5 of 8 (1,079 Views)

Re: .NET C# Ribbon tab

05-14-2013 11:09 PM in reply to: norman.yuan

Hello,

 

Thank you for the answer! it works!, thank you very much!

Valued Contributor
Stemdriller
Posts: 88
Registered: ‎12-15-2011
Message 6 of 8 (954 Views)

Re: .NET C# Ribbon tab

06-12-2013 02:32 AM in reply to: Sined99

Hi

 

I have managed to fumble my way through the C# code and converted it into vb.net, and indeed have managed to create a custom tab.

 

I have placed a button within the panel, but can I get my head around how to fire it when clicked. All i need is to get it to show a form when the user clicks the button.

 

Think it is to do with event handling, which at the moment is a bit of a blurr to say the least.

 

Could someone point me in the right direction?

 

Thanks

 

Gareth 

 

*Expert Elite*
norman.yuan
Posts: 966
Registered: ‎04-27-2009
Message 7 of 8 (941 Views)

Re: .NET C# Ribbon tab

06-12-2013 06:47 AM in reply to: Stemdriller

To respond to user action (clicking, in your case) to a RibbonCommandItem (RibbonButton is derived from RibbonCommandItem), you need to have a class that implements System.Windows.Input.ICommand as a command handler, then assign this command handler to the RibbonCommandItem. Something like:

 

In the code of adding RibbonButton to a RibbonTab,

 

...

RibbonButton btn=new RibbonButton()

btn.Text="Click me";

btn...

btn.CommandHandler=new MyRibbonCommandHandler();

btn.CommandParameter="MyCommand";

btn.ToolTip=....

 

public class MyRibbonCommandHandler : System.Windows.Input.ICommand

{

    ....

 

    public void Execute(object parameter)

    {

        RibbonCommandItem btn = parameter as RibbonCommandItem

        if (btn!=null)

        {

            //execute an AutoCAD command, or your custom command defined by [CommandMethod]

            Document dwg=Application.DocimentManager.MdiActiveDocument;

            dwg.SendStringToExecute((string)btn.CommandParameter + " ", true, false, true);

        }

    }

}

 

HTH.

Valued Contributor
Stemdriller
Posts: 88
Registered: ‎12-15-2011
Message 8 of 8 (916 Views)

Re: .NET C# Ribbon tab

06-13-2013 04:25 AM in reply to: norman.yuan

Thanks, i nailed it now.

 

GW

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