mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 11:18:18 +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
|
@persistent
|
||||||
def loadIfcStore(scene):
|
def loadIfcStore(scene):
|
||||||
@@ -58,17 +69,7 @@ def loadIfcStore(scene):
|
|||||||
IfcStore.guid_map = (
|
IfcStore.guid_map = (
|
||||||
{k: bpy.data.objects.get(v) for k, v in json.loads(props.guid_map).items()} if props.id_map else {}
|
{k: bpy.data.objects.get(v) for k, v in json.loads(props.guid_map).items()} if props.id_map else {}
|
||||||
)
|
)
|
||||||
|
purge_module_data()
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
@persistent
|
@persistent
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import json
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
import tempfile
|
import tempfile
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
from blenderbim.bim.handler import purge_module_data
|
||||||
|
|
||||||
|
|
||||||
class AddCsvAttribute(bpy.types.Operator):
|
class AddCsvAttribute(bpy.types.Operator):
|
||||||
@@ -78,13 +79,19 @@ class ImportIfcCsv(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
import ifccsv
|
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 = ifccsv.IfcCsv()
|
||||||
ifc_csv.output = self.filepath
|
ifc_csv.output = self.filepath
|
||||||
if props.csv_delimiter == "CUSTOM":
|
if props.csv_delimiter == "CUSTOM":
|
||||||
ifc_csv.delimiter = props.csv_custom_delimiter
|
ifc_csv.delimiter = props.csv_custom_delimiter
|
||||||
else:
|
else:
|
||||||
ifc_csv.delimiter = props.csv_delimiter
|
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"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -131,8 +131,7 @@ class IfcCsv:
|
|||||||
results.update([p.Name for p in element.Quantities])
|
results.update([p.Name for p in element.Quantities])
|
||||||
return ["{}.{}".format(pset_qto_name, n) for n in results]
|
return ["{}.{}".format(pset_qto_name, n) for n in results]
|
||||||
|
|
||||||
def Import(self, ifc):
|
def Import(self, ifc_file):
|
||||||
ifc_file = ifcopenshell.open(ifc)
|
|
||||||
with open(self.output, newline="", encoding="utf-8") as f:
|
with open(self.output, newline="", encoding="utf-8") as f:
|
||||||
reader = csv.reader(f, delimiter=self.delimiter)
|
reader = csv.reader(f, delimiter=self.delimiter)
|
||||||
headers = []
|
headers = []
|
||||||
@@ -149,7 +148,6 @@ class IfcCsv:
|
|||||||
if i == 0:
|
if i == 0:
|
||||||
continue # Skip GlobalId
|
continue # Skip GlobalId
|
||||||
element = IfcAttributeSetter.set_element_key(ifc_file, element, headers[i], value)
|
element = IfcAttributeSetter.set_element_key(ifc_file, element, headers[i], value)
|
||||||
ifc_file.write(ifc)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -174,4 +172,6 @@ if __name__ == "__main__":
|
|||||||
elif getattr(args, "import"):
|
elif getattr(args, "import"):
|
||||||
ifc_csv = IfcCsv()
|
ifc_csv = IfcCsv()
|
||||||
ifc_csv.output = args.csv
|
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