I have started using BlenderBIM Bonsai since a week ago. I wanted to update IFC files data parameters. I have succeeded in updating the parameters inside the IFC file and then save the IFC file with the new parameters using python scripts. That process will take between 10 seconds and a couple of minutes based on the file size. I found that the more objects are available, the longer it will take to complete the task ( the time of competition of each object will elongate with the increase in object quantity).
Ex :
- File with 100 objects, then each object to be updated will require something around 0.02 seconds.
2: File with 2000 objects, then each object to be updated will require something around 1.3 seconds.
However, when I tried to do so with files that contain huge number of objects ( more than 10 k) , each object will require more than 5 seconds. For a file the contains 23 k objects each object will require around 14.6 seconds, so that to update the file I do need 4.2 days :).
If someone can support/advise me about the optimum way to update the data using BlenderBIM/Bonsai regardless of the file size or number of objects.
Below is the code I am using:
Get all the from the SQL Server
query = ("""SELECT '0, ' + LEFT([filename],23) + '.dgn, Design Model:' + cast(cast([Id] as bigint) as varchar(100)) as FileID,
[Trade],[Sub Trade],[Construction Zone Number],[Room Number],[Level 1],[Level 2],[Level 3],[Level 4],[Level 6],[BIM Code],
[BIM Description],[CSI Code],[Unit],cast(cast([Quantity] as bigint) as varchar(100)) as Quantity,[Electrical Zone],[HVAC Zone],[Fire Fighting Zone],[Fire Evacuation Zone],[Nominal Size],
[Asset Code],[Function],[Circuit Number],[Equipment Mechanical Interface],[Equipment Electrical Interface],[Equipment Parent],[Fire Resistance Rating],
[Control Circuit Number],[Asset Code 2],[Asset Code 3] FROM [Tandem].[dbo].[myTable] where [filename] like '%"""+ Modlenamex + "%'")
df = pd.read_sql(query, cnxn)
if df.empty:
print('The selected file has no records in the MTO database table or you have not selected all items!')
bpy.ops.bim.save_project(filepath="C:\\Users\\far\\Desktop\\BIM\\Blender IFC\\" + Modlenamex + ".ifc", should_save_as=True, save_as_invoked=True)
print ('Finiiiiiiiiished Running the Code')
else:
for obj in selection:
obj.select_set(True)
# some exporters only use the active object
view_layer.objects.active = obj
name = bpy.path.clean_name(obj.name)
bpy.ops.bim.enable_editing_attributes(obj=obj.name)
ModelObjectId = bpy.data.objects[obj.name].BIMAttributeProperties.attributes[2].string_value
myidDF = df.query('FileID == **@ModelObjectId**')
if myidDF.empty:
print('The selected object ', ModelObjectId,' has no records in the MTO Database File!')
else:
##### Add the header Paramter #####
bpy.ops.bim.add_pset(obj=obj.name, obj_type="Object")
bpy.data.objects[obj.name].PsetProperties.active_pset_name = "Graphical_Parameter"
bpy.ops.bim.disable_pset_editing(obj=obj.name, obj_type="Object")
# print (bpy.data.objects[obj.name].PsetProperties.active_pset_name)
# print(bpy.data.objects[obj.name].PsetProperties.active_pset_id)
bpy.ops.bim.enable_pset_editing(pset_id=0, pset_name="Graphical_Parameter", pset_type="PSET", obj=obj.name, obj_type="Object")
# Loop to add the Graphical Data related to each object ID
for column in myidDF:
# print (column.count)
bpy.data.objects[obj.name].PsetProperties.prop_name = column
if myidDF.iloc[0][column] is None:
bpy.data.objects[obj.name].PsetProperties.prop_value = "-"
bpy.ops.bim.add_proposed_prop(obj=obj.name, obj_type="Object", prop_name=column, prop_value="-")
else:
bpy.data.objects[obj.name].PsetProperties.prop_value = myidDF.iloc[0][column]
bpy.ops.bim.add_proposed_prop(obj=obj.name, obj_type="Object", prop_name=column, prop_value=myidDF.iloc[0][column])
#Save the add grpahical data to the object
bpy.ops.bim.edit_pset(obj=obj.name, obj_type="Object", pset_id=0)
obj.select_set(False)
#bpy.ops.bim.save_project(filepath="C:\\Users\\far\\Desktop\\BIM\\Blender IFC\\", Modlenamex,".ifc", should_save_as=True, save_as_invoked=True)
bpy.ops.bim.save_project(filepath="C:\\Users\\far\\Desktop\\BIM\\Blender IFC\\" + Modlenamex + ".ifc",should_save_as=True, save_as_invoked=True)
print ('This is the total selected object: ', len(bpy.context.selected_objects))
print ('Finiiiiiiiiished Running the Code')