Create List Parameters

Create List Parameters

Anonymous
Not applicable
2,201 Views
5 Replies
Message 1 of 6

Create List Parameters

Anonymous
Not applicable

Hi everybody,

 

I would like to get a list of definitions of the no shared parameters of my project. At present, the solution, that I am using, is to get a list of element and then with a loop over elements I get the definitions. And with the list of definitions a I do a sublist where the definitions are not repeated. As you can see, this system is very slow in big projects.

 

So, my question is there is a better solution, for example something similar to ParameterBindings but for not shared parameters.

 

Thanks for you time,

 

Javi

0 Likes
2,202 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

Hi Javier,

 

What is your method to select the elements? Are you trying to get a list of parameters names or the parameters itself?

 

Anyways here is what I use some times to query using linq but I didn't try it with a big project.


FilteredElementCollector collector = 
			new FilteredElementCollector(doc, doc.ActiveView.Id)
			.WhereElementIsNotElementType();
		
collector.ToElements();
		
var parameters = new List<Parameter>();
		
foreach (Element element in collector)
{
//Create an IEnumerable from the set of parameters
IEnumerable<Parameter> lp = (from Parameter p in element.Parameters select p) .ToList();
//Check if parameter is not shared and no exist in the final list
IEnumerable<Parameter> query = lp.TakeWhile( p => p.IsShared == false && parameters.Contains(p) .Equals(false));
//Finally add it to the list parameters.AddRange(query); }



Related info that may be helpful for you.
https://forums.autodesk.com/t5/revit-api-forum/how-to-get-list-of-all-parameter-and-values-of-wall-o...

 


@Anonymous wrote:

Hi everybody,

 

I would like to get a list of definitions of the no shared parameters of my project. At present, the solution, that I am using, is to get a list of element and then with a loop over elements I get the definitions. And with the list of definitions a I do a sublist where the definitions are not repeated. As you can see, this system is very slow in big projects.

 

So, my question is there is a better solution, for example something similar to ParameterBindings but for not shared parameters.

 

Thanks for you time,

 

Javi


 

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for your answer. But it is more or less that I did. I trying to avoid the loop over a list of elements because when you have a big project then it need much time.

 

Javi

0 Likes
Message 4 of 6

Anonymous
Not applicable

I suspected that you where using something like that, but it worth the shot. Probably you had tried this too.

If the API has no method to access the info faster than a foreach loop or linq query, had you tried reducing the element list?
If you need a list of all parameters available on each element ,you may only need to iterate over just one instance of each element type.

At the end you just iterate over smaller list of parameters.

 

 

List<ElementId> typesIdsList = new List<ElementId>();
List<Parameter> paramList = new List<Parameter>();

FilteredElementCollector collector = 
			new FilteredElementCollector(doc, doc.ActiveView.Id)
			.WhereElementIsNotElementType();
		
collector.ToElements();

foreach (Element element in collector)
{
    //Iterate only over parameters of a single lement instance per type
    if (typesIdsList.Contains(element.GetTypeId()) == false)
    {
        foreach (Parameter p in element.Parameters)
        {
            if (p.IsShared == false && parameters.Contains(p) ==  false))
            {  parameters.Add(p)  }
        }
        typesIdsList.Add(element.GetTypeId());
    }
}

 

0 Likes
Message 5 of 6

Anonymous
Not applicable

Thanks for your answer. I has been very useful. I have reduced the time, not as I would. But it is an improvement.

 

Javi

0 Likes
Message 6 of 6

FAIR59
Advisor
Advisor

this should be faster:

 

StringBuilder sb = new StringBuilder(); 
IEnumerable<ParameterElement> allParameters = new FilteredElementCollector(doc)   .OfClass(typeof(ParameterElement))   .Cast<ParameterElement>()   .Where(x => !(x is SharedParameterElement));

foreach(var p in allParameters)
             {
                 sb.AppendLine(string.Format("<{0}> {1}",p.Id, p.GetDefinition().Name));
             }
TaskDialog.Show("debug", sb.ToString());