Hi,
Occasionally we have to make view filters multiple view filters in a model based on a project parameter. I am trying to put together a macro that I can modify when needed to help me create these filters. However, I am struggling with being able to select any parameters that are not built in to create filters. How can I find the parameter Id when i only have the name?
Thank you in advance.
public void viewFilter() { Document doc = this.ActiveUIDocument.Document; srviewfilter(doc,"PU"); } public void srviewfilter(Document doc,string typeabbreviation) { Element firstmech = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_MechanicalEquipment).FirstElement(); string prefix="Mech_Eq-"; IList<ElementId> catIds = new List<ElementId>(); catIds.Add(doc.Settings.Categories.get_Item("Mechanical Equipment").Id); catIds.Add(doc.Settings.Categories.get_Item("Duct Accessories").Id); string filtername=string.Concat(prefix,typeabbreviation); IList<FilterRule> rules = new List<FilterRule>(); ElementId paramID = new ElementId(firstmech.LookupParameter("TAG_MECH").Id); rules.Add(ParameterFilterRuleFactory.CreateEqualsRule(paramID,typeabbreviation, true)); using (Transaction t = new Transaction(doc,"View Filter")) { t.Start(); ParameterFilterElement filter = ParameterFilterElement.Create(doc, filtername, catIds, rules); t.Commit(); } }
One way that could work but that may be computationally heavy is to declare two lists (one of parameter id, one of parameter names) and to associate the two of them.
So you would loop through all the parameters, and for each parameter you add its id to one list and its name to the other list.
Then you could easily find the id of a parameter based on its name, as long as all parameters in the list have unique names.
Dim ParamIdList as new List(Of ElementId)
Dim ParamNameList as new List(Of String)
Dim ParamId as ElementId = Nothing
Dim ParamName as String = "Name of the parameter I want the ElementId of"
-------
Put all the parameters info into the lists
-------
For i=0 to ParamNameList.count-1
If ParamNameList(i) = ParamName then
ParamId = ParamIdList(i)
Exit For
End If
Next
(I code in VB.Net)
This may not be the fastest solution or the prettiest one, but I think it could work.
Antoine
Project parameters are "document-based" parameters, and are stored in a (Shared)ParameterElement.
Given a name, this is how you find the Id:
string name2Find = "test"; ParameterElement pElem = new FilteredElementCollector(doc) .OfClass(typeof(ParameterElement)) .Cast<ParameterElement>() .Where(e=> e.Name == name2Find) .FirstOrDefault(); ElementId paramID = pElem.Id;
Thank you for the answer!
In a previous thread, you compared the name of the Definition instead of the ParameterElement itself:
https://forums.autodesk.com/t5/revit-api-forum/deleting-a-non-shared-project-parameter/td-p/5975020
Do both of these works equally?
I haven't run into an error yet, using the Name of the ParameterElement. Before I was delving into Parameters and FamilyParameters, and with those you can only use the Definition.Name, which probably is the "official" place to look for the name.
Of course only the develpment team can give you a definitive answer.
Can't find what you're looking for? Ask the community or share your knowledge.