Let’s see how to create TextBox items using RevitAddinWizard.
After the menu item or the tool of the Revit Addin Coder is clicked, the Ribbon Creator window will appear. Then a TextBox can be specified in the Item column and Text/Tooltip can be input for the TextBox. A default image is provided for each TextBox as shown in the first TextBox in the following screenshot and the image can be changed to any other one through clicking on the icon itself as shown in the second TextBox. A Separator is also demonstrated in this example:
As can be noticed, the Command cells are all disabled for these TextBox and Separator items as they do not trigger any commands.
After the OK button is pressed, the following code will be created:
public void AddRibbonItemsToRibbonPanel(RibbonPanel panel)
{
string assemFullName = Assembly.GetExecutingAssembly().Location;
string assemPath = Path.GetDirectoryName(assemFullName);
TextBoxData cnt1Panel_grp0_item1Data = new TextBoxData("cnt1Panel_grp0_item1");
Autodesk.Revit.UI.TextBox cnt1Panel_grp0_item1 = panel.AddItem(cnt1Panel_grp0_item1Data) as Autodesk.Revit.UI.TextBox;
cnt1Panel_grp0_item1.ToolTip = @"How are you?";
cnt1Panel_grp0_item1.Value = @"Hello";
cnt1Panel_grp0_item1.Image = BmpImageSource(@"RevitAddinCSProject.Resources.CheckAndUpdate.bmp");
cnt1Panel_grp0_item1.ShowImageAsButton = true;
cnt1Panel_grp0_item1.EnterPressed += CallbackOfTextBoxEnterPressed;
panel.AddSeparator();
TextBoxData cnt1Panel_grp0_item3Data = new TextBoxData("cnt1Panel_grp0_item3");
Autodesk.Revit.UI.TextBox cnt1Panel_grp0_item3 = panel.AddItem(cnt1Panel_grp0_item3Data) as Autodesk.Revit.UI.TextBox;
cnt1Panel_grp0_item3.ToolTip = @"How's it going?";
cnt1Panel_grp0_item3.Value = @"Hey";
cnt1Panel_grp0_item3.Image = BmpImageSource(@"RevitAddinCSProject.Resources.good.bmp");
cnt1Panel_grp0_item3.ShowImageAsButton = true;
cnt1Panel_grp0_item3.EnterPressed += CallbackOfTextBoxEnterPressed;
}
public static void CallbackOfTextBoxEnterPressed(object sender, TextBoxEnterPressedEventArgs args)
{
}
public static System.Windows.Media.ImageSource BmpImageSource(string embeddedPath)
{
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedPath);
var decoder = new System.Windows.Media.Imaging.BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
return decoder.Frames[0];
}
As shown in the code, each TextBox is associated with an image and clicking the image will trigger an event to update the value of the text box from its current input; otherwise the ENTER key has to be pressed so as to update the value. If not, the input will just be lost as introduced in early posts.
If some extra code is added to the same External Application:
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel(Guid.NewGuid().ToString());
AddRibbonItemsToRibbonPanel(panel);
panel.Name = "ABC_APP3_PNL2";
panel.Title = "Buttons created by the RevitAddinWizard";
something like the following will be added to the Revit Ribbon (depending on what the specified image really looks like):
As can be seen, the left text box has the default image and the right one has a different one specified in the Ribbon Creator window, and they function the same through the handler of the event EnterPressed of the TextBox.
All the above is supported by RevitAddinWizard.
Links to some related articles:
Ribbon of Revit API - PushButton And TextBox
Use Ribbon Creator of RevitAddCoder to Create PushButton And Separator
Use Ribbon Creator of RevitAddCoder to Create TextBox
Ribbon of Revit API - ComboBox And ComboBoxMember
Use Ribbon Creator of RevitAddCoder to Create ComboBox And ComboBoxMember
Ribbon of Revit API - PulldownButton And SplitButton
Use Ribbon Creator of RevitAddCoder to Create PulldownButton And PushButton
Use Ribbon Creator of RevitAddCoder to Create SplitButton And PushButton
Ribbon of Revit API - RadioButtonGroup And ToggleButton
Use Ribbon Creator of RevitAddCoder to Create RadioButtonGroup And ToggleButton
Ribbon of Revit API - Stacked Group And AddStackedItems
Ribbon of Revit API - Stacked Group And PulldownButton
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And PushButton Items
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And TextBox Items
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And PulldownButton Items
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And ComboBox Items
Use Ribbon Creator of RevitAddCoder to Create Stacked Group And Various Items
Ribbon of Revit API - Slideout
Use Ribbon Creator of RevitAddCoder to Create Slideout And Various Buttons
Ribbon of Revit API - Manipulate Panels Created by Other Addins
Access Ribbons Created by Ribbon Creator From Another Addin
Update Ribbons Created by Ribbon Creator From Another Addin
Use Ribbon Creator of RevitAddCoder to Create a Comprehensive Ribbon Panel
Ribbon of Revit API - Title And Name of Panels
Ribbon of Revit API - Text And Name of RibbonItem
Ribbon of Revit API - LongDescription And TooltipImage of RibbonItem
Recent Comments