mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 13:52:23 +00:00
fix counting elements when importing cost schedules ( and run black)
This commit is contained in:
+25
-10
@@ -83,7 +83,8 @@ class Csv2Ifc:
|
|||||||
cost_values = {
|
cost_values = {
|
||||||
k: locale.atof(row[v])
|
k: locale.atof(row[v])
|
||||||
for k, v in self.headers.items()
|
for k, v in self.headers.items()
|
||||||
if k not in ["Hierarchy", "Identification", "Name", "Quantity", "Unit", "Subtotal", "Property", "Query"] and row[v]
|
if k not in ["Hierarchy", "Identification", "Name", "Quantity", "Unit", "Subtotal", "Property", "Query"]
|
||||||
|
and row[v]
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
cost_values = row[self.headers["Value"]]
|
cost_values = row[self.headers["Value"]]
|
||||||
@@ -129,8 +130,8 @@ class Csv2Ifc:
|
|||||||
cost_value = ifcopenshell.api.run("cost.add_cost_value", self.file, parent=cost_item["ifc"])
|
cost_value = ifcopenshell.api.run("cost.add_cost_value", self.file, parent=cost_item["ifc"])
|
||||||
cost_value.AppliedValue = self.file.createIfcMonetaryMeasure(value)
|
cost_value.AppliedValue = self.file.createIfcMonetaryMeasure(value)
|
||||||
if category != "Rate" or category != "Price":
|
if category != "Rate" or category != "Price":
|
||||||
if "Rate" in category or"Price" in category:
|
if "Rate" in category or "Price" in category:
|
||||||
category = category.replace("Rate","")
|
category = category.replace("Rate", "")
|
||||||
category = category.strip()
|
category = category.strip()
|
||||||
cost_value.Category = category
|
cost_value.Category = category
|
||||||
else:
|
else:
|
||||||
@@ -161,14 +162,25 @@ class Csv2Ifc:
|
|||||||
"cost.add_cost_item_quantity", self.file, cost_item=cost_item["ifc"], ifc_class=quantity_class
|
"cost.add_cost_item_quantity", self.file, cost_item=cost_item["ifc"], ifc_class=quantity_class
|
||||||
)
|
)
|
||||||
quantity[3] = cost_item["Quantity"]
|
quantity[3] = cost_item["Quantity"]
|
||||||
|
|
||||||
if cost_item["assignments"]["PropertyName"] and cost_item["assignments"]["Query"]:
|
if cost_item["assignments"]["Query"]:
|
||||||
print("for query",cost_item["assignments"]["Query"])
|
if (
|
||||||
|
not cost_item["assignments"]["PropertyName"]
|
||||||
|
or cost_item["assignments"]["PropertyName"].upper() == "COUNT"
|
||||||
|
):
|
||||||
|
prop_name = ""
|
||||||
|
else:
|
||||||
|
prop_name = cost_item["assignments"]["PropertyName"]
|
||||||
results = ifcopenshell.util.selector.filter_elements(self.file, cost_item["assignments"]["Query"])
|
results = ifcopenshell.util.selector.filter_elements(self.file, cost_item["assignments"]["Query"])
|
||||||
|
results = [r for r in results if has_property(self.file, r, prop_name)]
|
||||||
results = [r for r in results if has_property(self.file, r, cost_item["assignments"]["PropertyName"])]
|
|
||||||
if results:
|
if results:
|
||||||
ifcopenshell.api.run("cost.assign_cost_item_quantity", self.file, cost_item=cost_item["ifc"], products=results, prop_name=cost_item["assignments"]["PropertyName"])
|
ifcopenshell.api.run(
|
||||||
|
"cost.assign_cost_item_quantity",
|
||||||
|
self.file,
|
||||||
|
cost_item=cost_item["ifc"],
|
||||||
|
products=results,
|
||||||
|
prop_name=prop_name,
|
||||||
|
)
|
||||||
|
|
||||||
self.create_cost_items(cost_item["children"], cost_item["ifc"])
|
self.create_cost_items(cost_item["children"], cost_item["ifc"])
|
||||||
|
|
||||||
@@ -185,10 +197,13 @@ class Csv2Ifc:
|
|||||||
def create_boilerplate_ifc(self):
|
def create_boilerplate_ifc(self):
|
||||||
self.file = ifcopenshell.file(schema="IFC4")
|
self.file = ifcopenshell.file(schema="IFC4")
|
||||||
|
|
||||||
|
|
||||||
def has_property(self, product, property_name):
|
def has_property(self, product, property_name):
|
||||||
|
if not property_name:
|
||||||
|
return True
|
||||||
qtos = ifcopenshell.util.element.get_psets(product, qtos_only=True)
|
qtos = ifcopenshell.util.element.get_psets(product, qtos_only=True)
|
||||||
for qset, quantities in qtos.items():
|
for qset, quantities in qtos.items():
|
||||||
for quantity, value in quantities.items():
|
for quantity, value in quantities.items():
|
||||||
if quantity == property_name:
|
if quantity == property_name:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user