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.
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
Solved by Jeff_M. Go to Solution.
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; } } }
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!
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.
Norman Yuan
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
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.
Norman Yuan
Hi Jeff,
I want to create my own AutoCad Plugin, but I have no experience with c# at this point. Anyway I want to learn and see how far I can get.
To begin with I thought it would be cool, to have my own Ribbon, like in the example-code you gave.
Therefore I copied your code into Visual Studio Express (2015) with all the AutoDesk templates installed (using the C# Autocad template)
I've also added all the references you posted. Building worked just fine and didn't give me any error-messages.
However, when I start Autocad (2018) and use the 'netload'-command to load the .dll-file, nothing happens. I don't get an error-message either, but no additional ribbon appears.
Do you have any idea, what the issue could be?
Regards,
Felix
@f.rampf wrote:Hi Jeff,
I want to create my own AutoCad Plugin, but I have no experience with c# at this point. Anyway I want to learn and see how far I can get.
To begin with I thought it would be cool, to have my own Ribbon, like in the example-code you gave.
Therefore I copied your code into Visual Studio Express (2015) with all the AutoDesk templates installed (using the C# Autocad template)
I've also added all the references you posted. Building worked just fine and didn't give me any error-messages.
However, when I start Autocad (2018) and use the 'netload'-command to load the .dll-file, nothing happens. I don't get an error-message either, but no additional ribbon appears.
Do you have any idea, what the issue could be?
Regards,
Felix
You have to make calls to APIs in order to add your content to the Ribbon. If you read what it says at the top of the example, you'll see the Initialize() method mentioned. What the poster was actually referring to is the IExtensionApplication interface's Initialize() method, which you must provide.
You can search here for IExtensionApplication and you should find examples of how its used to execute your code when your .DLL is loaded.
Norman and Jeff_M,
I just wanted to post a thank you to you both for these (reasonably old) examples. I've looked into this topic a few times over the years, wanting to do this, but never having it be a pressing need, so always gave up on it. The two of you, with a few paragraphs, have saved me countless hours of wading through documentation and such trying to figure out how to do this.
Thank you both for all of your efforts, here, and providing such useful, simple, on point, practical samples.
Hello @norman.yuan ,
I try to find these file PresentationFramework.dll, PresentationCore.dll, System.Xaml.dll but could not see them. Where should i find it ?
Thanks you,
Those are part of .NET Framework, which is, obviously, available with your computer, because you have AutoCAD and/or VIsual Studio installed to do AutoCAD .NET programming.
In VS, open open "Add References..." dialog box, select "Asseblies" tab on the left, then you can find all of them, as shown in pictures below.
Norman Yuan
how can I add a new button in Add-ins Ribbon with a custom icon?
Also, need to load .dll file when the user clicks on the button.
Thanks in Advance.
When you say "Add-ins Ribbon", do you mean a Ribbon tab, created by your code/add-in, or an existing ribbon tab, created by other add-in (or, simply an existing ribbon tab, which may already loaded at the moment you want to add a button to)? Let's assume this is the possible scenario: you want to add a button to the ribbon menu, preferably, an existing/loaded ribbon tab; however, if the existing ribbon tab does not exists, your code would decide either to add a new ribbon tab (and a ribbon panel on the tab), then the ribbon button; or to not add the button at all.
If you have read Jeff's code (message 2/17) and mine (7/17) carefully enough, you would have gotten the idea already:
1. Obtain RibbonControl object, as Jeff's code shows;
2. Use FindTab() method to decide if the target ribbon tab exists or not;
3. If the tab is found, you will need to decide which ribbon panel the button would be added into, or add a new ribbon panel for the button;
4. If the tab is not found, you need to create one, if the button must be added. Of course you also need to add a ribbon panel to the new tab.
5. Once the button added (as Jeff's code demos), you simply set the button's CommandParameter to a string of command, something like
"_NETLOAD \"[Path]\myApp.dll\""
Norman Yuan
@norman.yuan Thank you for your detailed reply.
I mean an existing Ribbon which is called "Add-Ins" as below screenshot. However, I'll go through the codes from you and Jeff.
Firstly, changing an existing ribbon menu, which is not created by your own code/customization, might not be a good idea; secondly, changing/updating CUI might be better/easier solution than dynamic change made by code (meaning you have to make sure your code must run to guarantee your ribbon button's availability.
If you have reach the conclusion that you need to use code to generate the said ribbon button, again, Jeff's code HAS ALREADY provide enough clue of how to do it. Let me reiterate again:
1. Use RibbonControl.FindTab() to make sure "Add-ins" tab does exists; You would need to decide what if it does not exists (say, the current AutoCAD profile does not load AutoCAD default ribbon, but user defined custom ribbon): you would either add the tab, or choose not adding your ribbon button.
2. Add a new panel into the "Add-ins" tab, as Jeff's code demos (addContent() and addOnePanel() methods in Jeff's code, you only need minor and obvious change, such as panel/button text...)
3. Set button's CommandParameter property to "_.NETLOAD ..." string.
Norman Yuan
Can't find what you're looking for? Ask the community or share your knowledge.