IfcOpenShell, how to add a new property and value to an object?

2»

Comments

  • edited June 2023

    Hi,

    @Moult said:
    In IFC, attributes are fixed. If you want to add arbitrary properties, use property sets, not attributes. This is as @Coen has explained. However, there is a simpler method using the IfcOpenShell API.

    import ifcopenshell
    import ifcopenshell.api
    ifc = ifcopenshell.open('path\to_your\ifc_file')
    element = ifc.by_type("IfcElement")[0] # Just as an example, you will need to select the elements you want to add properties to yourself.
    pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Your Property Set Name")
    ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"foo": "foobar", "foo2": "foobaz"})
    

    this code is not working for me, I don't have much experience with ifc.

    Im trying to assign parameters coming from excel file.

    f = ifcopenshell.open(ifc_path)
    df = pd.read_excel(xls_path), sheet_name="CONCRETE")
    for index, row in df.iterrows():
        ifcguid = row['IfcGUID']
        el = f.by_id(ifcguid) 
        pset = ifcopenshell.api.run("pset.add_pset", f, product=el, name="Pset_AsBuilt")
        ifcopenshell.api.run("pset.edit_pset", f, pset=pset, properties=row)
    f.write(ifc_path)
    

    and it looks like they do get assigned to elements but they are not visible in bim viewer/blender.

    this is ifc file after editing. for example:

    #1069189=IFCPROPERTYSINGLEVALUE('Product Manufacture Name',$,IFCLABEL('40MPa Aquron'),$);
    #1069176=IFCPROPERTYSET('1KvRowVMrEIfpEJA8$4jLm',#1069175,'Pset_AsBuilt',$,(#1069179,#1069180,#1069181,#1069182,#1069183,#1069184,#1069185,#1069186,#1069187,#1069188,#1069189,#1069190,#1069191));
    #1069177=IFCOWNERHISTORY(#192,#188,.READWRITE.,.ADDED.,1686207125,#192,#188,1686207125);
    #1069178=IFCRELDEFINESBYPROPERTIES('3S7ICTkE9BIBEDyYqYj8K7',#1069177,$,$,(#8997),#1069176);
    #8997=IFCSLAB('0e3zm5Y85BhfXSflZpYTEV',#193,'Default Slab','1,..\\..\\..\\..\\.......................
    
Sign In or Register to comment.