Message 1 of 6

Not applicable
07-01-2019
05:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, i have created a dll with several different commands to use in Autocad Mechanical 2018, now i would like, instead of have to write every time the command, have a custom tab in the menu where i can use buttons to call the functions i have implemented.
I have already read the documentation about CUI with c#, and followed several tutorials but i can't make appear anything.
This is the code i use:
[CommandMethod("CreateRibbonTabAndPanel")] public static void CreateRibbonTabAndPanel_Method() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; try { CustomizationSection cs = new CustomizationSection((string)Application.GetSystemVariable("MENUNAME")); string curWorkspace = (string)Application.GetSystemVariable("WSCURRENT"); CreateRibbonTabAndPanel(cs, curWorkspace, "ANAW", "AcadNetAddinWizard"); cs.Save(); } catch (System.Exception ex) { ed.WriteMessage(Environment.NewLine + ex.Message); } } public static void CreateRibbonTabAndPanel(CustomizationSection cs, string toWorkspace, string tabName, string panelName) { RibbonRoot root = cs.MenuGroup.RibbonRoot; RibbonPanelSourceCollection panels = root.RibbonPanelSources; //Create the ribbon panel source and add it to the ribbon panel source collection RibbonPanelSource panelsrc=new RibbonPanelSource(root); panelSrc.Text = panelSrc.Name = panelName; panelSrc.ElementID = panelSrc.Id = panelName + "_PanelSourceID"; panels.Add(panelSrc); //Create the ribbon tab source and add it to the ribbon tab source collection RibbonTabSource tabsrc=new RibbonTabSource(root); tabSrc.Name = tabSrc.Text = tabName; tabSrc.ElementID = tabSrc.Id = tabName + "_TabSourceID"; root.RibbonTabSources.Add(tabSrc); //Create the ribbon panel source reference and add it to the ribbon panel source reference collection RibbonPanelSourceReference ribPanelSourceRef = new RibbonPanelSourceReference(tabSrc); ribPanelSourceRef.PanelId = panelSrc.ElementID; tabSrc.Items.Add(ribPanelSourceRef); //Create the workspace ribbon tab source reference WSRibbonTabSourceReference tabSrcRef = WSRibbonTabSourceReference.Create(tabSrc); //Get the ribbon root of the workspace int curWsIndex = cs.Workspaces.IndexOfWorkspaceName(toWorkspace); WSRibbonRoot wsRibbonRoot = cs.Workspaces[curWsIndex].WorkspaceRibbonRoot; var wsToolbarcollection = cs.Workspaces[curWsIndex].WorkspaceToolbars; //Set the owner of the ribbon tab source reference and add it to the workspace ribbon tab collection tabSrcRef.SetParent(wsRibbonRoot); wsRibbonRoot.WorkspaceTabs.Add(tabSrcRef); }
This code is from a tutorial, so i dont mind to change it completely.
Thanks in advance
Solved! Go to Solution.