diff --git a/src/blenderbim/blenderbim/bim/module/patch/operator.py b/src/blenderbim/blenderbim/bim/module/patch/operator.py index 44b48969bd..8ad931edbb 100644 --- a/src/blenderbim/blenderbim/bim/module/patch/operator.py +++ b/src/blenderbim/blenderbim/bim/module/patch/operator.py @@ -71,7 +71,7 @@ class ExecuteIfcPatch(bpy.types.Operator): @classmethod def poll(cls, context): input_file = context.scene.BIMPatchProperties.ifc_patch_input - return os.path.isfile(input_file) and "ifc" in os.path.splitext(input_file)[1].lower() + return input_file or context.scene.BIMPatchProperties.should_load_from_memory def execute(self, context): props = context.scene.BIMPatchProperties @@ -80,10 +80,17 @@ class ExecuteIfcPatch(bpy.types.Operator): else: arguments = [arg.get_value() for arg in props.ifc_patch_args_attr] + if props.should_load_from_memory and tool.Ifc.get(): + input_file = props.ifc_patch_input + file = tool.Ifc.get() + else: + input_file = props.ifc_patch_input + file = ifcopenshell.open(props.ifc_patch_input) + output = ifcpatch.execute( { - "input": props.ifc_patch_input, - "file": ifcopenshell.open(props.ifc_patch_input), + "input": input_file, + "file": file, "recipe": props.ifc_patch_recipes, "arguments": arguments, "log": os.path.join(context.scene.BIMProperties.data_dir, "process.log"), diff --git a/src/blenderbim/blenderbim/bim/module/patch/prop.py b/src/blenderbim/blenderbim/bim/module/patch/prop.py index 27c0e44ab5..af80c35e95 100644 --- a/src/blenderbim/blenderbim/bim/module/patch/prop.py +++ b/src/blenderbim/blenderbim/bim/module/patch/prop.py @@ -66,3 +66,4 @@ class BIMPatchProperties(PropertyGroup): ifc_patch_output: StringProperty(default="", name="IFC Patch Output IFC") ifc_patch_args: StringProperty(default="", name="Arguments") ifc_patch_args_attr: CollectionProperty(type=Attribute, name="Arguments") + should_load_from_memory: BoolProperty(default=False, name="Load from Memory") diff --git a/src/blenderbim/blenderbim/bim/module/patch/ui.py b/src/blenderbim/blenderbim/bim/module/patch/ui.py index 9e7a241e51..7b0416bd14 100644 --- a/src/blenderbim/blenderbim/bim/module/patch/ui.py +++ b/src/blenderbim/blenderbim/bim/module/patch/ui.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . -from blenderbim.bim.helper import prop_with_search import bpy +import blenderbim.tool as tool +from blenderbim.bim.helper import prop_with_search from blenderbim.bim.helper import draw_attributes @@ -40,9 +41,14 @@ class BIM_PT_patch(bpy.types.Panel): row = layout.row() prop_with_search(row, props, "ifc_patch_recipes") - row = layout.row(align=True) - row.prop(props, "ifc_patch_input") - row.operator("bim.select_ifc_patch_input", icon="FILE_FOLDER", text="") + if tool.Ifc.get(): + row = self.layout.row() + row.prop(props, "should_load_from_memory") + + if not tool.Ifc.get() or not props.should_load_from_memory: + row = layout.row(align=True) + row.prop(props, "ifc_patch_input") + row.operator("bim.select_ifc_patch_input", icon="FILE_FOLDER", text="") row = layout.row(align=True) row.prop(props, "ifc_patch_output") diff --git a/src/blenderbim/test/bim/feature/patch.feature b/src/blenderbim/test/bim/feature/patch.feature index dc89edf2d0..e49065bb30 100644 --- a/src/blenderbim/test/bim/feature/patch.feature +++ b/src/blenderbim/test/bim/feature/patch.feature @@ -1,7 +1,16 @@ @patch Feature: Patch -Scenario: Execute IFC Patch +Scenario: Execute IFC Patch - file in memory + Given an empty IFC project + And I set "scene.BIMPatchProperties.ifc_patch_recipes" to "OffsetObjectPlacements" + And I set "scene.BIMPatchProperties.should_load_from_memory" to "True" + And I set "scene.BIMPatchProperties.ifc_patch_output" to "{cwd}/test/files/basic-patched.ifc" + And I set "scene.BIMPatchProperties.ifc_patch_args" to "[123454321,0,0,0]" + When I press "bim.execute_ifc_patch(use_json_for_args=True)" + Then the file "{cwd}/test/files/basic-patched.ifc" should contain "123454321" + +Scenario: Execute IFC Patch - file from disk Given an empty IFC project And I set "scene.BIMPatchProperties.ifc_patch_recipes" to "OffsetObjectPlacements" And I set "scene.BIMPatchProperties.ifc_patch_input" to "{cwd}/test/files/basic.ifc"