当前位置:首页 > C#在AutoCAD2010中创建Ribbon
API for CUIx files and the Runtime Ribbon in AutoCAD?
//now create button 2
Autodesk.Windows.RibbonButton ribButton2 = new RibbonButton(); ribButton2.Text = \;
ribButton2.CommandParameter = \; ribButton2.ShowText = true;
ribButton2.CommandHandler = new AdskCommandHandler();
//create a tooltip
Autodesk.Windows.RibbonToolTip ribToolTip = new RibbonToolTip(); ribToolTip.Command = \; ribToolTip.Title = \;
ribToolTip.Content = \;
ribToolTip.ExpandedContent = \Also check which event you should add handle to add custom ribbon on AutoCAD startup.\; ribButton1.ToolTip = ribToolTip;
//now add the 2 button with a RowBreak ribSourcePanel.Items.Add(ribButton1);
ribSourcePanel.Items.Add(new RibbonRowBreak()); ribSourcePanel.Items.Add(ribButton2);
//now add and expanded panel (with 1 button)
Autodesk.Windows.RibbonRowPanel ribExpPanel = new RibbonRowPanel();
//and add it to source
ribSourcePanel.Items.Add(ribExpPanel);//needs to be here
Autodesk.Windows.RibbonButton ribExpButton1 = new RibbonButton(); ribExpButton1.Text = \; ribExpButton1.ShowText = true;
ribExpButton1.CommandParameter = \;
ribExpButton1.CommandHandler = new AdskCommandHandler(); ribExpPanel.Items.Add(ribExpButton1);
5
API for CUIx files and the Runtime Ribbon in AutoCAD?
//ribSourcePanel.Items.Add(new RibbonPanelBreak()); //ribSourcePanel.Items.Add(ribExpPanel);//needs to be above }
private static void addPanel2(RibbonTab ribTab) {
//create the panel source
Autodesk.Windows.RibbonPanelSource ribSourcePanel = new RibbonPanelSource(); ribSourcePanel.Title = \; //now the panel
RibbonPanel ribPanel = new RibbonPanel(); ribPanel.Source = ribSourcePanel; ribTab.Panels.Add(ribPanel);
//create a Ribbon text
Autodesk.Windows.RibbonTextBox ribTxt = new RibbonTextBox(); ribTxt.Width = 100;
ribTxt.IsEmptyTextValid = false; ribTxt.InvokesCommand = true;
ribTxt.CommandHandler = new AdskCommandHandler();
//create a Ribbon List Button
Autodesk.Windows.RibbonSplitButton ribListBtn = new RibbonSplitButton(); Autodesk.Windows.RibbonButton ribButton1 = new RibbonButton(); ribButton1.Text = \; ribButton1.ShowText = true;
ribButton1.CommandParameter = \;
ribButton1.CommandHandler = new AdskCommandHandler(); Autodesk.Windows.RibbonButton ribButton2 = new RibbonButton(); ribButton2.Text = \; ribButton2.ShowText = true;
ribButton2.CommandParameter = \;
6
API for CUIx files and the Runtime Ribbon in AutoCAD?
ribButton2.CommandHandler = new AdskCommandHandler(); ribListBtn.Text = \; ribListBtn.ShowText = true; ribListBtn.Items.Add(ribButton1); ribListBtn.Items.Add(ribButton2);
ribSourcePanel.Items.Add(ribTxt);
ribSourcePanel.Items.Add(new RibbonRowBreak()); ribSourcePanel.Items.Add(ribListBtn); }
Here is the Event handler that is called when the control is clicked.
public class AdskCommandHandler: System.Windows.Input.ICommand {
public bool CanExecute(object parameter) {
return true; }
public event EventHandler CanExecuteChanged;
public void Execute(object parameter) {
//is from a Ribbon Button?
RibbonButton ribBtn = parameter as RibbonButton; if (ribBtn != null)
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute((String)ribBtn.CommandParameter, true, false, true);
//is from s Ribbon Textbox?
RibbonTextBox ribTxt = parameter as RibbonTextBox;
7
API for CUIx files and the Runtime Ribbon in AutoCAD?
if (ribTxt != null)
System.Windows.Forms.MessageBox.Show(ribTxt.TextValue); } }
This command will remove the ribbon:
[CommandMethod(\)] public void removeRibbon() {
Autodesk.Windows.RibbonControl ribCntrl =
Autodesk.AutoCAD.Ribbon. RibbonServices.RibbonPaletteSet.RibbonControl; //find the custom tab using the Id for (int i = 0; i < ribCntrl.Tabs.Count; i++) {
if (ribCntrl.Tabs[i].Id.Equals(MY_TAB_ID)) {
ribCntrl.Tabs.Remove(ribCntrl.Tabs[i]); return; } } }
Here is a screenshot of the Ribbon with the new Tab after running the addMyRibbon command:
8
共分享92篇相关文档