How to let the program know which category has been selected? If you will be able to attach code as well that would be really great!
Here's the of the source code and addin so you can have the idea and say if something should be changed immediately.
Basically, main stuff is marked in red color. Many tutorials advice on using a string variable to keep category in, but I have no idea what am I supposed to do with it now or if it is a good solution at all? Thanks!
public class Class : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
Settings documentSettings = doc.Settings;
Categories categories = documentSettings.Categories;
SortedList<string, Category> myCategories = new SortedList<string, Category>();
foreach (Category c in categories)
{
myCategories.Add(c.Name, c);
}
myCategories.Clear();
foreach (Category c in categories)
{
if (c.AllowsBoundParameters)
myCategories.Add(c.Name, c);
}
UserWindow UserWindow = new UserWindow(myCategories);
UserWindow.Show();
return Result.Succeeded;
}
}
UserWindow.xaml.cs
public partial class UserWindow : Window
{
SortedList<string, Category> myCategories;
public UserWindow(SortedList<string, Category> elements)
{
InitializeComponent();
myCategories = elements;
AllTheCategories.ItemsSource = myCategories;
string ChosenCategory = AllTheCategories.SelectedItem.ToString()
}
}
`