diff --git a/src/ifcblenderexport/io_export_ifc/__init__.py b/src/ifcblenderexport/io_export_ifc/__init__.py index 680446fd6e..d43945ce82 100644 --- a/src/ifcblenderexport/io_export_ifc/__init__.py +++ b/src/ifcblenderexport/io_export_ifc/__init__.py @@ -32,6 +32,8 @@ classes = ( operator.AssignSweptSolidProfile, operator.AssignSweptSolidExtrusion, operator.AssignPset, + operator.UnassignPset, + operator.AddPset, operator.RemovePset, operator.GenerateGlobalId, operator.AddAttribute, @@ -39,6 +41,7 @@ classes = ( operator.QuickProjectSetup, ui.BIMProperties, ui.Attribute, + ui.Pset, ui.ObjectProperties, ui.MaterialProperties, ui.MeshProperties, diff --git a/src/ifcblenderexport/io_export_ifc/export_ifc.py b/src/ifcblenderexport/io_export_ifc/export_ifc.py index f8672b35c4..fa7c19c9d7 100644 --- a/src/ifcblenderexport/io_export_ifc/export_ifc.py +++ b/src/ifcblenderexport/io_export_ifc/export_ifc.py @@ -271,11 +271,12 @@ class IfcParser(): if object.name in self.qtos: self.rel_defines_by_qto.setdefault(object.name, []).append(product) + for pset in object.ObjectProperties.psets: + self.rel_defines_by_pset.setdefault( + '{}/{}'.format(pset.name, pset.file), []).append(product) + for key in object.keys(): - if key[0:5] == 'Pset_': - self.rel_defines_by_pset.setdefault( - '{}/{}'.format(key, object[key]), []).append(product) - elif key[0:3] == 'Doc': + if key[0:3] == 'Doc': self.rel_associates_document_object.setdefault( object[key], []).append(product) elif key[0:5] == 'Class': @@ -651,8 +652,8 @@ class IfcParser(): 'location': object.location, 'up_axis': object.matrix_world.to_quaternion() @ Vector((0, 0, 1)), 'forward_axis': object.matrix_world.to_quaternion() @ Vector((1, 0, 0)), - 'psets': ['{}/{}'.format(key, object[key]) for key in - object.keys() if key[0:5] == 'Pset_'], + 'psets': ['{}/{}'.format(pset.name, pset.file) for pset in + object.ObjectProperties.psets], 'class': self.get_ifc_class(object.name), 'representations': self.get_object_representation_names(object), 'attributes': self.get_object_attributes(object) diff --git a/src/ifcblenderexport/io_export_ifc/operator.py b/src/ifcblenderexport/io_export_ifc/operator.py index 01f400288d..5b368e95e9 100644 --- a/src/ifcblenderexport/io_export_ifc/operator.py +++ b/src/ifcblenderexport/io_export_ifc/operator.py @@ -228,17 +228,42 @@ class AssignPset(bpy.types.Operator): def execute(self, context): for object in bpy.context.selected_objects: - object[bpy.context.scene.BIMProperties.pset_name] = bpy.context.scene.BIMProperties.pset_file + index = object.ObjectProperties.psets.find(bpy.context.scene.BIMProperties.pset_name) + if index >= 0: + global_id = object.ObjectProperties.psets[index] + else: + global_id = object.ObjectProperties.psets.add() + global_id.name = bpy.context.scene.BIMProperties.pset_name + global_id.file = bpy.context.scene.BIMProperties.pset_file + return {'FINISHED'} + +class UnassignPset(bpy.types.Operator): + bl_idname = 'bim.unassign_pset' + bl_label = 'Unassign Pset' + + def execute(self, context): + for object in bpy.context.selected_objects: + index = object.ObjectProperties.psets.find(bpy.context.scene.BIMProperties.pset_name) + if index != -1: + object.ObjectProperties.psets.remove(index) + return {'FINISHED'} + +class AddPset(bpy.types.Operator): + bl_idname = 'bim.add_pset' + bl_label = 'Add Pset' + + # This is a temporary measure until we get a better UI + def execute(self, context): + bpy.context.active_object.ObjectProperties.psets.add() return {'FINISHED'} class RemovePset(bpy.types.Operator): bl_idname = 'bim.remove_pset' bl_label = 'Remove Pset' + pset_index: bpy.props.IntProperty() def execute(self, context): - for object in bpy.context.selected_objects: - if bpy.context.scene.BIMProperties.pset_name in object.keys(): - del(object[bpy.context.scene.BIMProperties.pset_name]) + bpy.context.active_object.ObjectProperties.psets.remove(self.pset_index) return {'FINISHED'} class GenerateGlobalId(bpy.types.Operator): @@ -246,12 +271,10 @@ class GenerateGlobalId(bpy.types.Operator): bl_label = 'Generate GlobalId' def execute(self, context): - global_id = None - for attribute in bpy.context.active_object.ObjectProperties.attributes: - if attribute.name == 'GlobalId': - global_id = attribute - break - if not global_id: + index = bpy.context.active_object.ObjectProperties.attributes.find('GlobalId') + if index >= 0: + global_id = bpy.context.active_object.ObjectProperties.attributes[index] + else: global_id = bpy.context.active_object.ObjectProperties.attributes.add() global_id.name = 'GlobalId' global_id.data_type = 'string' diff --git a/src/ifcblenderexport/io_export_ifc/ui.py b/src/ifcblenderexport/io_export_ifc/ui.py index f75a226510..efca786954 100644 --- a/src/ifcblenderexport/io_export_ifc/ui.py +++ b/src/ifcblenderexport/io_export_ifc/ui.py @@ -55,8 +55,13 @@ class Attribute(bpy.types.PropertyGroup): int_value: bpy.props.IntProperty(name="Value") float_value: bpy.props.FloatProperty(name="Value") +class Pset(bpy.types.PropertyGroup): + name: bpy.props.StringProperty(name="Name") + file: bpy.props.StringProperty(name="File") + class ObjectProperties(bpy.types.PropertyGroup): attributes: bpy.props.CollectionProperty(name="Attributes", type=Attribute) + psets: bpy.props.CollectionProperty(name="Psets", type=Pset) class MaterialProperties(bpy.types.PropertyGroup): is_external: bpy.props.BoolProperty(name="Has External Definition") @@ -96,6 +101,19 @@ class ObjectPanel(bpy.types.Panel): row = layout.row() row.prop(bpy.context.active_object.ObjectProperties, 'attributes') + layout.label(text="Property Sets:") + row = layout.row() + row.operator('bim.add_pset') + + for index, pset in enumerate(bpy.context.active_object.ObjectProperties.psets): + row = layout.row(align=True) + row.prop(pset, 'name', text='') + row.prop(pset, 'file', text='') + row.operator('bim.remove_pset', icon='CANCEL', text='').pset_index = index + + row = layout.row() + row.prop(bpy.context.active_object.ObjectProperties, 'psets') + class MeshPanel(bpy.types.Panel): bl_label = 'IFC Representations' bl_idname = 'BIM_PT_mesh' @@ -187,7 +205,7 @@ class BIMPanel(bpy.types.Panel): row = layout.row(align=True) row.operator("bim.assign_pset") - row.operator("bim.remove_pset") + row.operator("bim.unassign_pset") layout.label(text="Quality Auditing:")