You can now switch contexts of of objects in bulk

This commit is contained in:
Dion Moult
2022-09-19 15:59:37 +10:00
parent 57e8e47061
commit 18387e7732
8 changed files with 58 additions and 37 deletions
@@ -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):
@@ -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"}
+3 -1
View File
@@ -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)
@@ -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"
@@ -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.
+2 -1
View File
@@ -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:
+13 -1
View File
@@ -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(
+2 -6
View File
@@ -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 :-)")