SimpleToggleButton
Adding custom controls to AutoCAD Ribbon interface through CUI API
Install / Use
/learn @MadhukarMoogala/SimpleToggleButtonREADME
How to Create a Custom Toggle Button
Here in this blog I have shown how to create a Ribbon Toggle Button using AutoCAD Ribbon Runtime API.
https://adndevblog.typepad.com/autocad/2015/03/how-to-use-toggle-button-ribbon-api.html
This code sample shows how can we register a custom ribbon control on AutoCAD Ribbon bar, to illustrate I created a simple toggle button, but however this logic can be extended to any other fancy controls.
Logic:
-
Create a ResourceDictionary to hold resources and controls in XAML
-
Implement the binding logic to manage the state of ToggleButton.
- Create a SystemVariable to hold the state of ToggleButton
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return IsChecked(value); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { bool isOn = (bool)value; if (isOn && !string.IsNullOrEmpty(OnMacro)) RunMacro(OnMacro); else if (!isOn && !string.IsNullOrEmpty(OffMacro)) RunMacro(OffMacro); return DataBindings.DoNothing; } -
Load this XAML in to AutoCAD Runtime, so this custom dictionary gets merged in to the AutoCAD main resource dictionary and you will see a unfied UX.
-
If you are preparing CUIX using CUI editor, make sure, the
keyof ToggleButton should be same as theIdof ToggleButton in CUI. For example "XyzToggleButton"
string menuName = (string)Application.GetSystemVariable("MENUNAME");
CustomizationSection cs = new CustomizationSection(menuName + ".cuix");
var ribbonRoot = cs.MenuGroup.RibbonRoot;
var homeTab = ribbonRoot.FindTab("ID_TabHome");
var elementId = "ID_TogglePanel";
var ribbonPanelSourceReference = homeTab.Find(elementId);
if(ribbonPanelSourceReference is null)
{
var panel = homeTab.AddNewPanel(elementId, "TogglePanel");
var row = panel.AddNewRibbonRow();
row.AddNewToggleButton("XyzToggleButton", "XYZSTATE\nToggle", null, RibbonButtonStyle.LargeWithText);
cs.Save();
}
<adw:RibbonToggleButton
x:Uid="RibbonToggleButton-Xyz"
x:Key="XyzToggleButton"
Name="XYZ Toggle"
Tag="XYZSTATE">
<adw:RibbonToggleButton.IsCheckedBinding>
<Binding Source="{x:Static acmgd:Application.UIBindings}" Path="SystemVariables[XYZSTATE].Value" Converter="{StaticResource XyzToggleButtonConverter}"/>
</adw:RibbonToggleButton.IsCheckedBinding>
<adw:RibbonToggleButton.Image>
<BitmapImage x:Uid="BitmapImage_1" UriSource="Resources/Toggle.bmp" />
</adw:RibbonToggleButton.Image>
<adw:RibbonToggleButton.LargeImage>
<BitmapImage x:Uid="BitmapImage_2" UriSource="Resources/Toggle.bmp"/>
</adw:RibbonToggleButton.LargeImage>
</adw:RibbonToggleButton>TE">
Reading:
How to: Convert Bound Data - WPF .NET Framework | Microsoft Learn
Steps To Build
git clone https://github.com/MadhukarMoogala/SimpleToggleButton.git
cd SimpleToggleButton
msbuild SimpleToggleButton.csproj -property:Configuration=Debug
Expected Build Log: here
Steps To Run
-
Copy
SimpleToggleButton.bundleto %APPDATA%\Autodesk\ApplicationPlugins -
Launch AutoCAD
Demo
<img src="https://github.com/MadhukarMoogala/SimpleToggleButton/blob/master/Toggle.gif" width="450" height="450">
License
This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.
Written By
Madhukar Moogala, Forge Partner Development @galakar
Related Skills
node-connect
348.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
348.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
348.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
