From b821e62391563f8c2ca0de0620e9719ee7c0193b Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 8 Apr 2021 08:57:45 +1000 Subject: [PATCH] You can now add/remove material profiles in a profile set. Thanks Jesusbill! --- .../bim/module/material/__init__.py | 2 + .../bim/module/material/operator.py | 37 +++++++++++++++++++ .../api/material/add_constituent.py | 3 -- .../ifcopenshell/api/material/add_layer.py | 3 -- .../ifcopenshell/api/material/add_profile.py | 13 +++++++ .../api/material/remove_constituent.py | 3 -- .../ifcopenshell/api/material/remove_layer.py | 3 -- .../api/material/remove_profile.py | 9 +++++ .../api/sequence/add_work_time.py | 2 +- 9 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 src/ifcopenshell-python/ifcopenshell/api/material/add_profile.py create mode 100644 src/ifcopenshell-python/ifcopenshell/api/material/remove_profile.py diff --git a/src/blenderbim/blenderbim/bim/module/material/__init__.py b/src/blenderbim/blenderbim/bim/module/material/__init__.py index 89e1f74243..7680e62122 100644 --- a/src/blenderbim/blenderbim/bim/module/material/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/material/__init__.py @@ -8,6 +8,8 @@ classes = ( operator.UnassignMaterial, operator.AddConstituent, operator.RemoveConstituent, + operator.AddProfile, + operator.RemoveProfile, operator.AddLayer, operator.RemoveLayer, operator.ReorderMaterialSetItem, diff --git a/src/blenderbim/blenderbim/bim/module/material/operator.py b/src/blenderbim/blenderbim/bim/module/material/operator.py index bf7dde4867..c77e96048b 100644 --- a/src/blenderbim/blenderbim/bim/module/material/operator.py +++ b/src/blenderbim/blenderbim/bim/module/material/operator.py @@ -115,6 +115,43 @@ class RemoveConstituent(bpy.types.Operator): return {"FINISHED"} +class AddProfile(bpy.types.Operator): + bl_idname = "bim.add_profile" + bl_label = "Add Profile" + obj: bpy.props.StringProperty() + profile_set: bpy.props.IntProperty() + + def execute(self, context): + obj = bpy.data.objects.get(self.obj) if self.obj else bpy.context.active_object + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "material.add_profile", + self.file, + **{ + "profile_set": self.file.by_id(self.profile_set), + "material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)), + }, + ) + Data.load_profiles() + return {"FINISHED"} + + +class RemoveProfile(bpy.types.Operator): + bl_idname = "bim.remove_profile" + bl_label = "Remove Profile" + obj: bpy.props.StringProperty() + profile: bpy.props.IntProperty() + + def execute(self, context): + obj = bpy.data.objects.get(self.obj) if self.obj else bpy.context.active_object + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "material.remove_profile", self.file, **{"profile": self.file.by_id(self.profile)} + ) + Data.load_profiles() + return {"FINISHED"} + + class AddLayer(bpy.types.Operator): bl_idname = "bim.add_layer" bl_label = "Add Layer" diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_constituent.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_constituent.py index f91dda0980..afa23c3a94 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/add_constituent.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_constituent.py @@ -1,6 +1,3 @@ -import ifcopenshell - - class Usecase: def __init__(self, file, **settings): self.file = file diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_layer.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_layer.py index b5cb426eb9..b895901227 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/add_layer.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_layer.py @@ -1,6 +1,3 @@ -import ifcopenshell - - class Usecase: def __init__(self, file, **settings): self.file = file diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_profile.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_profile.py new file mode 100644 index 0000000000..c1b282720e --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_profile.py @@ -0,0 +1,13 @@ +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"profile_set": None, "material": None} + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + profiles = list(self.settings["profile_set"].MaterialProfiles or []) + profile = self.file.create_entity("IfcMaterialProfile", **{"Material": self.settings["material"]}) + profiles.append(profile) + self.settings["profile_set"].MaterialProfiles = profiles + return profile diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/remove_constituent.py b/src/ifcopenshell-python/ifcopenshell/api/material/remove_constituent.py index 9c66ae6afc..a149b63531 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/remove_constituent.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/remove_constituent.py @@ -1,6 +1,3 @@ -import ifcopenshell - - class Usecase: def __init__(self, file, **settings): self.file = file diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/remove_layer.py b/src/ifcopenshell-python/ifcopenshell/api/material/remove_layer.py index d953c56a25..88bd925292 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/remove_layer.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/remove_layer.py @@ -1,6 +1,3 @@ -import ifcopenshell - - class Usecase: def __init__(self, file, **settings): self.file = file diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/remove_profile.py b/src/ifcopenshell-python/ifcopenshell/api/material/remove_profile.py new file mode 100644 index 0000000000..33b00ce347 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/material/remove_profile.py @@ -0,0 +1,9 @@ +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"profile": None} + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + self.file.remove(self.settings["profile"]) diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/add_work_time.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/add_work_time.py index 13e7ec080a..40589b5098 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/add_work_time.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/add_work_time.py @@ -14,5 +14,5 @@ class Usecase: elif self.settings["type"] == "ExceptionTimes": exception_times = list(self.settings["work_calendar"].ExceptionTimes or []) exception_times.append(work_time) - self.settings["work_calendar"].WorkingTimes = exception_times + self.settings["work_calendar"].ExceptionTimes = exception_times return work_time