You can now copy cost values from one cost item to another

This commit is contained in:
Dion Moult
2021-05-13 15:11:45 +10:00
parent 4e014d1a10
commit 66862a6cba
4 changed files with 42 additions and 6 deletions
@@ -30,6 +30,7 @@ classes = (
operator.RemoveCostItemQuantity,
operator.AddCostValue,
operator.RemoveCostItemValue,
operator.CopyCostItemValues,
prop.CostItem,
prop.BIMCostProperties,
ui.BIM_PT_cost_schedules,
@@ -458,11 +458,7 @@ class RemoveCostItemValue(bpy.types.Operator):
def execute(self, context):
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"cost.remove_cost_item_value",
self.file,
cost_value=self.file.by_id(self.cost_value),
)
ifcopenshell.api.run("cost.remove_cost_item_value", self.file, cost_value=self.file.by_id(self.cost_value))
Data.load(self.file)
return {"FINISHED"}
@@ -519,3 +515,20 @@ class EditCostValue(bpy.types.Operator):
Data.load(IfcStore.get_file())
bpy.ops.bim.disable_editing_cost_item_value()
return {"FINISHED"}
class CopyCostItemValues(bpy.types.Operator):
bl_idname = "bim.copy_cost_item_values"
bl_label = "Copy Cost Item Values"
source: bpy.props.IntProperty()
destination: bpy.props.IntProperty()
def execute(self, context):
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"cost.copy_cost_item_values",
self.file,
**{"source": self.file.by_id(self.source), "destination": self.file.by_id(self.destination)},
)
Data.load(IfcStore.get_file())
return {"FINISHED"}
@@ -260,9 +260,14 @@ class BIM_UL_cost_items(UIList):
op.cost_item = item.ifc_definition_id
if props.active_cost_item_id == item.ifc_definition_id:
row.operator("bim.edit_cost_item", text="", icon="CHECKMARK")
if props.cost_item_editing_type == "ATTRIBUTES":
row.operator("bim.edit_cost_item", text="", icon="CHECKMARK")
row.operator("bim.disable_editing_cost_item", text="", icon="CANCEL")
elif props.active_cost_item_id:
if props.cost_item_editing_type == "VALUES":
op = row.operator("bim.copy_cost_item_values", text="", icon="COPYDOWN")
op.source = props.active_cost_item_id
op.destination = item.ifc_definition_id
row.operator("bim.add_cost_item", text="", icon="ADD").cost_item = item.ifc_definition_id
row.operator("bim.remove_cost_item", text="", icon="X").cost_item = item.ifc_definition_id
else:
@@ -0,0 +1,17 @@
import ifcopenshell.util.element
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"source": None, "destination": None}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
for cost_value in self.settings["destination"].CostValues or []:
ifcopenshell.api.run("cost.remove_cost_item_value", self.file, cost_value=cost_value)
copied_cost_values = []
for cost_value in self.settings["source"].CostValues or []:
copied_cost_values.append(ifcopenshell.util.element.copy_deep(self.file, cost_value))
self.settings["destination"].CostValues = copied_cost_values