mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 22:22:26 +00:00
BBIM Feature to import resources data from CSV
This commit is contained in:
@@ -48,6 +48,7 @@ classes = (
|
|||||||
operator.DisableEditingResourceQuantity,
|
operator.DisableEditingResourceQuantity,
|
||||||
operator.DisableEditingResourceCostValue,
|
operator.DisableEditingResourceCostValue,
|
||||||
operator.CalculateResourceWork,
|
operator.CalculateResourceWork,
|
||||||
|
operator.ImportResources,
|
||||||
prop.Resource,
|
prop.Resource,
|
||||||
prop.BIMResourceProperties,
|
prop.BIMResourceProperties,
|
||||||
prop.BIMResourceTreeProperties,
|
prop.BIMResourceTreeProperties,
|
||||||
|
|||||||
@@ -330,3 +330,18 @@ class EditResourceQuantity(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
tool.Resource, tool.Ifc, physical_quantity=tool.Ifc.get().by_id(self.physical_quantity)
|
tool.Resource, tool.Ifc, physical_quantity=tool.Ifc.get().by_id(self.physical_quantity)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ImportResources(bpy.types.Operator, tool.Ifc.Operator, ImportHelper):
|
||||||
|
bl_idname = "import_resources.bim"
|
||||||
|
bl_label = "Import P6"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
filename_ext = ".csv"
|
||||||
|
filter_glob: bpy.props.StringProperty(default="*.csv", options={"HIDDEN"})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
|
return ifc_file is not None
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
core.import_resources(tool.Resource, file_path=self.filepath)
|
||||||
|
|||||||
@@ -54,10 +54,12 @@ class BIM_PT_resources(Panel):
|
|||||||
row.operator("bim.disable_resource_editing_ui", text="", icon="CANCEL")
|
row.operator("bim.disable_resource_editing_ui", text="", icon="CANCEL")
|
||||||
else:
|
else:
|
||||||
row.operator("bim.load_resources", text="Load Resources", icon="GREASEPENCIL")
|
row.operator("bim.load_resources", text="Load Resources", icon="GREASEPENCIL")
|
||||||
|
row.operator("import_resources.bim", text="Import Resources", icon="IMPORT")
|
||||||
if not self.props.is_editing:
|
if not self.props.is_editing:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.draw_resource_operators()
|
self.draw_resource_operators()
|
||||||
|
|
||||||
self.layout.template_list(
|
self.layout.template_list(
|
||||||
"BIM_UL_resources",
|
"BIM_UL_resources",
|
||||||
"",
|
"",
|
||||||
|
|||||||
@@ -427,6 +427,7 @@ class Resource:
|
|||||||
def get_resource_quantity_attributes(cls): pass
|
def get_resource_quantity_attributes(cls): pass
|
||||||
def expand_resource(cls, resource): pass
|
def expand_resource(cls, resource): pass
|
||||||
def contract_resource(cls, resource): pass
|
def contract_resource(cls, resource): pass
|
||||||
|
def import_resources(cls, file_path): pass
|
||||||
|
|
||||||
@interface
|
@interface
|
||||||
class Root:
|
class Root:
|
||||||
|
|||||||
@@ -26,9 +26,7 @@ class Csv2Ifc:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.csv = None
|
self.csv = None
|
||||||
self.file = None
|
self.file = None
|
||||||
self.resource_items = []
|
self.resources = []
|
||||||
self.cost_schedule = None
|
|
||||||
self.is_schedule_of_rates = False
|
|
||||||
self.units = {}
|
self.units = {}
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
@@ -52,7 +50,7 @@ class Csv2Ifc:
|
|||||||
cost_data = self.get_row_resource_data(row)
|
cost_data = self.get_row_resource_data(row)
|
||||||
hierarchy_key = int(row[0])
|
hierarchy_key = int(row[0])
|
||||||
if hierarchy_key == 1:
|
if hierarchy_key == 1:
|
||||||
self.resource_items.append(cost_data)
|
self.resources.append(cost_data)
|
||||||
else:
|
else:
|
||||||
self.parents[hierarchy_key - 1]["children"].append(cost_data)
|
self.parents[hierarchy_key - 1]["children"].append(cost_data)
|
||||||
self.parents[hierarchy_key] = cost_data
|
self.parents[hierarchy_key] = cost_data
|
||||||
@@ -73,12 +71,12 @@ class Csv2Ifc:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"Identification": str(identification) if identification else None,
|
"Identification": str(identification).strip() if identification else None,
|
||||||
"Name": str(name) if name else None,
|
"Name": str(name).strip() if name else None,
|
||||||
"Type": type,
|
"Type": type,
|
||||||
"BaseCostValue": float(base_cost_value) if base_cost_value else None,
|
"BaseCostValue": float(base_cost_value) if base_cost_value else None,
|
||||||
"BaseCostQuantity": float(base_cost_quantity) if base_cost_quantity else None,
|
"BaseCostQuantity": float(base_cost_quantity) if base_cost_quantity else None,
|
||||||
"Unit": str(base_cost_unit) if base_cost_unit else None,
|
"Unit": str(base_cost_unit).strip() if base_cost_unit else None,
|
||||||
"Productivity": productivity if productivity["BaseQuantityProducedName"] else None,
|
"Productivity": productivity if productivity["BaseQuantityProducedName"] else None,
|
||||||
"children": [],
|
"children": [],
|
||||||
}
|
}
|
||||||
@@ -86,10 +84,10 @@ class Csv2Ifc:
|
|||||||
def create_ifc(self):
|
def create_ifc(self):
|
||||||
if not self.file:
|
if not self.file:
|
||||||
self.create_boilerplate_ifc()
|
self.create_boilerplate_ifc()
|
||||||
self.create_resources(self.resource_items)
|
self.create_resources(self.resources)
|
||||||
|
|
||||||
def create_resources(self, resource_items, parent=None):
|
def create_resources(self, resources, parent=None):
|
||||||
for resource in resource_items:
|
for resource in resources:
|
||||||
self.create_resource(resource, parent)
|
self.create_resource(resource, parent)
|
||||||
|
|
||||||
def create_resource(self, resource, parent):
|
def create_resource(self, resource, parent):
|
||||||
@@ -115,29 +113,35 @@ class Csv2Ifc:
|
|||||||
cost_value.AppliedValue = self.file.createIfcMonetaryMeasure(resource["BaseCostValue"])
|
cost_value.AppliedValue = self.file.createIfcMonetaryMeasure(resource["BaseCostValue"])
|
||||||
if resource["Unit"]:
|
if resource["Unit"]:
|
||||||
measure_class = ifcopenshell.util.unit.get_symbol_measure_class(resource["Unit"])
|
measure_class = ifcopenshell.util.unit.get_symbol_measure_class(resource["Unit"])
|
||||||
|
print(measure_class)
|
||||||
value_component = self.file.create_entity(measure_class, resource["BaseCostQuantity"])
|
value_component = self.file.create_entity(measure_class, resource["BaseCostQuantity"])
|
||||||
|
print(value_component)
|
||||||
unit_component = None
|
unit_component = None
|
||||||
if measure_class == "IfcNumericMeasure":
|
if measure_class == "IfcNumericMeasure":
|
||||||
unit_component = self.create_unit(resource["Unit"])
|
unit_component = self.create_unit(resource["Unit"])
|
||||||
else:
|
else:
|
||||||
unit_type = ifcopenshell.util.unit.get_measure_unit_type(measure_class)
|
unit_type = ifcopenshell.util.unit.get_measure_unit_type(measure_class)
|
||||||
|
print(unit_type)
|
||||||
unit_assignment = ifcopenshell.util.unit.get_unit_assignment(self.file)
|
unit_assignment = ifcopenshell.util.unit.get_unit_assignment(self.file)
|
||||||
if unit_assignment:
|
if unit_assignment:
|
||||||
units = [u for u in unit_assignment.Units if getattr(u, "UnitType", None) == unit_type]
|
units = [u for u in unit_assignment.Units if getattr(u, "UnitType", None) == unit_type]
|
||||||
if units:
|
if units:
|
||||||
unit_component = units[0]
|
unit_component = units[0]
|
||||||
if not unit_component:
|
if not unit_component:
|
||||||
unit_component = self.create_unit(resource["Unit"])
|
unit_component = self.create_unit(resource["Unit"], unit_type)
|
||||||
|
print(unit_component)
|
||||||
cost_value.UnitBasis = self.file.createIfcMeasureWithUnit(value_component, unit_component)
|
cost_value.UnitBasis = self.file.createIfcMeasureWithUnit(value_component, unit_component)
|
||||||
self.create_resources(resource["children"], resource["ifc"])
|
self.create_resources(resource["children"], resource["ifc"])
|
||||||
|
|
||||||
def create_unit(self, symbol):
|
def create_unit(self, symbol, unit_type):
|
||||||
unit = self.units.get(symbol, None)
|
unit = self.units.get(symbol, None)
|
||||||
if unit:
|
if unit:
|
||||||
return unit
|
return unit
|
||||||
unit = self.file.createIfcContextDependentUnit(
|
else:
|
||||||
self.file.createIfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0), "USERDEFINED", symbol
|
unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type=unit_type, name=ifcopenshell.util.unit.si_type_names.get(unit_type, None))
|
||||||
)
|
# unit = self.file.createIfcContextDependentUnit(
|
||||||
|
# self.file.createIfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0), "USERDEFINED", symbol
|
||||||
|
# )
|
||||||
self.units[symbol] = unit
|
self.units[symbol] = unit
|
||||||
return unit
|
return unit
|
||||||
|
|
||||||
Reference in New Issue
Block a user