OSArch Community

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

  1. B

    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 <module>

    object_id = wall.id()

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

  2. T

    newbie too...

    maybe file.id(wall)

  3. M

    @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 ...

  4. A

    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.

Login or Register to reply.