mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
New feature to copy attributes or psets to all selected objects courtesy of Lucyon Oak (Teck-Freak)
This commit is contained in:
@@ -94,6 +94,7 @@ if bpy is not None:
|
||||
operator.AssignContext,
|
||||
operator.SetViewPreset1,
|
||||
operator.OpenUpstream,
|
||||
operator.BIM_OT_CopyAttributesToSelection,
|
||||
prop.BcfTopic,
|
||||
prop.BcfTopicLabel,
|
||||
prop.BcfTopicFile,
|
||||
|
||||
@@ -1599,3 +1599,66 @@ class OpenUpstream(bpy.types.Operator):
|
||||
elif self.page == 'community':
|
||||
webbrowser.open('https://community.osarch.org/')
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class BIM_OT_CopyAttributesToSelection(bpy.types.Operator):
|
||||
"""Copies attributes from the active object towards selected objects"""
|
||||
bl_idname = "bim.copy_attributes_to_selection"
|
||||
bl_label = "Copy Attributes To Selection"
|
||||
|
||||
prop_base = bpy.props.StringProperty() # data for properties to assign to
|
||||
prop_name = bpy.props.StringProperty(description="Property name which to change")
|
||||
sub_props = bpy.props.StringProperty() # properties which to copy (commasep). (empty = all)
|
||||
collection_element = bpy.props.BoolProperty(
|
||||
description="If this is a collection element, copy the complete thing")
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.active_object is not None
|
||||
|
||||
def execute(self, context):
|
||||
active_object = bpy.context.active_object
|
||||
selected_objects = [obj for obj in bpy.context.visible_objects
|
||||
if obj.type == active_object.type and obj in bpy.context.selected_objects and obj!=active_object]
|
||||
if self.prop_base:
|
||||
prop_base = eval('active_object.'+ self.prop_base)
|
||||
else:
|
||||
prop_base = active_object
|
||||
if not self.collection_element:
|
||||
self.copy_simple(prop_base, selected_objects)
|
||||
return {'FINISHED'}
|
||||
self.copy_collection(prop_base, selected_objects)
|
||||
return {'FINISHED'}
|
||||
|
||||
def copy_simple(self, prop_base, selected_objects):
|
||||
prop = getattr(prop_base, self.prop_name)
|
||||
for obj in selected_objects:
|
||||
if self.prop_base:
|
||||
new_prop_base = eval('obj.' + self.prop_base)
|
||||
else:
|
||||
new_prop_base = obj
|
||||
setattr(new_prop_base, self.prop_name, prop)
|
||||
|
||||
def copy_collection(self, prop_base, selected_objects):
|
||||
prop = prop_base[self.prop_name]
|
||||
for obj in selected_objects:
|
||||
if self.prop_base:
|
||||
new_prop_base = eval('obj.' + self.prop_base)
|
||||
else:
|
||||
new_prop_base = obj
|
||||
|
||||
if self.prop_name in new_prop_base:
|
||||
new_prop_base = new_prop_base[self.prop_name]
|
||||
else:
|
||||
new_prop_base = new_prop_base.add()
|
||||
|
||||
if self.sub_props:
|
||||
for p in self.sub_props.replace(' ','').split(','):
|
||||
try:
|
||||
setattr(new_prop_base, p, getattr(prop, p))
|
||||
except: pass
|
||||
else:
|
||||
for p in dir(prop):
|
||||
try:
|
||||
setattr(new_prop_base, p, getattr(prop, p))
|
||||
except: pass
|
||||
|
||||
@@ -32,6 +32,10 @@ class BIM_PT_object(Panel):
|
||||
row = layout.row(align=True)
|
||||
row.prop(attribute, 'name', text='')
|
||||
row.prop(attribute, 'string_value', text='')
|
||||
op = row.operator('bim.copy_attributes_to_selection', icon='COPYDOWN', text='')
|
||||
op.prop_base = 'BIMObjectProperties.attributes'
|
||||
op.prop_name = attribute.name
|
||||
op.collection_element = True
|
||||
row.operator('bim.remove_attribute', icon='X', text='').attribute_index = index
|
||||
|
||||
row = layout.row()
|
||||
@@ -71,6 +75,10 @@ class BIM_PT_object(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.override_psets[\'{}\'].properties'.format(pset.name)
|
||||
op.prop_name = prop.name
|
||||
op.collection_element = True
|
||||
|
||||
layout.label(text="Quantities:")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user