Update ProjectParameter CategorySet without loosing values

Update ProjectParameter CategorySet without loosing values

lwlXUTTT
Advocate Advocate
513 Views
4 Replies
Message 1 of 5

Update ProjectParameter CategorySet without loosing values

lwlXUTTT
Advocate
Advocate

Dear All,

 

is there a way to update existing ProjectParameter (e.g add new category to categorySet) differently than using ReInsert method from BindingMap? The problem with this one is that it removes existing ProjectParam and later creates new with new CategorySet, therefore already-specified and stored in this Parameter values would be gone!

ReInsert method:

https://www.revitapidocs.com/2023/7b613771-310d-6d89-4b69-475a68033f73.htm

 

any help much appreciated,

Lukasz

0 Likes
Accepted solutions (1)
514 Views
4 Replies
Replies (4)
Message 2 of 5

architect.bim
Collaborator
Collaborator
Accepted solution

Hello!
I think there is no straightforward solution to this problem. But this topic has already been discussed here and here.


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 3 of 5

Mohamed_Arshad
Advisor
Advisor

HI @lwlXUTTT 

 

 I already answered for the issue. Kindly Check the Below Link and Reference Code.

 

URL :https://forums.autodesk.com/t5/revit-api-forum/adding-categories-to-existing-parameter-binding/m-p/1... 

 

Script

 //Global Variables
            InstanceBinding instanceBinding = null;
            Definition def = null;

            //Category Need to Add to the Existing Prameter Bindings
            Category cat = Category.GetCategory(doc, BuiltInCategory.OST_Assemblies);

            //Get Instance Binding From Document
            var map = doc.ParameterBindings.ForwardIterator();

            //Iterate using Iterator
            while (map.MoveNext())
            {
                //Get the Parameter need to add
                def = map.Key as Definition;

                if (def.Name == "Demo")
                {
                    instanceBinding = map.Current as InstanceBinding;
                }

            }

            //Get Existing Category Set From the Binding
            CategorySet existingSet = instanceBinding.Categories;

            if(!existingSet.Contains(cat))
            {
                existingSet.Insert(cat);
            }

            //Adding Category to Exsting Instance Binding (Without changing any parameter)
            using (Transaction addCategory = new Transaction(doc,"Add Category"))
            {
                addCategory.Start();

                //Re-Insert Categories to Exsting Instance Binding
                instanceBinding.Categories = existingSet;

                doc.ParameterBindings.ReInsert(def, instanceBinding);

                addCategory.Commit();
            }

 

Hope this Helps 🙂

 

 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 4 of 5

Mohamed_Arshad
Advisor
Advisor

HI @architect.bim 
  I have solved this issue. Without losing value I can be able to re-insert new Category for Existing Parameters Bindings. Can you please suggest any idea on this 🙂

 

URL : https://forums.autodesk.com/t5/revit-api-forum/adding-categories-to-existing-parameter-binding/m-p/1... 

 

 

 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 5 of 5

lwlXUTTT
Advocate
Advocate

workaround with saved values to Cache solved the issue partially, I will mark it as a solution -> problem exists for example, when project parameters are used in KeySchedules -> after reinserting, they are gone from key schedule

0 Likes