OSArch Community

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

  1. M

    @InformationWorker if you are getting errors like that, it suggests there is something fundamentally broken with your installation of IfcOpenshell. For example, does this code work for you?

    
    import ifcopenshell
    
    f = ifcopenshell.file()
    
    f.create_entity('IfcPerson')
    

    If not, try uninstall your IfcOpenShell and reinstall following the instructions here: https://blenderbim.org/docs-python/ifcopenshell-python/installation.html - also feel free to reach out for live help at https://osarch.org/chat where we can screenshare and solve it together.

  2. C

    How would I add an IfcWall to an existing IFC using the ifcopenshell.api? I could only find in the documentation how to create an entire IFC from scratch.

  3. C

    I believe that just like this:

    
    import ifcopenshell
    
    model = ifcopenshell.open('/path/to/your/model.ifc')
    
    wall = ifcopenshell.api.run('root.create_entity', model, ifc_class='IfcWall', predefined_type='SOLIDWALL')
    

    Have you had a look at the base ifcopenshell-python docs (not the API)?

  4. B
  5. C

    How does one delete an entire PropertySet?

  6. M
  7. G

    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,..\\..\\..\\..\\.......................
    
  1. Page 1
  2. 2

Login or Register to reply.