简体   繁体   中英

Group data from two lists - REVIT API - IronPython

I'm creating a plugin for Revit (pyRevit) and I need the code to group the data in the output. I cannot use PANDAS as it does not work with IronPython and CLR.

Below I put the entire code and the desired output:

from Autodesk.Revit import DB

doc = __revit__.ActiveUIDocument.Document

# Create Filtered Element Collector 
collector = DB.FilteredElementCollector(doc)

#Create Filter
filter = DB.ElementCategoryFilter(DB.BuiltInCategory.OST_FlexPipeCurves)

#Apply Filter
flex_pipe = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements()

start_len = 0.0


#looping for all the elements
for flex_pipes in flex_pipe:
type_name = flex_pipes.Name
len_param = flex_pipes.Parameter[DB.BuiltInParameter.CURVE_ELEM_LENGTH]
if len_param:
        total_len = start_len + len_param.AsDouble()
        print('Description:\"{}\"  Length:\"{}\"'.format(type_name,total_len))



 **Current Output** 
     Description:"CABLE TYPE A"  Length:"10.00"
     Description:"CABLE TYPE A"  Length:"15.00"
     Description:"CABLE TYPE A"  Length:"20.00"
     Description:"CABLE TYPE B"  Length:"10.00"
     Description:"CABLE TYPE B"  Length:"15.00"
     Description:"CABLE TYPE B"  Length:"20.00"
     


 **Desired Output** 
     Description:"CABLE TYPE A"  Length:"45.00"
     Description:"CABLE TYPE B"  Length:"45.00"

Updade: I did it, after a hard work. This is the result. Thank you guys.

   # looping for all the elements
       for flex_pipes in flex_pipe:
       len_param = flex_pipes.Parameter[DB.BuiltInParameter.CURVE_ELEM_LENGTH]
       type_name = flex_pipes.Name
       if len_param:
          total_len = start_len + (len_param.AsDouble() * 0.3048)
          length.append(total_len)
          if type_name:
             name.append(type_name)

 x = zip(name, length)


 def getkey(item):
     return item[0]


  lista_final = sorted(x, key=getkey)

  output = []
  last = None
  for type, amount in lista_final:
      if type != last:
      output.append([type, 0])
             last = type
      output[-1][1] += amount


  for a, b in output:  # <-- this unpacks the tuple like a, b = (0, 1)
  print('ELEMENTO:\"{}\" - COMPRIMENTO:\"{} m"'.format(a, b))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM