From 2ac0b75dbce16fd7987ef4b6408e77119706bfa1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 10 Dec 2020 13:52:29 +1100 Subject: [PATCH] New Link IFC operator to easily append IFCs from another Blend file into a master file --- .../blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/operator.py | 27 +++++++++++++++++++ src/ifcblenderexport/blenderbim/bim/ui.py | 2 ++ 3 files changed, 30 insertions(+) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 5e83cf6c2c..653cd10110 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -231,6 +231,7 @@ if bpy is not None: operator.SetBlenderClashSetB, operator.ExecuteBlenderClash, operator.CleanWireframes, + operator.LinkIfc, prop.StrProperty, prop.Attribute, prop.MaterialLayer, diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 613f076a97..e14d627ea0 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -4862,3 +4862,30 @@ class CleanWireframes(bpy.types.Operator): if not obj.modifiers.get("EdgeSplit"): obj.modifiers.new("EdgeSplit", "EDGE_SPLIT") return {"FINISHED"} + + +class LinkIfc(bpy.types.Operator): + bl_idname = "bim.link_ifc" + bl_label = "Link IFC" + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + #bpy.context.active_object.active_material.BIMMaterialProperties.location = self.filepath + #coll_name = "MyCollection" + + with bpy.data.libraries.load(self.filepath, link=True) as (data_from, data_to): + data_to.scenes = data_from.scenes + + for scene in bpy.data.scenes: + if not scene.library or scene.library.filepath != self.filepath: + continue + for child in scene.collection.children: + if "IfcProject" not in child.name: + continue + bpy.data.scenes[0].collection.children.link(child) + + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 46d710ec9f..8a5b86c016 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -2305,6 +2305,8 @@ class BIM_PT_annotation_utilities(Panel): row = layout.row(align=True) row.operator("bim.clean_wireframes") + row = layout.row(align=True) + row.operator("bim.link_ifc") row = layout.row(align=True) op = row.operator("bim.add_annotation", text="Dim", icon="ARROW_LEFTRIGHT")