bim.assign_cost_item_quantity - to show error if no related objects were found

Just to make UI more responsive - e.g. if some objects are selected but they are not products.
This commit is contained in:
Andrej730
2024-11-20 20:20:28 +05:00
parent 610665d732
commit 37141c89ac
2 changed files with 10 additions and 2 deletions
@@ -265,13 +265,18 @@ class AssignCostItemQuantity(bpy.types.Operator, tool.Ifc.Operator):
prop_name: bpy.props.StringProperty()
def _execute(self, context):
core.assign_cost_item_quantity(
result = core.assign_cost_item_quantity(
tool.Ifc,
tool.Cost,
cost_item=tool.Ifc.get().by_id(self.cost_item),
related_object_type=self.related_object_type,
prop_name=self.prop_name, # TODO: REVIEW PROP_NAME USABILITY
)
if not result:
self.report(
{"ERROR"},
f"Cost item wasn't assigned - no objects of type '{self.related_object_type}' are selected.",
)
class UnassignCostItemQuantity(bpy.types.Operator, tool.Ifc.Operator):
+4 -1
View File
@@ -160,11 +160,14 @@ def assign_cost_item_quantity(
cost_item: ifcopenshell.entity_instance,
related_object_type: tool.Cost.RELATED_OBJECT_TYPE,
prop_name: str,
) -> None:
) -> bool:
products = cost.get_products(related_object_type)
if products:
ifc.run("cost.assign_cost_item_quantity", cost_item=cost_item, products=products, prop_name=prop_name)
cost.load_cost_item_quantity_assignments(cost_item, related_object_type=related_object_type)
return True
else:
return False
def load_cost_item_quantities(cost: tool.Cost) -> None: