Ifcopenshell-Python beginner

I am a beginner and want to know related quick getting started articles about Ifcopenshell-Python, thx

Comments

  • Hey @shanmama - did you see some of the links and source code posted here?

    Is there a particular type of data you are trying to extract? Is it geometry? Is it an attribute? Is it a property set? If you're interested, in an online meeting I can do a screenshare and teach a bit about IfcOpenShell-python. Would you participate?

  • Dear all,
    Please Help....
    I am a beginner in using python, IFC and BlenderBim add on. I am trying to do the following;
    1. extract the quantities, material type of walls and floors and place them into a dictionary
    2. extract the quantities of external walls and group them based on their cardinal orientation (south, north, west, etc) of each wall. I do not know if it's workable.

    For the quantities I tried the sample code on https://thinkmoult.com/using-ifcopenshell-parse-ifc-files-python.html but I get an attribute error (as shown below). I just hope I am doing the right thing.

  • @polsonmila at first glance it looks as if you're getting an AttributeError because you're attempting to access quantity.lengthValue instead of quantity.LengthValue -- > the properties all use CamelCase

  • edited November 22

    Also, you need to loop through each Wall in your Walls list before you try to access .isDefinedBy.
    something like:

    walls = [] # your list of walls
    for wall in walls:
            for definition in wall.IsDefinedBy:
    
  • @vpajic Thank you for the response. I will try to do that and give you an update.

  • BTW: if you post code do not use a screen shot but copy the code and use code tags instead. It looks like in the post of vpajic. If you post a screen shot noone can copy and test your code.

    cheers bernd

  • edited November 23

    am grateful for the help
    After reading through the https://wiki.osarch.org/index.php?title=IfcOpenShell_code_examples
    I was able to at least use the sample code to extract the wall pset as dictionary.

    #These are the imports I am using
    import ifcopenshell
    import ifcopenshell.util
    from ifcopenshell.util.selector import Selector
    from ifcopenshell import util
    import ifcopenshell.util.pset
    import ifcopenshell.util.element
    import pandas as pd
    
    # The IFC file I am using as attached
    ifc = ifcopenshell.open('Duplex3.ifc')
    selector = Selector()
    
    # The walls and slab using the by_type function
    walls = ifc.by_type('IfcWall')
    slabs = ifc.by_type('IfcSlab')
    
    # The iterations for the psets I did.
    for wall in my_walls:
    wall_details = wall.get_info()
    for wall in walls:
    pset_wall = ifcopenshell.util.element.get_psets(wall)
    

    NOTE: I am trying to extract the quantities of Walls and Slabs and place them in a dataframe.
    I want these to have their GUID.
    I would also like to group all the Walls external walls based on their Cardinal points (south, north, etc)
    once again thank you for your anticipated responses.

  • edited November 23

    @vpajic said:
    Also, you need to loop through each Wall in your Walls list before you try to access .isDefinedBy.
    something like:

        walls = [] # your list of walls
    for wall in walls:
            for definition in wall.IsDefinedBy:
    

    NOTE: I am trying to extract the quantities of Walls and Slabs and place them in a dataframe.
    I want these to have their GUID.
    I would also like to group all the Walls external walls based on their Cardinal points (south, north, etc)
    once again thank you for your anticipated responses.

  • @vpajic Thank you. I am relatively new to both Python and IfcOpenshell. I am now exploring my way through (as I go through the Wiki.osarch.org tutorials. I was able use the get_info and loop through (as shown below). But I as you suggested, I also observed that I could loop through the wall list from the wall.by_type function call. I will work on it so that I can try accessing the IsDefinedBy.
    Well this is how far I have gone.

    import ifcopenshell
    import pandas as pd
    m = ifcopenshell.open("data/Duplex_A.ifc")
    #m = ifcopenshell.open("../data/231110AC-11-Smiley-West-04-07-2007.ifc")
    walls = m.by_type('IfcWall')
    #print (walls)
    #count = 0
    for wall in walls:
        #count += 1
        wall_details = wall.get_info()
        #print(wall_details)
        wall_details_edit = {str(key): str(value) for key, value in wall_details.items()}
        #print(wall_details_edit)
        wall_details_edit_df = pd.DataFrame(wall_details_edit, index = [0])
        print(wall_details_edit_df)    
    #print(count)
    
  • @vpajic Thank you for your comment I still need help...
    @Moult and @bernd kindly assist.
    I am relatively new to both Python and IfcOpenshell. I am now exploring my way through (as I go through the Wiki.osarch.org tutorials. I was able use the get_info and loop through (as shown below). But I as @vpajic suggested, I also observed that I could loop through the wall list from the wall.by_type function call. I will work on it so that I can try accessing the IsDefinedBy.
    Well, this is how far I have gone.
    I have been able to have the loop through to get the property set of one wall using the IsDefinedBy procedure. But I could not access the Quantities. Please, can someone help me to identify where I am getting things wrong?

    '''I am trying to access all the propeties and quantities of the walls
    using an IFC 2x3 file format but???? please help'''
    
    ifc = ifcopenshell.open('Duplex3.ifc')
    #the walls from the model
    walls = ifc.by_type('IfcWall')
    
    #the single wall I am considering since the loop for properties has no IsDefinedBy
    wall_1 = walls[0]
    a = wall_1.IsDefinedBy
    print(a)
    
    '''the for loop I used to track the inverse IsDefineBy as in the tutorials
    all went well and I am still exploring''' 
    for i in a:
        if i.is_a('IfcRelDefinesByProperties'):
            a_property_set = i.RelatingPropertyDefinition
            #print(a_property_set.Name) # Might return Pset_WallCommon
            for property in a_property_set.HasProperties:
                if property.is_a('IfcPropertySingleValue'):
                    #print(property.Name)
                    print(property.NominalValue.wrappedValue)
    
    '''this is the point where I am stuck, I have tried many approaches but I couldn't get the Quantities of the wall following the tutorial'''
    for i in a:
        #if i.is_a('IfcRelDefinesByProperties'):
        a_property_set = i.RelatingPropertyDefinition
        if property.is_a('IfcElementQuantity'):
            print(property.Name)
            for quantity in property.Quantities:
                print(quantity.Name)
                if quantity.is_a('IfcQuantityLength'):
                    print(quantity.LengthValue)
    
  • @polsonmila - i would heartily recommend having a look at . Using the console in blender will allow you to explore the commands and structure of ifcopenshell more intuitively.

    bruno_perdigao
  • In your last example, it seems to me you are trying to access property.is_a('IfcElementQuantity'): without having first defined 'property'

Sign In or Register to comment.