Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i have problem in convert 'user category selected' to 'item in BuiltInCategory enum'
thanks for your help ...
Solved! Go to Solution.
i have problem in convert 'user category selected' to 'item in BuiltInCategory enum'
thanks for your help ...
Solved! Go to Solution.
Hi Ahmed,
as shown in your screenshots, form1.selectedcategory is a String type variable,
but the ElementCategoryFilter() Constructor takes a BuiltInCategory enum value!
so what you need is to convert your string to a BuiltInCategory enum value,
you can try this:
BuiltInCategory BIC = (BuiltInCategory) BuiltInCategory.Parse(typeof(BuiltInCategory), form1.selectedcategory) ;
ElementCategoryFilter f = new ElementCategoryFilter(BIC);
Note that form1.selectedcategory must be equal to the enum string value not the direct Revit category name, e.g.
Revit category name : "StructuralFraming"
enum string value : "OST_StructuralFraming"
you must use "OST_StructuralFraming" not "StructuralFraming"!
to get that you can make a dictionary to convert the value of the string
this link will help you a lot to achieve this:
https://docs.google.com/spreadsheets/....
I hope that will help you!
what kind of string do you use in your ComboBox? (ex : "OST_Walls" or "Walls"?). If you use the first one, you have to parse the built in category like @Omar_Amen said. If you use the second one (category name), you can iterate over the built in category enumeration, get their names and check if it's the same as the combo box value.
BuiltInCategory BuiltInCategoryFromName(Document doc, string category_name)
{
BuiltInCategory ost = BuiltInCategory.INVALID;
Categories categories = doc.Settings.Categories;
foreach (BuiltInCategory bic in System.Enum.GetValues(typeof(BuiltInCategory)))
{
try
{
if (categories.get_Item(bic).Name == category_name)
{
ost = bic;
break;
}
}
catch
{
}
}
return ost;
}