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: 

Categories from Shared Parameters

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
NiclasSassHald
205 Views, 2 Replies

Categories from Shared Parameters

Hello everyone,

 

I have a list of SharedParameterElements, which contains all Shared Parameters in my document.

I'm trying to find out which categories the different parameters are added to, but when I use the code below, I only get null. Even if I use the Revit LookUp-tool, I get null in categories.

Can anyone tell me what I'm missing?

 

sortedSharedParameters = new List<Element>();         
FilteredElementCollector coll = new FilteredElementCollector(document);
            coll
                .WhereElementIsNotElementType()
                .OfClass(typeof(SharedParameterElement))
                .ToList();
            sortedSharedParameters = coll.OrderBy(p => p.Name).ToList();

            foreach (Element e in sortedSharedParameters)
            {
                SharedParameterElement sp = (SharedParameterElement)e;
                string category = sp.Category.Name;
            }

 

 

Thanks in advance,

Niclas

2 REPLIES 2
Message 2 of 3

Hi, Look into ParameterBindings; ParameterBindings Property

Get it's iterator and each element is a ElementBinding (instanceBinding for instance state)

 

The ElementBinding has a Categories property with the bound categories to the Project parameter

 

- Michel

Message 3 of 3

Thanks for the reply @TripleM-Dev.net - and sorry for the late respond. Been off programming for a while..

But you led me in the right direction with ParameterBindings.

 

I ended up with the code below, and from there I could loop through each parameter, to get the categories.

            List<Parameter> pamLst = new List<Parameter>();
            BindingMap bindingMap = document.ParameterBindings;

            DefinitionBindingMapIterator it = bindingMap.ForwardIterator();
            while (it.MoveNext())
            {
                Definition definition = it.Key;
                InternalDefinition internalDefinition = (InternalDefinition)definition;
                ElementBinding elementBinding = (ElementBinding)it.Current;


                foreach (Parameter e in pamElement)
                {
                    if (e.Id == internalDefinition.Id)
                    {
                        pamLst.Add(e);
                    }
                }
            }

 

Thanks again!

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

Post to forums  

Forma Design Contest


Rail Community