Skip to content

Commit

Permalink
Selecting multiple objects will now guess quantities in bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
Moult committed Aug 15, 2020
1 parent a1e5135 commit 0a7c365
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/ifcblenderexport/blenderbim/bim/operator.py
Expand Up @@ -3211,11 +3211,23 @@ class GuessQuantity(bpy.types.Operator):
prop_index: bpy.props.IntProperty()

def execute(self, context):
qto_calculator = qto.QtoCalculator()
props = bpy.context.active_object.BIMObjectProperties.qtos[self.qto_index].properties
self.qto_calculator = qto.QtoCalculator()
source_qto = bpy.context.active_object.BIMObjectProperties.qtos[self.qto_index]
props = source_qto.properties
prop = props[self.prop_index]
quantity = qto_calculator.guess_quantity(
prop.name, [p.name for p in props], bpy.context.active_object)
for obj in bpy.context.selected_objects:
dest_qto = obj.BIMObjectProperties.qtos.get(source_qto.name)
if not dest_qto:
if source_qto.name not in obj.BIMObjectProperties.qto_name:
continue
dest_qto = self.add_qto(obj, source_qto.name)
prop = dest_qto.properties.get(prop.name)
self.guess_quantity(obj, prop, props)
return {'FINISHED'}

def guess_quantity(self, obj, prop, props):
quantity = self.qto_calculator.guess_quantity(
prop.name, [p.name for p in props], obj)
if 'area' in prop.name.lower():
if bpy.context.scene.BIMProperties.area_unit:
prefix, name = self.get_prefix_name(bpy.context.scene.BIMProperties.area_unit)
Expand All @@ -3228,7 +3240,16 @@ def execute(self, context):
prefix, name = self.get_blender_prefix_name()
quantity = helper.SIUnitHelper.convert(quantity, None, 'METRE', prefix, name)
prop.string_value = str(round(quantity, 3))
return {'FINISHED'}

def add_qto(self, obj, name):
if name not in schema.ifc.qtos:
return
qto = obj.BIMObjectProperties.qtos.add()
qto.name = name
for prop_name in schema.ifc.qtos[name]['HasPropertyTemplates'].keys():
prop = qto.properties.add()
prop.name = prop_name
return qto

def get_prefix_name(self, value):
if '/' in value:
Expand Down

0 comments on commit 0a7c365

Please sign in to comment.