Use passed context instead of bpy when available (#1607)

This commit is contained in:
Gorgious56
2021-07-29 23:08:17 +02:00
committed by GitHub
parent d2e421382b
commit 2af1ebc614
50 changed files with 549 additions and 545 deletions
@@ -16,7 +16,7 @@ class TogglePsetExpansion(bpy.types.Operator):
pset_id: bpy.props.IntProperty()
def execute(self, context):
obj = bpy.context.active_object
obj = context.active_object
data = Data.psets if self.pset_id in Data.psets else Data.qtos
data[self.pset_id]["is_expanded"] = not data[self.pset_id]["is_expanded"]
return {"FINISHED"}
@@ -295,7 +295,7 @@ class AddQto(bpy.types.Operator):
def _execute(self, context):
self.file = IfcStore.get_file()
obj = bpy.context.active_object
obj = context.active_object
oprops = obj.BIMObjectProperties
props = obj.PsetProperties
ifcopenshell.api.run(
@@ -318,23 +318,23 @@ class GuessQuantity(bpy.types.Operator):
def execute(self, context):
self.qto_calculator = QtoCalculator()
obj = bpy.context.active_object
obj = context.active_object
prop = obj.PsetProperties.properties.get(self.prop)
prop.float_value = self.guess_quantity(obj)
prop.float_value = self.guess_quantity(obj, context)
return {"FINISHED"}
def guess_quantity(self, obj):
def guess_quantity(self, obj, context):
quantity = self.qto_calculator.guess_quantity(self.prop, [p.name for p in obj.PsetProperties.properties], obj)
if "area" in self.prop.lower():
if bpy.context.scene.BIMProperties.area_unit:
prefix, name = self.get_prefix_name(bpy.context.scene.BIMProperties.area_unit)
if context.scene.BIMProperties.area_unit:
prefix, name = self.get_prefix_name(context.scene.BIMProperties.area_unit)
quantity = ifcopenshell.util.unit.convert(quantity, None, "SQUARE_METRE", prefix, name)
elif "volume" in self.prop.lower():
if bpy.context.scene.BIMProperties.volume_unit:
prefix, name = self.get_prefix_name(bpy.context.scene.BIMProperties.volume_unit)
if context.scene.BIMProperties.volume_unit:
prefix, name = self.get_prefix_name(context.scene.BIMProperties.volume_unit)
quantity = ifcopenshell.util.unit.convert(quantity, None, "CUBIC_METRE", prefix, name)
else:
prefix, name = self.get_blender_prefix_name()
prefix, name = self.get_blender_prefix_name(context)
quantity = ifcopenshell.util.unit.convert(quantity, None, "METRE", prefix, name)
return round(quantity, 3)
@@ -343,13 +343,14 @@ class GuessQuantity(bpy.types.Operator):
return value.split("/")
return None, value
def get_blender_prefix_name(self):
if bpy.context.scene.unit_settings.system == "IMPERIAL":
if bpy.context.scene.unit_settings.length_unit == "INCHES":
def get_blender_prefix_name(self, context):
unit_settings = context.scene.unit_settings
if unit_settings.system == "IMPERIAL":
if unit_settings.length_unit == "INCHES":
return None, "inch"
elif bpy.context.scene.unit_settings.length_unit == "FEET":
elif unit_settings.length_unit == "FEET":
return None, "foot"
elif bpy.context.scene.unit_settings.system == "METRIC":
if bpy.context.scene.unit_settings.length_unit == "METERS":
elif unit_settings.system == "METRIC":
if unit_settings.length_unit == "METERS":
return None, "METRE"
return bpy.context.scene.unit_settings.length_unit[0 : -len("METERS")], "METRE"
return unit_settings.length_unit[0 : -len("METERS")], "METRE"