0

My task is to find IfcQuantityArea values of all IfcWall in the project.ifc and export those values to .csv with another attributes such as GlobalId and Name.

The question is how I can "define" the result from def function, so I could set is as variable or list, so I could insert it into a column in my new .csv file?

I tried several ways, but as I print it, it looks fine, but I have no idea how to collect this values to my .csv file. Maybe there is another approach to count the IfcWall areas using some api functions? Any ideas both to python and ifcopenshell environment?

import ifcopenshell

def print_quantities(property_definition):
  if 'IfcElementQuantity' == property_definition.is_a():
    for quantity in property_definition.Quantities:
      if 'IfcQuantityArea' == quantity.is_a():
        print('Area value: ' + str(quantity.AreaValue))
  

model = ifcopenshell.open('D:/.../project-modified.ifc')
products = model.by_type('IfcWall')
for product in products:
  if product.IsDefinedBy:
    definitions = product.IsDefinedBy
    for definition in definitions:

      if 'IfcRelDefinesByProperties' == definition.is_a():
        property_definition = definition.RelatingPropertyDefinition
        print_quantities(property_definition)
      if 'IfcRelDefinesByType' == definition.is_a():
        type = definition.RelatingType
        if type.HasPropertySets:
          for property_definition in type.HasPropertySets:
            print_quantities(property_definition)
        
import csv

header = ['GlobalId', 'Name', 'TotalArea']

data = []
for wall in model.by_type('IfcWall'):
    row = [wall.GlobalId, wall.Name, AreaValue]
    data.append(row)

with open('D:/.../quantities.csv', 'w', encoding='UTF8', newline='') as f:
    writer = csv.writer(f)

    writer.writerow(header)

    writer.writerows(data)
    
        
  • Are you asking how to *return* a value from a function? – mkrieger1 Jul 27 '22 at 20:26
  • Exactly, but as I put return print_quantities it doesn’t give me the same results as it prints, basically no area values. – Karol Cheluszka Jul 28 '22 at 06:19
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 28 '22 at 08:49

0 Answers0