AttributeError: "str" object has no attribute "id"

edited February 26 in General

Hi!
I'm new IFC openshell and coding in general. Does anyone know why i get this error from my code.

Code

import ifcopenshell
import ifcopenshell.util.element as Element

file = ifcopenshell.open("\test.ifc")

walls = file.by_type("IfcWall")[0]

object_data = {}

for wall in walls:
    object_id = wall.id()
    object_data[object_id] = { 
        "ExpressID": wall.id(),
        "GlobalId": wall.GlobalId,
        "Class" : wall.is_a(),
        "PredefinedType": Element.get_predefined_type(wall),
        "Name": wall.Name,
        "Level": Element.get_container(wall).Name
        if Element.get_container(wall)
        else "",
        "ObjectType": Element.get_type(wall).Name
        if Element.get_type(wall)
        else "",
        "QuantitySets": Element.get_psets(wall, qtos_only=True),
        "PropertySets": Element.get_psets(wall, psets_only=True)
          }
import pprint
pp =pprint.PrettyPrinter()
pp.pprint(object_data)

Errorcode:
line 12, in
object_id = wall.id()
AttributeError: 'str' object has no attribute 'id'

Comments

  • newbie too...
    maybe file.id(wall)

  • @Bobob86 well, the line
    walls = file.by_type("IfcWall")[0]
    gives only the first IfcWall in the file (look at the 0) ...
    You need to get all the walls so delete the [0] and it should work ...

    steverugi
  • Yes, iterating over file.by_type("IfcWall")[0] iterates over attributes of a first wall found instead of iterating over all IfcWalls in the project.

Sign In or Register to comment.