mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 05:46:51 +00:00
WIP fix issues in IFCCSV refactor. See #1222.
This commit is contained in:
@@ -7,6 +7,7 @@ classes = (
|
|||||||
operator.ExportIfcCsv,
|
operator.ExportIfcCsv,
|
||||||
operator.ImportIfcCsv,
|
operator.ImportIfcCsv,
|
||||||
operator.EyedropIfcCsv,
|
operator.EyedropIfcCsv,
|
||||||
|
operator.SelectCsvIfcFile,
|
||||||
prop.CsvProperties,
|
prop.CsvProperties,
|
||||||
ui.BIM_PT_ifccsv,
|
ui.BIM_PT_ifccsv,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,24 +9,25 @@ import tempfile
|
|||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AddCsvAttribute(bpy.types.Operator):
|
class AddCsvAttribute(bpy.types.Operator):
|
||||||
bl_idname = "bim.add_csv_attribute"
|
bl_idname = "bim.add_csv_attribute"
|
||||||
bl_label = "Add CSV Attribute"
|
bl_label = "Add CSV Attribute"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
attribute = bpy.context.scene.CsvProperties.csv_attributes.add()
|
attribute = context.scene.CsvProperties.csv_attributes.add()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class RemoveCsvAttribute(bpy.types.Operator):
|
class RemoveCsvAttribute(bpy.types.Operator):
|
||||||
bl_idname = "bim.remove_csv_attribute"
|
bl_idname = "bim.remove_csv_attribute"
|
||||||
bl_label = "Remove CSV Attribute"
|
bl_label = "Remove CSV Attribute"
|
||||||
index: bpy.props.IntProperty()
|
index: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
bpy.context.scene.CsvProperties.csv_attributes.remove(self.index)
|
context.scene.CsvProperties.csv_attributes.remove(self.index)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class ExportIfcCsv(bpy.types.Operator):
|
class ExportIfcCsv(bpy.types.Operator):
|
||||||
bl_idname = "bim.export_ifccsv"
|
bl_idname = "bim.export_ifccsv"
|
||||||
bl_label = "Export IFC to CSV"
|
bl_label = "Export IFC to CSV"
|
||||||
@@ -42,21 +43,26 @@ class ExportIfcCsv(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
import ifccsv
|
import ifccsv
|
||||||
|
|
||||||
|
props = context.scene.CsvProperties
|
||||||
self.filepath = bpy.path.ensure_ext(self.filepath, ".csv")
|
self.filepath = bpy.path.ensure_ext(self.filepath, ".csv")
|
||||||
ifc_file = ifcopenshell.open(bpy.context.scene.CsvProperties.csv_ifc_file)
|
if props.should_load_from_memory:
|
||||||
|
ifc_file = IfcStore.get_file()
|
||||||
|
else:
|
||||||
|
ifc_file = ifcopenshell.open(props.csv_ifc_file)
|
||||||
selector = ifcopenshell.util.selector.Selector()
|
selector = ifcopenshell.util.selector.Selector()
|
||||||
results = selector.parse(ifc_file, bpy.context.scene.CsvProperties.ifc_selector)
|
results = selector.parse(ifc_file, props.ifc_selector)
|
||||||
ifc_csv = ifccsv.IfcCsv()
|
ifc_csv = ifccsv.IfcCsv()
|
||||||
ifc_csv.output = self.filepath
|
ifc_csv.output = self.filepath
|
||||||
ifc_csv.attributes = [a.name for a in bpy.context.scene.CsvProperties.csv_attributes]
|
ifc_csv.attributes = [a.name for a in props.csv_attributes]
|
||||||
ifc_csv.selector = selector
|
ifc_csv.selector = selector
|
||||||
if bpy.context.scene.CsvProperties.csv_delimiter == "CUSTOM":
|
if props.csv_delimiter == "CUSTOM":
|
||||||
ifc_csv.delimiter = bpy.context.scene.CsvProperties.csv_custom_delimiter
|
ifc_csv.delimiter = props.csv_custom_delimiter
|
||||||
else:
|
else:
|
||||||
ifc_csv.delimiter = bpy.context.scene.CsvProperties.csv_delimiter
|
ifc_csv.delimiter = props.csv_delimiter
|
||||||
ifc_csv.export(ifc_file, results)
|
ifc_csv.export(ifc_file, results)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class ImportIfcCsv(bpy.types.Operator):
|
class ImportIfcCsv(bpy.types.Operator):
|
||||||
bl_idname = "bim.import_ifccsv"
|
bl_idname = "bim.import_ifccsv"
|
||||||
bl_label = "Import CSV to IFC"
|
bl_label = "Import CSV to IFC"
|
||||||
@@ -74,18 +80,35 @@ class ImportIfcCsv(bpy.types.Operator):
|
|||||||
|
|
||||||
ifc_csv = ifccsv.IfcCsv()
|
ifc_csv = ifccsv.IfcCsv()
|
||||||
ifc_csv.output = self.filepath
|
ifc_csv.output = self.filepath
|
||||||
ifc_csv.Import(bpy.context.scene.CsvProperties.csv_ifc_file)
|
ifc_csv.Import(context.scene.CsvProperties.csv_ifc_file)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class EyedropIfcCsv(bpy.types.Operator):
|
class EyedropIfcCsv(bpy.types.Operator):
|
||||||
bl_idname = "bim.eyedrop_ifccsv"
|
bl_idname = "bim.eyedrop_ifccsv"
|
||||||
bl_label = "Query Selected Items"
|
bl_label = "Query Selected Items"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
global_ids = []
|
global_ids = []
|
||||||
for obj in bpy.context.selected_objects:
|
for obj in context.selected_objects:
|
||||||
if hasattr(obj, "BIMObjectProperties") and obj.BIMObjectProperties.attributes.get("GlobalId"):
|
if hasattr(obj, "BIMObjectProperties") and obj.BIMObjectProperties.attributes.get("GlobalId"):
|
||||||
global_ids.append("#" + obj.BIMObjectProperties.attributes.get("GlobalId").string_value)
|
global_ids.append("#" + obj.BIMObjectProperties.attributes.get("GlobalId").string_value)
|
||||||
bpy.context.scene.CsvProperties.ifc_selector = "|".join(global_ids)
|
context.scene.CsvProperties.ifc_selector = "|".join(global_ids)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class SelectCsvIfcFile(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.select_csv_ifc_file"
|
||||||
|
bl_label = "Select CSV IFC File"
|
||||||
|
filename_ext = ".ifc"
|
||||||
|
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
||||||
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
|
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
context.scene.CsvProperties.csv_ifc_file = self.filepath
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
context.window_manager.fileselect_add(self)
|
||||||
|
return {"RUNNING_MODAL"}
|
||||||
|
|||||||
@@ -18,10 +18,14 @@ class CsvProperties(PropertyGroup):
|
|||||||
ifc_selector: StringProperty(default="", name="IFC Selector")
|
ifc_selector: StringProperty(default="", name="IFC Selector")
|
||||||
csv_attributes: CollectionProperty(name="CSV Attributes", type=StrProperty)
|
csv_attributes: CollectionProperty(name="CSV Attributes", type=StrProperty)
|
||||||
csv_delimiter: EnumProperty(
|
csv_delimiter: EnumProperty(
|
||||||
items=[(";", ";", ""), (",", ",", ""), (".", ".", ""), ("CUSTOM", "Custom", ""),],
|
items=[
|
||||||
|
(";", ";", ""),
|
||||||
|
(",", ",", ""),
|
||||||
|
(".", ".", ""),
|
||||||
|
("CUSTOM", "Custom", ""),
|
||||||
|
],
|
||||||
name="IFC CSV Delimiter",
|
name="IFC CSV Delimiter",
|
||||||
default=",",
|
default=",",
|
||||||
)
|
)
|
||||||
csv_custom_delimiter: StringProperty(default="", name="Custom Delimiter")
|
csv_custom_delimiter: StringProperty(default="", name="Custom Delimiter")
|
||||||
should_load_from_memory: BoolProperty(default=False, name="Load from Memory")
|
should_load_from_memory: BoolProperty(default=False, name="Load from Memory")
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,20 @@ class BIM_PT_ifccsv(Panel):
|
|||||||
scene = context.scene
|
scene = context.scene
|
||||||
props = scene.CsvProperties
|
props = scene.CsvProperties
|
||||||
|
|
||||||
if IfcStore.get_file():
|
if IfcStore.get_file():
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(props, "should_load_from_memory")
|
row.prop(props, "should_load_from_memory")
|
||||||
|
|
||||||
if not IfcStore.get_file() or not props.should_load_from_memory:
|
if not IfcStore.get_file() or not props.should_load_from_memory:
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(props, "csv_ifc_file")
|
row.prop(props, "csv_ifc_file")
|
||||||
row.operator("bim.import_ifccsv", icon="FILE_FOLDER", text="")
|
row.operator("bim.select_csv_ifc_file", icon="FILE_FOLDER", text="")
|
||||||
row = layout.row(align=True)
|
|
||||||
row.prop(props, "ifc_selector")
|
row = layout.row(align=True)
|
||||||
row.operator("bim.eyedrop_ifccsv", icon="EYEDROPPER", text="")
|
row.prop(props, "ifc_selector")
|
||||||
|
row.operator("bim.eyedrop_ifccsv", icon="EYEDROPPER", text="")
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.label(text="Add IFC attributes to filter", icon="FILE_BLANK")
|
|
||||||
row.operator("bim.add_csv_attribute")
|
row.operator("bim.add_csv_attribute")
|
||||||
|
|
||||||
for index, attribute in enumerate(props.csv_attributes):
|
for index, attribute in enumerate(props.csv_attributes):
|
||||||
@@ -40,11 +40,10 @@ class BIM_PT_ifccsv(Panel):
|
|||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(props, "csv_delimiter")
|
row.prop(props, "csv_delimiter")
|
||||||
|
|
||||||
if(props.csv_delimiter == 'CUSTOM'):
|
if props.csv_delimiter == "CUSTOM":
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(props, "csv_custom_delimiter")
|
row.prop(props, "csv_custom_delimiter")
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.operator("bim.export_ifccsv", icon="EXPORT")
|
row.operator("bim.export_ifccsv", icon="EXPORT")
|
||||||
row.operator("bim.import_ifccsv", icon="IMPORT")
|
row.operator("bim.import_ifccsv", icon="IMPORT")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user