这个代码也运行,但在关闭autocad时出现问题,我的选项卡不是autocad中的永久选项卡必须每个打开的autocad运行TAB,面板和按钮
如何在Autocad中编辑永久选项卡,而无需每次打开运行此代码以使TAB
感谢关注
- [CommandMethod("testmyRibbon")]
- public void Testme()
- {
- RibbonControl ribbon = ComponentManager.Ribbon;
- if (ribbon != null)
- {
- RibbonTab rtab = ribbon.FindTab("TEST ME");
- 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()
- {
- Document dwg = Application.DocumentManager.MdiActiveDocument;
- 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.ShowImage = true;
- rb.Width = 250;
- rb.Text = "Test Button";
- rb.CommandHandler = new MyRibbonCommandHandler();
- rb.CommandParameter = "CF";
- // dwg.SendStringToExecute((string)rb.CommandParameter + " ", true, false, true);
- //Add the Button to the Tab
- rps.Items.Add(rb);
- return rp;
- }
-
- }
- internal class MyRibbonCommandHandler : System.Windows.Input.ICommand
- {
- public event EventHandler CanExecuteChanged;
- public bool CanExecute(object parameter)
- {
- return true;
- }
- 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 = acApp.DocumentManager.MdiActiveDocument;
- dwg.SendStringToExecute((string)btn.CommandParameter + " ", true, false, true);
- }
- }
- }
02xtj4le4hx.png
hjv13fuvu3o.png
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |