Adding a category to a project parameter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
When I want to add a category to a project parameter that already exists in a Revit file, simply inserting the category into the parameter that exists in the "Document.ParameterBindings" property does not actually add that category, and the box for that category in the project parameter definitions is not checked. It seems to me that something like the code below should be sufficient for adding the category to the parameter:
ElementBinding b = (ElementBinding)elem.Document.ParameterBindings.get_Item(definition);
b.Categories.Insert(elem.Category);
This is something that is easily available in the UI, but does not seem to function the same through the API.
So, I use the "ReInsert" function of the "BindingMap" class to get the parameter to update. What I am finding is that when I perform this action on multiple different occasions, applying new categories to the same parameter(s), some of the elements that already had a value for the parameter(s) will lose the value(s). It is an inconsistent behavior, but performing the function multiple times seems to always end up in a loss of data on at least some of the elements. This prevents functionality of some of our custom workflows, so I am going to have to write a custom reinsert function that will save and rewrite all values of the parameter if changed.
What I am wondering is if there is a better way to add a category to a project parameter that I am overlooking, or if the API is not working the way it was intended to (or should) work.