bim.export_resources #5760

Simple export for resources to csv file, supports just the same fields that import currently does.
Location - https://i.imgur.com/Ssz7BwZ.png
This commit is contained in:
Andrej730
2024-11-18 15:15:48 +05:00
parent 8420823342
commit 164e5c69ca
6 changed files with 137 additions and 13 deletions
@@ -43,6 +43,7 @@ classes = (
operator.EnableEditingResourceBaseQuantity,
operator.EnableEditingResourceCosts,
operator.EnableEditingResourceCostValue,
operator.ExportResources,
operator.CalculateResourceUsage,
operator.EnableEditingResourceCostValueFormula,
operator.EnableEditingResourceQuantity,
@@ -17,7 +17,7 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
import bpy
from bpy_extras.io_utils import ImportHelper
from bpy_extras.io_utils import ImportHelper, ExportHelper
from bonsai.bim.module.resource.ui import draw_productivity_ui
import bonsai.core.resource as core
import bonsai.tool as tool
@@ -334,6 +334,7 @@ class EditResourceQuantity(bpy.types.Operator, tool.Ifc.Operator):
class ImportResources(bpy.types.Operator, tool.Ifc.Operator, ImportHelper):
bl_idname = "bim.import_resources"
bl_label = "Import Resources"
bl_description = "Import resources from a .csv file"
bl_options = {"REGISTER", "UNDO"}
filename_ext = ".csv"
filter_glob: bpy.props.StringProperty(default="*.csv", options={"HIDDEN"})
@@ -351,6 +352,24 @@ class ImportResources(bpy.types.Operator, tool.Ifc.Operator, ImportHelper):
self.report({"INFO"}, f"{resources_after - resources_before} resources are imported.")
class ExportResources(bpy.types.Operator, tool.Ifc.Operator, ExportHelper):
bl_idname = "bim.export_resources"
bl_label = "Export Resources"
bl_description = "Export resources to a .csv file"
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.export_resources(tool.Resource, file_path=self.filepath)
self.report({"INFO"}, f"Resources are exported to {self.filepath}")
class AddProductivityData(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.add_productivity_data"
bl_label = "Add Productivity"
@@ -54,6 +54,7 @@ class BIM_PT_resources(Panel):
else:
row.operator("bim.load_resources", text="", icon="GREASEPENCIL")
row.operator("bim.import_resources", text="", icon="IMPORT")
row.operator("bim.export_resources", text="", icon="EXPORT")
if not self.props.is_editing:
return
+4
View File
@@ -171,6 +171,10 @@ def import_resources(resource_tool: tool.Resource, file_path: str) -> None:
resource_tool.load_resources()
def export_resources(resource_tool: tool.Resource, file_path: str) -> None:
resource_tool.export_resources(file_path)
def expand_resource(resource_tool: tool.Resource, resource: ifcopenshell.entity_instance) -> None:
resource_tool.expand_resource(resource)
resource_tool.load_resources()
+11 -2
View File
@@ -304,8 +304,17 @@ class Resource(bonsai.core.tool.Resource):
from ifc4d.csv2ifc import Csv2Ifc
start = time.time()
p62ifc = Csv2Ifc(file_path, tool.Ifc.get())
p62ifc.execute()
csv2ifc = Csv2Ifc(file_path, tool.Ifc.get())
csv2ifc.execute()
print("Importing Resources CSV finished in {:.2f} seconds".format(time.time() - start))
@classmethod
def export_resources(cls, file_path: str) -> None:
from ifc4d.csv2ifc import Ifc2Csv
start = time.time()
csv2ifc = Ifc2Csv(file_path, tool.Ifc.get())
csv2ifc.execute()
print("Importing Resources CSV finished in {:.2f} seconds".format(time.time() - start))
@classmethod