Yes, it is possible to add a TextBox and ComboBox control to a CUI (Custom User Interface) file in AutoCAD using C# and the AcCUI reference. Here's an example code snippet that demonstrates how to add a TextBox and ComboBox control to a ribbon tab and save it to a CUI file:
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
// Add references to AcCUI, AcWindows, and AcDbServices
public class MyCUICommands
{
[CommandMethod("AddControlsToCUI")]
public void AddControlsToCUI()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
// Open the CUI file
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Get the CUI editor
Editor editor = doc.Editor;
EditorUserInteraction eui = editor as EditorUserInteraction;
if (eui == null)
{
editor.WriteMessage("\nUnable to get the CUI editor.");
return;
}
// Get the CUI file
CuiFile cuiFile = eui.CuiFile;
if (cuiFile == null)
{
editor.WriteMessage("\nUnable to get the CUI file.");
return;
}
// Get the Ribbon tab
CuiGroup ribbonTab = cuiFile.RibbonRootGroup.AddGroup("MyRibbonTab");
ribbonTab.Name = "My Ribbon Tab";
ribbonTab.Description = "My custom ribbon tab";
// Add a TextBox control
CuiTextBox textBox = new CuiTextBox();
textBox.Name = "MyTextBox";
textBox.Text = "Hello World!";
textBox.ToolTip = "This is a text box.";
ribbonTab.Add(textBox);
// Add a ComboBox control
CuiComboBox comboBox = new CuiComboBox();
comboBox.Name = "MyComboBox";
comboBox.Text = "Option 1";
comboBox.ToolTip = "This is a combo box.";
ribbonTab.Add(comboBox);
// Save the changes to the CUI file
cuiFile.Save();
tr.Commit();
}
// Refresh the CUI
Application.UpdateMenus();
Application.UpdateScreen();
}
}
In this example, the AddControlsToCUI command adds a TextBox and ComboBox control to a ribbon tab named "My Ribbon Tab" in the CUI file. The CuiTextBox and CuiComboBox classes are used to define the properties of the TextBox and ComboBox controls, such as their name, text, and tooltip. Finally, the cuiFile.Save() method is called to save the changes to the CUI file, and the Application.UpdateMenus() and Application.UpdateScreen() methods are called to refresh the CUI in AutoCAD.