cost.copy_cost_schedule #6901

A feature allowing duplicate existing IfcCostSchedule - either from API or from Bonsai UI
Button location in Bonsai - https://files.catbox.moe/ct058q.png
This commit is contained in:
Andrej730
2025-07-23 18:57:35 +05:00
parent f24adcdadb
commit e50215ddce
7 changed files with 76 additions and 0 deletions
@@ -37,6 +37,7 @@ classes = (
operator.ContractCostItemRate,
operator.ContractCostItems,
operator.CopyCostItem,
operator.CopyCostSchedule,
operator.CopyCostItemValues,
operator.DisableEditingCostItem,
operator.DisableEditingCostItemQuantity,
@@ -82,6 +82,20 @@ class RemoveCostSchedule(bpy.types.Operator, tool.Ifc.Operator):
core.remove_cost_schedule(tool.Ifc, tool.Cost, cost_schedule=tool.Ifc.get().by_id(self.cost_schedule))
class CopyCostSchedule(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.copy_cost_schedule"
bl_label = "Copy Cost Schedule"
bl_description = "Create a duplicate of the provided cost schedule."
bl_options = {"REGISTER", "UNDO"}
cost_schedule: bpy.props.IntProperty() # pyright: ignore[reportRedeclaration]
if TYPE_CHECKING:
cost_schedule: int
def _execute(self, context):
core.copy_cost_schedule(tool.Cost, cost_schedule=tool.Ifc.get().by_id(self.cost_schedule))
class EnableEditingCostSchedule(bpy.types.Operator):
bl_idname = "bim.enable_editing_cost_schedule_attributes"
bl_label = "Enable Editing Cost Schedule"
+1
View File
@@ -129,6 +129,7 @@ class BIM_PT_cost_schedules(Panel):
row.operator("bim.enable_editing_cost_schedule_attributes", text="", icon="GREASEPENCIL").cost_schedule = (
cost_schedule["id"]
)
row.operator("bim.copy_cost_schedule", text="", icon="DUPLICATE").cost_schedule = cost_schedule["id"]
row.operator("bim.remove_cost_schedule", text="", icon="X").cost_schedule = cost_schedule["id"]
if self.props.active_cost_schedule_id == cost_schedule["id"]:
if self.props.is_editing == "COST_SCHEDULE_ATTRIBUTES":
+4
View File
@@ -48,6 +48,10 @@ def remove_cost_schedule(
ifc.run("cost.remove_cost_schedule", cost_schedule=cost_schedule)
def copy_cost_schedule(cost: type[tool.Cost], cost_schedule: ifcopenshell.entity_instance) -> None:
cost.copy_cost_schedule(cost_schedule)
def enable_editing_cost_schedule_attributes(cost: type[tool.Cost], cost_schedule: ifcopenshell.entity_instance) -> None:
cost.load_cost_schedule_attributes(cost_schedule)
cost.enable_editing_cost_schedule_attributes(cost_schedule)
+6
View File
@@ -1114,3 +1114,9 @@ class Cost(bonsai.core.tool.Cost):
if results["quantity_type"] == "IfcQuantityCount":
results["unit_symbol"] = "U"
return results
@classmethod
def copy_cost_schedule(cls, cost_schedule: ifcopenshell.entity_instance) -> None:
ifc_file = tool.Ifc.get()
new_schedule = ifcopenshell.api.cost.copy_cost_schedule(ifc_file, cost_schedule=cost_schedule)
new_schedule.Name = (cost_schedule.Name or "Unnamed") + " Copy"