Menu

Extracting specified entities and related PSets from one IFC to a new one

2022-10-06
2022-10-07
  • Jacob Hermansen

    Jacob Hermansen - 2022-10-06

    I have a case where I have a large IFC file in which I want to extract specific entities and their corresponding Psets and export them in a new IFC file. My approach is to iterate over all entities of the specified class and .add to the new file, but this does only extract the geometry and does not maintain its related psets..
    Various discussions points out that NewIFC.createIfcRelDefinesByProperties function does it, but my limited expertise with IfcOpenshell makes me hit rock bottom trying to make it work.

    I am using IfcOpenshell v0.7.0 and Python 3.10.7

    import ifcopenshell
    
    ## load model begin ##
    print('Loading the model...')
    ifc_file = 'model\file.ifc'
    model = ifcopenshell.open(ifc_file)
    
    Entity = "IfcFlowSegment"   
    
    products = model.by_type(Entity)
    Pipe = []
    for product in products:
        if product.is_a(Entity):
            Pipe.append(product)
    
    ## Generating new file for export ##  
    NewIfc = ifcopenshell.file(schema = model.schema)
    NewIfc.add(model.by_type('IfcProject')[0])
    
    
    ## Iterative writing of objects ##
    for i in range(len(Pipe)):
        NewIfc.add(products[i])
    
    
    NewIfc.write("V:/NewFile.ifc")
    print('Extrcation of ' + str(Entity) + '´s completed!')
    
     
  • Jacob Hermansen

    Jacob Hermansen - 2022-10-07

    I am able to obtain all psets, properties, and values from every instance of the specified entity, but I am not sure how to proceed on adding them to their respective objects in the new file

    ## Getting Psets of entities ##
    
    for i in range(len(products)):
        if products:
            obj = products[i] 
            for relDefinesByProperties in obj.IsDefinedBy:
                print([i])
                #print("[{0}]".format(relDefinesByProperties.RelatingPropertyDefinition.Name))
                PropertySetName = relDefinesByProperties.RelatingPropertyDefinition.Name
                print(PropertySetName)
                for prop in relDefinesByProperties.RelatingPropertyDefinition.HasProperties:
    
                    PropertyName = prop.Name
                    PropertyValue = prop.NominalValue.wrappedValue 
    
                    print ("{:<20} :{}".format(PropertyName,PropertyValue))
                print ("\n")
    
     

Log in to post a comment.