mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
You can now import and export IFCCSV to the current file in memory without writing to disk
This commit is contained in:
@@ -46,6 +46,17 @@ def subscribe_to(object, data_path, callback):
|
||||
},
|
||||
)
|
||||
|
||||
def purge_module_data():
|
||||
from blenderbim.bim import modules
|
||||
|
||||
for module in modules.values():
|
||||
if not module:
|
||||
continue
|
||||
try:
|
||||
getattr(getattr(module, "data"), "Data").purge()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
@persistent
|
||||
def loadIfcStore(scene):
|
||||
@@ -58,17 +69,7 @@ def loadIfcStore(scene):
|
||||
IfcStore.guid_map = (
|
||||
{k: bpy.data.objects.get(v) for k, v in json.loads(props.guid_map).items()} if props.id_map else {}
|
||||
)
|
||||
|
||||
# Purge data cache
|
||||
from blenderbim.bim import modules
|
||||
|
||||
for module in modules.values():
|
||||
if not module:
|
||||
continue
|
||||
try:
|
||||
getattr(getattr(module, "data"), "Data").purge()
|
||||
except AttributeError:
|
||||
pass
|
||||
purge_module_data()
|
||||
|
||||
|
||||
@persistent
|
||||
|
||||
@@ -7,6 +7,7 @@ import json
|
||||
import webbrowser
|
||||
import tempfile
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from blenderbim.bim.handler import purge_module_data
|
||||
|
||||
|
||||
class AddCsvAttribute(bpy.types.Operator):
|
||||
@@ -78,13 +79,19 @@ class ImportIfcCsv(bpy.types.Operator):
|
||||
def execute(self, context):
|
||||
import ifccsv
|
||||
|
||||
props = context.scene.CsvProperties
|
||||
if props.should_load_from_memory:
|
||||
ifc_file = IfcStore.get_file()
|
||||
else:
|
||||
ifc_file = ifcopenshell.open(props.csv_ifc_file)
|
||||
ifc_csv = ifccsv.IfcCsv()
|
||||
ifc_csv.output = self.filepath
|
||||
if props.csv_delimiter == "CUSTOM":
|
||||
ifc_csv.delimiter = props.csv_custom_delimiter
|
||||
else:
|
||||
ifc_csv.delimiter = props.csv_delimiter
|
||||
ifc_csv.Import(context.scene.CsvProperties.csv_ifc_file)
|
||||
ifc_csv.Import(ifc_file)
|
||||
purge_module_data()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -131,8 +131,7 @@ class IfcCsv:
|
||||
results.update([p.Name for p in element.Quantities])
|
||||
return ["{}.{}".format(pset_qto_name, n) for n in results]
|
||||
|
||||
def Import(self, ifc):
|
||||
ifc_file = ifcopenshell.open(ifc)
|
||||
def Import(self, ifc_file):
|
||||
with open(self.output, newline="", encoding="utf-8") as f:
|
||||
reader = csv.reader(f, delimiter=self.delimiter)
|
||||
headers = []
|
||||
@@ -149,7 +148,6 @@ class IfcCsv:
|
||||
if i == 0:
|
||||
continue # Skip GlobalId
|
||||
element = IfcAttributeSetter.set_element_key(ifc_file, element, headers[i], value)
|
||||
ifc_file.write(ifc)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -174,4 +172,6 @@ if __name__ == "__main__":
|
||||
elif getattr(args, "import"):
|
||||
ifc_csv = IfcCsv()
|
||||
ifc_csv.output = args.csv
|
||||
ifc_csv.Import(args.ifc)
|
||||
ifc_file = ifcopenshell.open(args.ifc)
|
||||
ifc_csv.Import(ifc_file)
|
||||
ifc_file.write(args.ifc)
|
||||
|
||||
Reference in New Issue
Block a user