IFC Attribuierung mittels Excelsheets
Verfasst: Mittwoch 4. Dezember 2024, 11:17
Hallo! Ich habe gerade begonnen mit der Unterstützung von Chat GDP mir ein Excel Export und Import-Skript für Blender BIM zu basteln. Der Export funktioniert. Beim Import bekomme ich ständig Indentation errors. Anbei das Skript. Vielleicht kann mir jemand einen Tip geben, woran es liegt. Wie bereits erwähnt sind das meine Anfänge und kenne mich nüsse aus.....
import bpy
from bpy import data as D
from bpy import context as C
from mathutils import *
from math import *
import ifcopenshell
import openpyxl
ifc_file_path = r"C:\Users\simon.engels\OneDrive - Geoconsult Group\TEMP\4739\Export\MSP\Baugrundmodell_Arbeitsstand_20241121.ifc"
excel_path = r"C:\Users\simon.engels\OneDrive - Geoconsult Group\TEMP\4739\Export\MSP\Baugrundmodell_Arbeitsstand_20241121.xlsx"
ifc_file = ifcopenshell.open(ifc_file_path)
wb = openpyxl.load_workbook(excel_path)
for sheet_name in wb.sheetnames:
sheet = wb[sheet_name]
headers = list(sheet.iter_rows(min_row=1, max_row=1, values_only=True))[0]
headers = [str(header).strip() for header in headers]
global_id_idx = headers.index("Global ID")
property_set = ifc_file.create_entity(
"IfcPropertySet",
Global Id=ifcopenshell.guid.new(),
Name=sheet_name
)
for row in sheet.iter_rows(min_row=2, values_only=True):
global_id = row[global_id_idx]
if not global_id:
continue
element = ifc_file.by_guid(global_id)
if not element:
continue
if not hasattr(element, "IsDefinedBy") or not element.IsDefinedBy:
element.IsDefinedBy = []
element.IsDefinedBy.append(
ifc_file.create_entity(
"IfcRelDefinesByProperties",
GlobalId=ifcopenshell.guid.new(),
RelatingPropertyDefinition=property_set,
RelatedObjects=[element]
)
)
for header, value in zip(headers, row):
if header != "Global ID" and value:
property_value = ifc_file.create_entity(
"IfcPropertySingleValue",
Name=header,
NominalValue=ifcopenshell.util.element.create_ifc_string(value)
)
property_set.HasProperties.append(property_value)
# Save the updated IFC file
output_path = r"C:\Users\simon.engels\OneDrive - Geoconsult Group\TEMP\4739\Export\MSP\Baugrundmodell_UPDATE.ifc"
ifc_file.write(output_path)
print(f"Updated IFC file saved at {output_path}")
import bpy
from bpy import data as D
from bpy import context as C
from mathutils import *
from math import *
import ifcopenshell
import openpyxl
ifc_file_path = r"C:\Users\simon.engels\OneDrive - Geoconsult Group\TEMP\4739\Export\MSP\Baugrundmodell_Arbeitsstand_20241121.ifc"
excel_path = r"C:\Users\simon.engels\OneDrive - Geoconsult Group\TEMP\4739\Export\MSP\Baugrundmodell_Arbeitsstand_20241121.xlsx"
ifc_file = ifcopenshell.open(ifc_file_path)
wb = openpyxl.load_workbook(excel_path)
for sheet_name in wb.sheetnames:
sheet = wb[sheet_name]
headers = list(sheet.iter_rows(min_row=1, max_row=1, values_only=True))[0]
headers = [str(header).strip() for header in headers]
global_id_idx = headers.index("Global ID")
property_set = ifc_file.create_entity(
"IfcPropertySet",
Global Id=ifcopenshell.guid.new(),
Name=sheet_name
)
for row in sheet.iter_rows(min_row=2, values_only=True):
global_id = row[global_id_idx]
if not global_id:
continue
element = ifc_file.by_guid(global_id)
if not element:
continue
if not hasattr(element, "IsDefinedBy") or not element.IsDefinedBy:
element.IsDefinedBy = []
element.IsDefinedBy.append(
ifc_file.create_entity(
"IfcRelDefinesByProperties",
GlobalId=ifcopenshell.guid.new(),
RelatingPropertyDefinition=property_set,
RelatedObjects=[element]
)
)
for header, value in zip(headers, row):
if header != "Global ID" and value:
property_value = ifc_file.create_entity(
"IfcPropertySingleValue",
Name=header,
NominalValue=ifcopenshell.util.element.create_ifc_string(value)
)
property_set.HasProperties.append(property_value)
# Save the updated IFC file
output_path = r"C:\Users\simon.engels\OneDrive - Geoconsult Group\TEMP\4739\Export\MSP\Baugrundmodell_UPDATE.ifc"
ifc_file.write(output_path)
print(f"Updated IFC file saved at {output_path}")