Adding TextBox to CUIx File using C#

Adding TextBox to CUIx File using C#

ebo134
Advocate Advocate
1,689 Views
6 Replies
Message 1 of 7

Adding TextBox to CUIx File using C#

ebo134
Advocate
Advocate

Hi every one, I wonder if there is any change to Add TextBox and Combo box Control to Ribbon tab Save it to  a CUI File in C# (NOT USING CUI Interface in Autocad) using AcCUI as Reference, I can add Combo box to a ribbon tab using AdWindows and AcWindows, but this Dynamic, any change to workspace it will disappear

1,690 Views
6 Replies
Replies (6)
Message 2 of 7

alishahsingh20
Explorer
Explorer

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.

Message 3 of 7

cadffm
Consultant
Consultant

Offtopic:

.Net board is the next door

https://forums.autodesk.com/t5/net/bd-p/152

 

Sebastian

Message 4 of 7

ebo134
Advocate
Advocate

I cannot find AcDbServices, where should I can find it,Please?

0 Likes
Message 5 of 7

kerry_w_brown
Mentor
Mentor

@ebo134 

is it possible you are referring to

namespace Autodesk.AutoCAD.DatabaseServices.

which is in AcDbMgd.dll

 

Regards,


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 6 of 7

ebo134
Advocate
Advocate

so, AcDbMgd.dll does not contains CuiTextBox! the problem is CuiTextbox, where I can find the assembly that it contains CuiTextbox

0 Likes
Message 7 of 7

Ed__Jobe
Mentor
Mentor

The CUI stuff should be in the Autodesk.AutoCAD.Customization namespace which is contained in AcCUI.dll. However, it doesn't have CuiTextbox. It appears that @alishahsingh20 is using a custom dll that they did not mention. I did an internet search and couldn't find a reference. There were some on github, but they didn't seem to be meant for AutoCAD.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes