Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update ProjectParameter CategorySet without loosing values

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
lwlXUTTT
307 Views, 4 Replies

Update ProjectParameter CategorySet without loosing values

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

4 REPLIES 4
Message 2 of 5
architect.bim
in reply to: lwlXUTTT

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
Message 3 of 5
Mohamed_Arshad
in reply to: lwlXUTTT

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 🙂

 

 

Thanks & Regards,
Mohamed Arshad K
Message 4 of 5

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... 

 

 

 

Thanks & Regards,
Mohamed Arshad K
Message 5 of 5
lwlXUTTT
in reply to: architect.bim

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report