I'm trying to create a script for blenderBIM, that edits a custom property set. My coding experience is very limited as I'm an architect so please keep in mind I'm new to this!
I want the script to check for each Building Story and enter a custom value into a property set field "Geschosscode" in the Pset "Spezifisch".
The Pset is already existing with a placeholder "--", the script just needs to overwrite the values with the correct codes. The code should be corresponding to the Building Story, for example: The Building Story "Untergeschoss" should recieve the code entry "UG01", but the next Building Story "Erdgeschoss" should recieve "EG00".
The problem here is, that it works to run without error, but it only adds the code "OG04", which is the last entry, to the selected Building Story. It should add the right codes to all Storeys, no matter which one is currently selected.
This is the code I have so far, I think I have a logic issue, any help is highly appreciated:
import bpy
import blenderbim.bim.ifc
ifc = blenderbim.bim.ifc.IfcStore().get_file()
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
## define the globalIDs for each level
level_global_ids = {
"Untergeschoss": "2LiJvusYaHxODNN62wEaPg",
"Erdgeschoss": "2UCKF9sYaHxODNN62wEaPg",
"1_Obergeschoss": "2aK8mdsYaHxODNN62wEaPg",
"2_Obergeschoss": "2aK8r2sYaHxODNN62wEaPg",
"3_Obergeschoss": "2mvNausYaHxODNN62wEaPg",
"4_Obergeschoss": "3FOkb0tj0HxODNN62wEaPg"
}
## define the psetIDs for each level
level_pset_ids = {
"Untergeschoss": 171,
"Erdgeschoss": 297,
"1_Obergeschoss": 374,
"2_Obergeschoss": 439,
"3_Obergeschoss": 504,
"4_Obergeschoss": 616
}
## define the pset values to enter for each psetID
storey_codes_by_pset_id = {
171: "UG01",
297: "EG00",
374: "OG01",
439: "OG02",
504: "OG03",
616: "OG04"
}
## loop over each BuildingStorey object and set the corresponding value / i think the issue is here
for level, pset_id in level_pset_ids.items():
obj_name = f"IfcBuildingStorey/{level}"
global_id = level_global_ids[level]
bpy.ops.bim.enable_pset_editing(pset_id=pset_id, obj=obj_name, obj_type="Object")
## Create a new element, code didnt run without this (?)
element = bpy.context.scene.AddEditProperties.add()
element.pset_name = "Spezifisch"
element.property_name = "Geschosscode"
element.string_value = storey_codes_by_pset_id[pset_id]
element.primary_measure_type = 'IfcGloballyUniqueId'
element.template_type = 'IfcPropertySingleValue'
bpy.ops.bim.add_edit_custom_property()
bpy.ops.bim.disable_pset_editing(obj=obj_name, obj_type="Object")
bpy.context.scene.AddEditProperties.clear()