Skip to content

Commit 2fb13c9

Browse files
authored
Update README.md
1 parent 8412782 commit 2fb13c9

1 file changed

Lines changed: 95 additions & 103 deletions

File tree

README.md

Lines changed: 95 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ You can reference the DLL in a Visual Studio project the same way you load any e
3333
using Autodesk.Revit.Attributes;
3434
using Autodesk.Revit.DB;
3535
using Autodesk.Revit.UI;
36-
using SCADtools.Revit.UI;
36+
using SCADtools.Revit.UI.OptionsBar;
37+
using SCADtools.Revit.UI.OptionsBar.Controls;
3738
using System;
3839
using System.Collections.Generic;
40+
using System.Collections.ObjectModel;
41+
using System.Linq;
3942
using System.Windows;
40-
using System.Windows.Controls;
4143
using System.Windows.Media.Imaging;
4244

4345
namespace SCADtools.OptionsBarSample
4446
{
4547
[TransactionAttribute(TransactionMode.Manual)]
4648
internal class Sample : IExternalCommand
4749
{
48-
private OptionsBar optionsBar;
49-
5050
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
5151
{
5252
UIApplication uiapp = commandData.Application;
@@ -56,26 +56,35 @@ namespace SCADtools.OptionsBarSample
5656
try
5757
{
5858
//Initialize OptionsBar
59-
optionsBar = new OptionsBar();
59+
using (OptionsBar optionsBar = new OptionsBar())
60+
{
61+
// build options bar
62+
BuildOptionsBar(optionsBar);
63+
// Show OptionsBar
64+
optionsBar.Show("Create Bending Detail");
6065

61-
DisplayOptionsBar();
66+
// Some instructions to execute in Revit
67+
try
68+
{
69+
IList<Element> pickElementsByRectangle =
70+
uidoc.Selection.PickElementsByRectangle("Select elements.");
6271

63-
//Some instructions to execute in Revit
64-
IList<Element> pickElementsByRectangle = uidoc.Selection.PickElementsByRectangle("Select elements.");
72+
using (Transaction tr = new Transaction(doc, "Transaction name"))
73+
{
74+
tr.Start();
6575

66-
//Optionally, you can disable the options bar while Revit is working
67-
optionsBar.IsEnabled = false;
76+
foreach (Element element in pickElementsByRectangle)
77+
{
78+
// TODO: Your code logic here
79+
}
6880

69-
using (Transaction tr = new Transaction(doc, "Transaction name"))
70-
{
71-
tr.Start();
72-
73-
foreach (Element element in pickElementsByRectangle)
81+
tr.Commit();
82+
}
83+
}
84+
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
7485
{
75-
//TODO: Your code logic here
86+
return Result.Cancelled;
7687
}
77-
78-
tr.Commit();
7988
}
8089

8190
return Result.Succeeded;
@@ -85,146 +94,129 @@ namespace SCADtools.OptionsBarSample
8594
message = ex.Message;
8695
return Result.Failed;
8796
}
88-
finally
89-
{
90-
//Hide the OptionsBar (IMPORTANT)
91-
optionsBar.Hide();
92-
}
9397
}
9498

95-
private void DisplayOptionsBar()
99+
private void BuildOptionsBar(OptionsBar optionsBar)
96100
{
97-
//Initialize a TextBlock to display information at the start of the OptionsBar
98-
TextBlock textBlock = new TextBlock()
99-
{
100-
Text = "Create Bending Detail",
101-
VerticalAlignment = VerticalAlignment.Center,
102-
Margin = new Thickness(10, 0, 20, 0)
103-
};
104-
105-
//Initialize a LabelComboBoxImage to display a list of bar images
106-
LabelComboBoxImage labelComboBoxImage = new LabelComboBoxImage()
101+
// Initialize a LabelComboBoxImage to display a list of bar images
102+
ObLabelComboBoxImage labelComboBoxImage = new ObLabelComboBoxImage()
107103
{
108-
ShowLabel = false,
109104
ItemsTextImage = GetRebarImages(),
110105

111-
//By default the width is 100
112-
ComboBoxWidth = 220
106+
ControlWidth = 220
113107
};
114108

115-
//Initialize a Button
116-
SCADtools.Revit.UI.Button button = new SCADtools.Revit.UI.Button()
109+
// Initialize a Button
110+
ObButton button = new ObButton("...")
117111
{
118-
Label = "...",
119-
120-
//To indicate the separation of the Button with some control that is to its left
112+
// To indicate the separation of the Button with some control that is to its left
121113
MarginLeft = 6,
122-
123-
ControlToolTip = new ControlToolTip()
114+
115+
ObExpandedToolTip = new ObExpandedToolTip()
124116
{
125117
Title = "Rebar Shape Browser",
126118
Content = "Launch/Close Rebar Shape Browser.",
127119
}
128120
};
121+
// Create some event
122+
button.Click += (s, e) =>
123+
{
124+
// Code here
125+
};
129126

130-
//Initialize some list of diameters
131-
List<ComboBoxItemText> comboBoxItemsText = new List<ComboBoxItemText>()
127+
// Initialize some list of diameters
128+
ObservableCollection<ComboBoxItemText> comboBoxItemsText = new ObservableCollection<ComboBoxItemText>(
129+
new List<ComboBoxItemText>()
132130
{
133131
new ComboBoxItemText() { ItemText = "8" },
134132
new ComboBoxItemText() { ItemText = "10" },
135133
new ComboBoxItemText() { ItemText = "12" },
136134
new ComboBoxItemText() { ItemText = "16" }
137-
};
138-
//Initialize a LabelComboBox to display a list of diameters
139-
LabelComboBox labelComboBox = new LabelComboBox()
135+
});
136+
// Initialize a LabelComboBox to display a list of diameters
137+
ObLabelComboBox labelComboBox = new ObLabelComboBox("Diameter:")
140138
{
141-
Label = "Diameter:",
142139
ItemsText = comboBoxItemsText,
143140

144-
//To indicate the separation of the LabelComboBox with some control that is to its left
141+
// To indicate the separation of the LabelComboBox with some control that is to its left
145142
MarginLeft = 10,
146143

147-
//By default the width is 100
148-
ComboBoxWidth = 52,
144+
ControlWidth = 52,
149145

150-
ControlToolTip = new ControlToolTip()
146+
ObExpandedToolTip = new ObExpandedToolTip()
151147
{
152148
Title = "Bar Diameter",
153149
Content = "Specifies the bar diameter.",
154150
}
155151
};
156-
//Create some event
157-
labelComboBox.ComboBoxControl.SelectionChanged += ComboBoxControlOnSelectionChanged;
152+
// Select first element
153+
labelComboBox.SelectedItem = comboBoxItemsText.FirstOrDefault();
154+
// Create some event
155+
labelComboBox.SelectionChanged += OnSelectionChanged;
158156

159-
//Initialize a LabelTextBox to indicate bar spacing
160-
LabelTextBox labelTextBox = new LabelTextBox()
157+
// Initialize a LabelTextBox to indicate bar spacing
158+
ObLabelTextBox labelTextBox = new ObLabelTextBox("Spacing:", "20")
161159
{
162-
Label = "Spacing:",
163-
Text = "20",
164-
165-
//To indicate the separation of the LabelTextBox with some control that is to its left
160+
// To indicate the separation of the LabelTextBox with some control that is to its left
166161
MarginLeft = 10,
167162

168-
//By default the width is 50
169-
TextBoxWidth = 52,
163+
ControlWidth = 52,
170164

171-
ControlToolTip = new ControlToolTip()
165+
ObExpandedToolTip = new ObExpandedToolTip()
172166
{
173167
Title = "Reinforcement Spacing",
174168
Content = "Specifies the spacing for rebar.",
175-
}
169+
},
170+
171+
InputMode = ObInputMode.Numeric
176172
};
177173

178-
LabelCheckBox labelCheckBox = new LabelCheckBox()
174+
ObLabelCheckBox labelCheckBox = new ObLabelCheckBox("Use amount settings")
179175
{
180-
Label = "Use amount settings",
181-
182-
//To indicate the separation of the LabelCheckBox with some control that is to its left
176+
// To indicate the separation of the LabelCheckBox with some control that is to its left
183177
MarginLeft = 10,
184-
185-
//Implement controls to manage the IsChecked property
178+
179+
// Implement controls to manage the IsChecked property
186180
EnabledElements = new List<UIElement>() { labelComboBox, labelTextBox }
187181
};
188182

189-
//Display the OptionsBar
190-
optionsBar.Show(new List<UIElement>()
191-
{
192-
textBlock,
193-
new SCADtools.Revit.UI.Separator(),
194-
labelComboBoxImage,
195-
button,
196-
new SCADtools.Revit.UI.Separator(),
197-
labelComboBox,
198-
labelTextBox,
199-
labelCheckBox
200-
});
183+
// Add controls to OptionsBar
184+
optionsBar.AddControl(new ObSeparator());
185+
optionsBar.AddControl(labelComboBoxImage);
186+
optionsBar.AddControl(button);
187+
optionsBar.AddControl(new ObSeparator());
188+
optionsBar.AddControl(labelComboBox);
189+
optionsBar.AddControl(labelTextBox);
190+
optionsBar.AddControl(labelCheckBox);
201191
}
202192

203-
private void ComboBoxControlOnSelectionChanged(object sender, SelectionChangedEventArgs e)
193+
private void OnSelectionChanged(object sender, RoutedEventArgs e)
204194
{
205-
System.Windows.Controls.ComboBox comboBox = (System.Windows.Controls.ComboBox)sender;
206-
if (comboBox.SelectedItem != null)
195+
var comboBox = sender as ObLabelComboBox;
196+
var item = comboBox.SelectedItem;
197+
if (item != null)
207198
{
208-
ComboBoxItemText comboBoxItemText = (ComboBoxItemText)comboBox.SelectedItem;
209-
MessageBox.Show("Selected item is: " + comboBoxItemText.ItemText);
199+
TaskDialog.Show("OptionsBar", $"Selected item is: {item.ItemText}");
210200
}
211201
}
212202

213-
private List<ComboBoxItemTextImage> GetRebarImages()
203+
private ObservableCollection<ComboBoxItemTextImage> GetRebarImages()
214204
{
215-
//Initialize some list of bar images
216-
return new List<ComboBoxItemTextImage>()
217-
{
218-
new ComboBoxItemTextImage() { ItemTitle = "Rebar Shape : ", ItemText = "B1",
219-
ItemImage = new BitmapImage(new Uri("pack://application:,,,/OptionsBarSample;component/Images/B1.png", UriKind.Absolute)),
220-
IsVisibleImageCollapsed = true },
221-
new ComboBoxItemTextImage() { ItemTitle = "Rebar Shape : ", ItemText = "B2",
222-
ItemImage = new BitmapImage(new Uri("pack://application:,,,/OptionsBarSample;component/Images/B2.png", UriKind.Absolute)),
223-
IsVisibleImageCollapsed = true },
224-
new ComboBoxItemTextImage() { ItemTitle = "Rebar Shape : ", ItemText = "B3",
225-
ItemImage = new BitmapImage(new Uri("pack://application:,,,/OptionsBarSample;component/Images/B3.png", UriKind.Absolute)),
226-
IsVisibleImageCollapsed = true }
227-
};
205+
string title = "Rebar Shape : ";
206+
string imageBaseUri = "pack://application:,,,/OptionsBarSample;component/Images/";
207+
208+
string[] shapes = { "B1", "B2", "B3" };
209+
210+
return new ObservableCollection<ComboBoxItemTextImage>(
211+
shapes.Select(shape => new ComboBoxItemTextImage
212+
{
213+
ItemTitle = title,
214+
ItemText = shape,
215+
ItemImage = new BitmapImage(
216+
new Uri($"{imageBaseUri}{shape}.png", UriKind.Absolute)),
217+
IsVisibleImageCollapsed = true
218+
})
219+
);
228220
}
229221
}
230222
}

0 commit comments

Comments
 (0)