From a list of elements, it’s values for parameters depending on each kind of parameter it has

Hello guys,

So, My problem is: from a list of elements, I need to get it’s values depending on each kind of parameter it has. The Farthest I Could Go Was This above, But It Is Not Working Because I need to treat differently each element depending on it’s parameters … Any ideas?

import clr,System
clr.AddReference(“RevitAPI”) #Adding reference to Revit’s API DLLs
import Autodesk #Loads the Autodesk namespace
from Autodesk.Revit.DB import * #Loading Revit’s API classes

clr.AddReference(“RevitServices”) #Dynamo’s classes for handling Revit documents
import RevitServices
from RevitServices.Persistence import DocumentManager
#An internal Dynamo class

import System.Collections.Generic
from System.Collections.Generic import List
from System.Collections.Generic import Dictionary

from collections import defaultdict

doc = DocumentManager.Instance.CurrentDBDocument #Finally, setting up handles to the active Revit document

#######OK NOW YOU CAN CODE########
########################## GET ELEMENTS #########################
#Creating ICollection
builtInCat = ListBuiltInCategory

#adding categories
builtInCat.Add(BuiltInCategory.OST_PipeCurves)
builtInCat.Add(BuiltInCategory.OST_PipeFitting)

filter= ElementMulticategoryFilter(builtInCat)

#Get Elements
elements = FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(filter).ToElements()

########################## GET PARAMETERS #########################

MAPPING PARAMETERS TO BE USED AS KEYS

#mapping parameters to be used as keys
def keys_for_pipes(element):
#gating parameters as strings
return element.LookupParameter(“CES_metre”).AsString() + " _ " + element.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM).AsValueString() + " _ " + element.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).AsValueString()

#mapping parameters to be used as keys
def keys_for_pipesfitting(element):
#gating parameters as strings
return element.LookupParameter(“CES_metre”).AsString() + " _ " + element.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM).AsValueString() + " _ " + element.get_Parameter(BuiltInParameter.RBS_PIPE_SIZE_MAXIMUM).AsValueString()

MAPPING PARAMETERS TO BE USED AS VALUES

def lengh_for_pipes(element):
#gating lengh parameter
return element.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble()

def lengh_for_pipesfitting(element):
#gating lengh parameter
return element.LookupParameter(“BERSfr_C_longueur”).AsDouble()

############ CREATING FIRST DICTIONARY #########################

#Creting a dictionary with multiple values (elements) for each key (group of elements with the same parameters)
dict = defaultdict(list)
for k, v in zip(map_keys, map_lengh):
dict[k].append(v)

############ CREATING DICTIONARY WITH SUM UP VALUES ###############
“”" keys = set(k for k, _ in dict)
totals = {unique_key: sum(v for k, v in ds if k==unique_key)
for unique_key in keys}
“”"

OUT = 0

BOQ_grab data_7.dyn (39.2 KB)

BOQ_grab data_7.dyn (42.4 KB)

Found a solution… maybe not the most elegant one but It will do

3 Likes

do you know how to get the builtin parameters of all Revit categories without selecting any element or any element in views as this example?, for example get builtin parameters of elements of a category that do not exist in our project