By Adam Nagy
I would like to modify the Ribbon content - add/remove panels, etc. How could I do it?
Solution
This is only available through the .NET API's.
There are two sets of functionalities:
1) Ribbon Runtime API - provided by AdWindows.dll under Autodesk.Windows namespace
Enables you to edit the Ribbon, but the changes will not be persisted in the CUIx file, so if AutoCAD is restarted, or even if the current workspace is changed (WSCURRENT system variable) or the menu file is reloaded then the changes will be gone and you need to redo them.
Here is a small sample that toggle's the visiblity of the Home tab:
[CommandMethod("HideShowHomeTab")]
static public void HideShowHomeTab()
{
Autodesk.Windows.RibbonControl rc =
Autodesk.Windows.ComponentManager.Ribbon;
Autodesk.Windows.RibbonTab tab =
rc.FindTab("ACAD.ID_TabHome3D");
if (tab != null)
tab.IsVisible = !tab.IsVisible;
}
2) CUI API - provided by AcCui.dll under Autodesk.AutoCAD.Customization namespace
You can use this to modify the user interface by modifying the CUIx file the same way as through the CUI Dialog and these changes will be persisted.
This sample as well toggles the visibility of the Home tab, but using the CUI API:
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
[CommandMethod("HideShowHomeTabInCurrentWorkspace")]
static public void HideShowHomeTabInCurrentWorkspace()
{
string menuName =
(string)acApp.GetSystemVariable("MENUNAME");
string curWorkspace =
(string)acApp.GetSystemVariable("WSCURRENT");
Autodesk.AutoCAD.Customization.CustomizationSection cs =
new Autodesk.AutoCAD.Customization.CustomizationSection(
menuName + ".cuix");
Autodesk.AutoCAD.Customization.WSRibbonRoot rr =
cs.getWorkspace(curWorkspace).WorkspaceRibbonRoot;
Autodesk.AutoCAD.Customization.WSRibbonTabSourceReference tab =
rr.FindTabReference("ACAD", "ID_TabHome3D");
if (tab != null)
tab.Show = !tab.Show;
if (cs.IsModified)
{
cs.Save();
// Reload to see the changes
acApp.ReloadAllMenus();
}
}
Note: The above samples only work without modification in case of using vanilla AutoCAD (where the menu group is ACAD) and inside 3D Modeling workspace (where the Home tab's id is ID_TabHome3D)