Fix #2620. You can now run patches from models in memory.

This commit is contained in:
Dion Moult
2023-02-01 19:29:35 +11:00
parent 7e16cb797f
commit d69aa20802
4 changed files with 31 additions and 8 deletions
@@ -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"),
@@ -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")
@@ -16,8 +16,9 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
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")
+10 -1
View File
@@ -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"