Package IFCCSV with BlenderBIM, with UI to import export CSV IFC data

This commit is contained in:
Dion Moult
2020-04-26 14:41:38 +10:00
parent 753fdae0d4
commit cbfd41ad28
5 changed files with 109 additions and 0 deletions
+7
View File
@@ -157,7 +157,14 @@ endif
cp -r dist/working/*.xsd dist/blenderbim/libs/site/packages/bcfplugin/schemas/
rm -rf dist/working
mkdir dist/working
cd dist/working && wget https://files.pythonhosted.org/packages/18/4d/8d522136c37d9e1ea74062b41b8d5e1318ebf45063ae46ce72ed60af223b/lark-parser-0.8.5.tar.gz
cd dist/working && tar -xzvf lark-parser*
cp -r dist/working/lark-parser-0.8.5/lark dist/blenderbim/libs/site/packages/
rm -rf dist/working
cd dist/blenderbim/libs/site/packages/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcdiff/ifcdiff.py
cd dist/blenderbim/libs/site/packages/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifccsv/ifccsv.py
cd dist/blenderbim && sed -i "s/999999/$(VERSION)/" __init__.py
cd dist && zip -r blender28-bim-$(VERSION)-$(PLATFORM).zip ./*
@@ -103,6 +103,10 @@ if bpy is not None:
operator.RemovePropertyTemplate,
operator.AddSectionPlane,
operator.RemoveSectionPlane,
operator.AddCsvAttribute,
operator.RemoveCsvAttribute,
operator.ExportIfcCsv,
operator.ImportIfcCsv,
prop.StrProperty,
prop.Classification,
prop.ClassificationReference,
@@ -138,6 +142,7 @@ if bpy is not None:
ui.BIM_PT_psets,
ui.BIM_PT_classifications,
ui.BIM_PT_search,
ui.BIM_PT_ifccsv,
ui.BIM_PT_bcf,
ui.BIM_PT_owner,
ui.BIM_PT_context,
@@ -2010,3 +2010,68 @@ class RemoveSectionPlane(bpy.types.Operator):
bpy.data.node_groups.remove(bpy.data.node_groups.get('Section Override'))
bpy.data.node_groups.remove(bpy.data.node_groups.get('Section Compare'))
bpy.ops.object.delete({"selected_objects": [bpy.context.active_object]})
class AddCsvAttribute(bpy.types.Operator):
bl_idname = 'bim.add_csv_attribute'
bl_label = 'Add CSV Attribute'
def execute(self, context):
attribute = bpy.context.scene.BIMProperties.csv_attributes.add()
return {'FINISHED'}
class RemoveCsvAttribute(bpy.types.Operator):
bl_idname = 'bim.remove_csv_attribute'
bl_label = 'Remove CSV Attribute'
index: bpy.props.IntProperty()
def execute(self, context):
bpy.context.scene.BIMProperties.csv_attributes.remove(self.index)
return {'FINISHED'}
class ExportIfcCsv(bpy.types.Operator):
bl_idname = 'bim.export_ifccsv'
bl_label = 'Export IFC to CSV'
filename_ext = '.csv'
filepath: bpy.props.StringProperty(subtype='FILE_PATH')
def invoke(self, context, event):
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, '.csv')
WindowManager = context.window_manager
WindowManager.fileselect_add(self)
return {'RUNNING_MODAL'}
def execute(self, context):
import ifccsv
self.filepath = bpy.path.ensure_ext(self.filepath, '.csv')
ifc_selector_parser = ifccsv.IfcSelectorParser()
ifc_selector_parser.ifc = bpy.context.scene.BIMProperties.ifc_file
ifc_selector_parser.query = bpy.context.scene.BIMProperties.ifc_selector
ifc_selector_parser.parse()
ifc_csv = ifccsv.IfcCsv()
ifc_csv.output = self.filepath
ifc_csv.attributes = [a.name for a in bpy.context.scene.BIMProperties.csv_attributes]
ifc_csv.export(ifc_selector_parser.results)
return {'FINISHED'}
class ImportIfcCsv(bpy.types.Operator):
bl_idname = 'bim.import_ifccsv'
bl_label = 'Import CSV to IFC'
filename_ext = '.csv'
filepath: bpy.props.StringProperty(subtype='FILE_PATH')
def invoke(self, context, event):
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, '.csv')
WindowManager = context.window_manager
WindowManager.fileselect_add(self)
return {'RUNNING_MODAL'}
def execute(self, context):
import ifccsv
ifc_csv = ifccsv.IfcCsv()
ifc_csv.output = self.filepath
ifc_csv.Import(bpy.context.scene.BIMProperties.ifc_file)
return {'FINISHED'}
@@ -850,6 +850,8 @@ class BIMProperties(PropertyGroup):
active_property_set_template: PointerProperty(type=PropertySetTemplate)
property_templates: CollectionProperty(name='Property Templates', type=PropertyTemplate)
should_section_selected_objects: BoolProperty(name="Section Selected Objects", default=False)
ifc_selector: StringProperty(default='', name='IFC Selector')
csv_attributes: CollectionProperty(name='CSV Attributes', type=StrProperty)
class BCFProperties(PropertyGroup):
+30
View File
@@ -648,6 +648,36 @@ class BIM_PT_search(Panel):
row.operator('bim.colour_by_pset', text='', icon='BRUSH_DATA')
class BIM_PT_ifccsv(Panel):
bl_label = "IFC CSV"
bl_idname = "BIM_PT_ifccsv"
bl_options = {'DEFAULT_CLOSED'}
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
props = scene.BIMProperties
row = layout.row()
row.prop(props, 'ifc_selector')
row = layout.row()
row.operator('bim.add_csv_attribute')
for index, attribute in enumerate(props.csv_attributes):
row = layout.row(align=True)
row.prop(attribute, 'name', text='')
row.operator('bim.remove_csv_attribute', icon='X', text='').index = index
row = layout.row(align=True)
row.operator('bim.export_ifccsv', icon='EXPORT')
row.operator('bim.import_ifccsv', icon='IMPORT')
class BIM_PT_bcf(Panel):
bl_label = "BIM Collaboration Format"
bl_idname = "BIM_PT_bcf"