From 5a7acda57d530b947b8502492e7917c8d22d73c0 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 19 Oct 2019 13:48:07 +1100 Subject: [PATCH] Allow to add attributes from a drop down for ease of use --- src/ifcblenderexport/io_export_ifc/operator.py | 5 +++-- src/ifcblenderexport/io_export_ifc/ui.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ifcblenderexport/io_export_ifc/operator.py b/src/ifcblenderexport/io_export_ifc/operator.py index 5b368e95e9..8c83791224 100644 --- a/src/ifcblenderexport/io_export_ifc/operator.py +++ b/src/ifcblenderexport/io_export_ifc/operator.py @@ -285,9 +285,10 @@ class AddAttribute(bpy.types.Operator): bl_idname = 'bim.add_attribute' bl_label = 'Add Attribute' - # This is a temporary measure until we get a better UI def execute(self, context): - bpy.context.active_object.ObjectProperties.attributes.add() + if bpy.context.active_object.ObjectProperties.applicable_attributes: + attribute = bpy.context.active_object.ObjectProperties.attributes.add() + attribute.name = bpy.context.active_object.ObjectProperties.applicable_attributes return {'FINISHED'} class RemoveAttribute(bpy.types.Operator): diff --git a/src/ifcblenderexport/io_export_ifc/ui.py b/src/ifcblenderexport/io_export_ifc/ui.py index efca786954..04a0b8934c 100644 --- a/src/ifcblenderexport/io_export_ifc/ui.py +++ b/src/ifcblenderexport/io_export_ifc/ui.py @@ -60,8 +60,17 @@ class Pset(bpy.types.PropertyGroup): file: bpy.props.StringProperty(name="File") class ObjectProperties(bpy.types.PropertyGroup): + def getApplicableAttributes(self, context): + if '/' in bpy.context.active_object.name \ + and bpy.context.active_object.name.split('/')[0] in ifc_schema.elements: + return [(a['name'], a['name'], '') for a in + ifc_schema.elements[bpy.context.active_object.name.split('/')[0]]['attributes'] + if bpy.context.active_object.ObjectProperties.attributes.find(a['name']) == -1] + return [] + attributes: bpy.props.CollectionProperty(name="Attributes", type=Attribute) psets: bpy.props.CollectionProperty(name="Psets", type=Pset) + applicable_attributes: bpy.props.EnumProperty(items=getApplicableAttributes, name="Attribute Names") class MaterialProperties(bpy.types.PropertyGroup): is_external: bpy.props.BoolProperty(name="Has External Definition") @@ -89,7 +98,8 @@ class ObjectPanel(bpy.types.Panel): row.operator('bim.generate_global_id') layout.label(text="Attributes:") - row = layout.row() + row = layout.row(align=True) + row.prop(bpy.context.active_object.ObjectProperties, 'applicable_attributes', text='') row.operator('bim.add_attribute') for index, attribute in enumerate(bpy.context.active_object.ObjectProperties.attributes):