From 18387e7732ae365b64e41ff404b59eccc2a4159d Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 19 Sep 2022 15:59:37 +1000 Subject: [PATCH] You can now switch contexts of of objects in bulk --- .../bim/module/geometry/operator.py | 32 +++++++++++++------ .../blenderbim/bim/module/patch/operator.py | 7 ++-- src/blenderbim/blenderbim/tool/patch.py | 4 ++- .../test/bim/feature/sequence.feature | 2 +- .../docs/ifcconvert/installation.rst | 25 ++++++--------- src/ifcopenshell-python/docs/ifcpatch.rst | 3 +- src/ifcpatch/ifcpatch/__init__.py | 14 +++++++- src/ifcpatch/ifcpatch/__main__.py | 8 ++--- 8 files changed, 58 insertions(+), 37 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index 14b67b7203..2a73b23819 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -97,15 +97,29 @@ class SwitchRepresentation(bpy.types.Operator, Operator): should_switch_all_meshes: bpy.props.BoolProperty() def _execute(self, context): - core.switch_representation( - tool.Geometry, - obj=bpy.data.objects.get(self.obj) if self.obj else context.active_object, - representation=tool.Ifc.get().by_id(self.ifc_definition_id), - should_reload=self.should_reload, - enable_dynamic_voids=self.disable_opening_subtractions, - is_global=self.should_switch_all_meshes, - should_sync_changes_first=True, - ) + target = tool.Ifc.get().by_id(self.ifc_definition_id).ContextOfItems + is_subcontext = target.is_a("IfcGeometricRepresentationSubContext") + for obj in context.selected_objects: + element = tool.Ifc.get_entity(obj) + if not element: + continue + if is_subcontext: + representation = ifcopenshell.util.representation.get_representation( + element, target.ContextType, target.ContextIdentifier, target.TargetView + ) + else: + representation = ifcopenshell.util.representation.get_representation(element, target.ContextType) + if not representation: + continue + core.switch_representation( + tool.Geometry, + obj=obj, + representation=representation, + should_reload=self.should_reload, + enable_dynamic_voids=self.disable_opening_subtractions, + is_global=self.should_switch_all_meshes, + should_sync_changes_first=True, + ) class RemoveRepresentation(bpy.types.Operator, Operator): diff --git a/src/blenderbim/blenderbim/bim/module/patch/operator.py b/src/blenderbim/blenderbim/bim/module/patch/operator.py index a5c3b19ac6..58a9e45f72 100644 --- a/src/blenderbim/blenderbim/bim/module/patch/operator.py +++ b/src/blenderbim/blenderbim/bim/module/patch/operator.py @@ -19,6 +19,7 @@ import os import bpy import json +import ifcopenshell import blenderbim.tool as tool import blenderbim.core.patch as core import blenderbim.bim.handler @@ -79,15 +80,15 @@ class ExecuteIfcPatch(bpy.types.Operator): else: arguments = [arg.get_value() for arg in props.ifc_patch_args_attr] - ifcpatch.execute( + output = ifcpatch.execute( { - "input": props.ifc_patch_input, - "output": props.ifc_patch_output, + "input": ifcopenshell.open(props.ifc_patch_input), "recipe": props.ifc_patch_recipes, "arguments": arguments, "log": os.path.join(context.scene.BIMProperties.data_dir, "process.log"), } ) + ifcpatch.write(output, props.ifc_patch_output) return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/tool/patch.py b/src/blenderbim/blenderbim/tool/patch.py index 16cca5ff44..3ad1237f53 100644 --- a/src/blenderbim/blenderbim/tool/patch.py +++ b/src/blenderbim/blenderbim/tool/patch.py @@ -18,6 +18,7 @@ import os import bpy +import ifcopenshell import blenderbim.core.tool import blenderbim.tool as tool @@ -31,4 +32,5 @@ class Patch(blenderbim.core.tool.Patch): @classmethod def run_migrate_patch(cls, infile, outfile, schema): log = os.path.join(bpy.context.scene.BIMProperties.data_dir, "process.log") - ifcpatch.execute({"input": infile, "output": outfile, "recipe": "Migrate", "arguments": [schema], "log": log}) + output = ifcpatch.execute({"input": ifcopenshell.open(infile), "recipe": "Migrate", "arguments": [schema]}) + ifcpatch.write(output, outfile) diff --git a/src/blenderbim/test/bim/feature/sequence.feature b/src/blenderbim/test/bim/feature/sequence.feature index 331cb254e7..0e9f7910c5 100644 --- a/src/blenderbim/test/bim/feature/sequence.feature +++ b/src/blenderbim/test/bim/feature/sequence.feature @@ -388,7 +388,7 @@ Scenario: Animate the demolition of a wall And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" And I press "bim.assign_class" And the object "IfcWall/Cube" is selected - And I press "bim.assign_process(task={task}, related_object=0)" + And I press "bim.assign_process(task={task}, related_object=0, related_object_type='PRODUCT')" And I set "scene.BIMWorkScheduleProperties.visualisation_start" to "01/01/21" And I set "scene.BIMWorkScheduleProperties.visualisation_finish" to "01/02/21" And I set "scene.BIMWorkScheduleProperties.speed_types" to "FRAME_SPEED" diff --git a/src/ifcopenshell-python/docs/ifcconvert/installation.rst b/src/ifcopenshell-python/docs/ifcconvert/installation.rst index 80ea9ee38c..84bfac01f6 100644 --- a/src/ifcopenshell-python/docs/ifcconvert/installation.rst +++ b/src/ifcopenshell-python/docs/ifcconvert/installation.rst @@ -14,22 +14,17 @@ Pre-built packages 1. Download the appropriate version for your operating system. - +----------------+----------------+----------------+----------------+ - | Linux 64bit | Windows 32bit | Windows 64bit | MacOS 64bit | - +================+================+================+================+ - | build-linux64_ | build-win32_ | build-win64_ | build-macos64_ | - +----------------+----------------+----------------+----------------+ + +----------------+----------------+----------------+----------------+------------------+ + | Linux 64bit | Windows 32bit | Windows 64bit | MacOS 64bit | MacOS M1 64bit | + +================+================+================+================+==================+ + | build-linux64_ | build-win32_ | build-win64_ | build-macos64_ | build-macosm164_ | + +----------------+----------------+----------------+----------------+------------------+ -.. _build-linux64: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-dc67287-linux64.zip -.. _build-win32: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-dc67287-win32.zip -.. _build-win64: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-dc67287-win64.zip -.. _build-macos64: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-dc67287-macos64.zip - -.. warning:: - - Versions for Mac ARM devices (M1 chip) are not yet available. You are free to - compile it yourself manually, but this requires a level of technical - expertise. +.. _build-linux64: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-4fb910f-linux64.zip +.. _build-win32: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-4fb910f-win32.zip +.. _build-win64: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-4fb910f-win64.zip +.. _build-macos64: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-4fb910f-macos64.zip +.. _build-macosm164: https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.0-4fb910f-macosm164.zip 2. Unzip the downloaded file and run IfcConvert using the command line. diff --git a/src/ifcopenshell-python/docs/ifcpatch.rst b/src/ifcopenshell-python/docs/ifcpatch.rst index 171e2ed063..af1f3eb5b6 100644 --- a/src/ifcopenshell-python/docs/ifcpatch.rst +++ b/src/ifcopenshell-python/docs/ifcpatch.rst @@ -56,11 +56,12 @@ Here is a minimal example of how to use IfcDiff as a library: import ifcpatch - ifcpatch.execute({ + output = ifcpatch.execute({ "input": ifcopenshell.open("input.ifc"), "recipe": "ExtractElements", "arguments": [".IfcWall"], }) + ifcpatch.write(output, "output.ifc") You can also alias it to a command: diff --git a/src/ifcpatch/ifcpatch/__init__.py b/src/ifcpatch/ifcpatch/__init__.py index 7b163f6c42..a5918e82f1 100644 --- a/src/ifcpatch/ifcpatch/__init__.py +++ b/src/ifcpatch/ifcpatch/__init__.py @@ -39,7 +39,19 @@ def execute(args): else: patcher = recipe.Patcher(args["input"], ifc_file, logger, args["arguments"]) patcher.patch() - return getattr(patcher, "file_patched", patcher.file) + output = getattr(patcher, "file_patched", patcher.file) + if isinstance(output, str): + with open(args["output"], "w") as text_file: + text_file.write(output) + return output + + +def write(output, filepath): + if isinstance(output, str): + with open(filepath, "w") as text_file: + text_file.write(output) + else: + output.write(filepath) def extract_docs( diff --git a/src/ifcpatch/ifcpatch/__main__.py b/src/ifcpatch/ifcpatch/__main__.py index c95a05ed8f..db931616c2 100644 --- a/src/ifcpatch/ifcpatch/__main__.py +++ b/src/ifcpatch/ifcpatch/__main__.py @@ -34,15 +34,11 @@ print("# Loading IFC file ...") args["input"] = ifcopenshell.open(args["input"]) print("# Patching ...") -ifc_file = ifcpatch.execute(args) +output = ifcpatch.execute(args) print("# Writing patched file ...") if not args["output"]: args["output"] = args["input"] -if isinstance(ifc_file, str): - with open(args["output"], "w") as text_file: - text_file.write(ifc_file) -else: - ifc_file.write(args["output"]) +ifcpatch.write(output, args["output"]) print("# All tasks are complete :-)")