Hi. Working with Revit API. Selected category is in the variable called "category". How to make a list of parameters that belong to that category and put it inside of a new ComboBox?
Assuming that I am going to need to continue inside of the Class.cs file. Should I create a list of all elements (in Class.cs) inside of that selected category and using foreach get the parameters of every single element (all types of parameters) to later create a collection out of them and finally put it in a new ComboBox?
Assuming that I am going to need to continue inside of the Class.cs file. Should I create a list of all elements (in Class.cs) inside of that selected category and using foreach get the parameters of every single element (all types of parameters) to later create a collection out of them and finally put it in a new ComboBox?
Class.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
namespace CombineParameters
{
[Transaction(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
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();
ElementCategoryFilter filter = new ElementCategoryFilter(category);
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> ListOfParameters = collector.WherePasses(filter);
//this one doesn't work either
//IList<Element> ListOfParameters = ListOfParameters.OfClass(typeof(category))
return Result.Succeeded;
}
}
}
UserWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Autodesk.Revit.DB;
namespace CombineParameters
{
/// <summary>
/// Interaction logic for UserWindRoom.xaml
/// </summary>
public partial class UserWindow : Window
{
SortedList<string, Category> myCategories;
public UserWindow(SortedList<string, Category> elements)
{
InitializeComponent();
AllTheCategories.ItemsSource = elements;
AllTheCategories.DisplayMemberPath = "Key";
AllTheCategories.SelectionChanged += OnSelectionChanged;
}
public void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (AllTheCategories.SelectedItem is null)
{
}
else if (AllTheCategories.SelectedItem is KeyValuePair<string, object> keyValuePair)
{
var category = (Category)keyValuePair.Value;
}
}
}
}