mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
You can now copy properties to selection even if the pset doesn't exist yet
This commit is contained in:
@@ -198,6 +198,7 @@ if bpy is not None:
|
||||
operator.GetNorthOffset,
|
||||
operator.AddDrawingStyleAttribute,
|
||||
operator.RemoveDrawingStyleAttribute,
|
||||
operator.CopyPropertyToSelection,
|
||||
prop.StrProperty,
|
||||
prop.Variable,
|
||||
prop.Role,
|
||||
|
||||
@@ -2571,6 +2571,46 @@ class BIM_OT_CopyAttributesToSelection(bpy.types.Operator):
|
||||
except: pass
|
||||
|
||||
|
||||
class CopyPropertyToSelection(bpy.types.Operator):
|
||||
bl_idname = 'bim.copy_property_to_selection'
|
||||
bl_label = 'Copy Property To Selection'
|
||||
pset_name: bpy.props.StringProperty()
|
||||
prop_name: bpy.props.StringProperty()
|
||||
prop_value: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.applicable_psets_cache = {}
|
||||
self.empty = ifcopenshell.file()
|
||||
for obj in bpy.context.selected_objects:
|
||||
if '/' not in obj.name:
|
||||
continue
|
||||
pset = obj.BIMObjectProperties.psets.get(self.pset_name)
|
||||
if not pset:
|
||||
applicable_psets = self.get_applicable_psets(obj.name.split('/')[0])
|
||||
if self.pset_name not in applicable_psets:
|
||||
continue
|
||||
pset = obj.BIMObjectProperties.psets.add()
|
||||
pset.name = self.pset_name
|
||||
for template_prop_name in schema.ifc.psets[self.pset_name]['HasPropertyTemplates'].keys():
|
||||
prop = pset.properties.add()
|
||||
prop.name = template_prop_name
|
||||
prop = pset.properties.get(self.prop_name)
|
||||
if prop:
|
||||
prop.string_value = self.prop_value
|
||||
return {'FINISHED'}
|
||||
|
||||
# TODO: move into util module. See bug #971
|
||||
def get_applicable_psets(self, element_class):
|
||||
if element_class not in self.applicable_psets_cache:
|
||||
element = self.empty.create_entity(element_class)
|
||||
applicable_psets = []
|
||||
for ifc_class, pset_names in schema.ifc.applicable_psets.items():
|
||||
if element.is_a(ifc_class):
|
||||
applicable_psets.extend(pset_names)
|
||||
self.applicable_psets_cache[element_class] = applicable_psets
|
||||
return self.applicable_psets_cache[element_class]
|
||||
|
||||
|
||||
class BIM_OT_ChangeClassificationLevel(bpy.types.Operator):
|
||||
bl_idname = "bim.change_classification_level"
|
||||
bl_label = "Change Classification Level"
|
||||
|
||||
@@ -372,6 +372,7 @@ def refreshReferences(self, context):
|
||||
context.scene.BIMProperties.classification_references.root = ''
|
||||
|
||||
|
||||
# TODO: move into util module. See bug #971
|
||||
def getPsetNames(self, context):
|
||||
global psetnames_enum
|
||||
psetnames_enum.clear()
|
||||
@@ -385,6 +386,7 @@ def getPsetNames(self, context):
|
||||
return psetnames_enum
|
||||
|
||||
|
||||
# TODO: move into util module. See bug #971
|
||||
def getQtoNames(self, context):
|
||||
global qtonames_enum
|
||||
qtonames_enum.clear()
|
||||
|
||||
@@ -101,10 +101,10 @@ class BIM_PT_object_psets(Panel):
|
||||
row = layout.row(align=True)
|
||||
row.prop(prop, 'name', text='')
|
||||
row.prop(prop, 'string_value', text='')
|
||||
op = row.operator('bim.copy_attributes_to_selection', icon='COPYDOWN', text='')
|
||||
op.prop_base = 'BIMObjectProperties.psets[\'{}\'].properties'.format(pset.name)
|
||||
op = row.operator('bim.copy_property_to_selection', icon='COPYDOWN', text='')
|
||||
op.pset_name = pset.name
|
||||
op.prop_name = prop.name
|
||||
op.collection_element = True
|
||||
op.prop_value = prop.string_value
|
||||
|
||||
class BIM_PT_object_qto(Panel):
|
||||
bl_label = 'IFC Object Quantity Sets'
|
||||
|
||||
Reference in New Issue
Block a user