2021-08-17 08:55:29 +10:00
|
|
|
|
|
|
|
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
|
|
|
|
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
|
|
|
|
|
#
|
|
|
|
|
# This file is part of BlenderBIM Add-on.
|
|
|
|
|
#
|
|
|
|
|
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# 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/>.
|
|
|
|
|
|
2021-01-17 12:46:35 +11:00
|
|
|
import bpy
|
2021-04-08 21:03:37 +10:00
|
|
|
import json
|
2021-03-27 22:52:52 +11:00
|
|
|
import ifcopenshell.api
|
2021-07-28 19:55:18 +10:00
|
|
|
import ifcopenshell.util.element
|
2021-03-24 16:09:29 +11:00
|
|
|
import ifcopenshell.util.attribute
|
2021-07-10 22:06:11 +10:00
|
|
|
import ifcopenshell.util.representation
|
2021-06-09 11:23:34 +10:00
|
|
|
import blenderbim.bim.helper
|
2021-04-14 18:40:52 +10:00
|
|
|
from blenderbim.bim.module.material.prop import purge as material_prop_purge
|
2021-01-17 12:46:35 +11:00
|
|
|
from blenderbim.bim.ifc import IfcStore
|
2021-03-25 10:48:31 +11:00
|
|
|
from ifcopenshell.api.material.data import Data
|
2021-04-08 21:03:37 +10:00
|
|
|
from ifcopenshell.api.profile.data import Data as ProfileData
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AssignParameterizedProfile(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.assign_parameterized_profile"
|
|
|
|
|
bl_label = "Assign Parameterized Profile"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-08 21:03:37 +10:00
|
|
|
ifc_class: bpy.props.StringProperty()
|
|
|
|
|
material_profile: bpy.props.IntProperty()
|
|
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-04-08 21:03:37 +10:00
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
profile = ifcopenshell.api.run(
|
|
|
|
|
"profile.add_parameterized_profile",
|
|
|
|
|
self.file,
|
|
|
|
|
**{"ifc_class": self.ifc_class},
|
|
|
|
|
)
|
|
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.assign_profile",
|
|
|
|
|
self.file,
|
2021-06-09 11:23:34 +10:00
|
|
|
**{"material_profile": self.file.by_id(self.material_profile), "profile": profile},
|
2021-04-08 21:03:37 +10:00
|
|
|
)
|
|
|
|
|
Data.load_profiles()
|
|
|
|
|
ProfileData.load(self.file)
|
|
|
|
|
bpy.ops.bim.enable_editing_material_set_item(obj=obj.name, material_set_item=self.material_profile)
|
|
|
|
|
return {"FINISHED"}
|
2021-01-17 12:46:35 +11:00
|
|
|
|
|
|
|
|
|
2021-01-26 11:45:58 +11:00
|
|
|
class AddMaterial(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.add_material"
|
|
|
|
|
bl_label = "Add Material"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-26 11:45:58 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.materials.get(self.obj) if self.obj else context.active_object.active_material
|
2021-01-26 11:45:58 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-05-28 10:59:20 +10:00
|
|
|
result = ifcopenshell.api.run("material.add_material", self.file, **{"name": obj.name})
|
2021-07-28 19:55:18 +10:00
|
|
|
IfcStore.link_element(result, obj)
|
2021-07-10 22:06:11 +10:00
|
|
|
if obj.BIMMaterialProperties.ifc_style_id:
|
|
|
|
|
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
|
|
|
|
|
if context:
|
2021-07-28 19:55:18 +10:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"style.assign_material_style",
|
|
|
|
|
self.file,
|
|
|
|
|
**{
|
|
|
|
|
"material": result,
|
|
|
|
|
"style": self.file.by_id(obj.BIMMaterialProperties.ifc_style_id),
|
|
|
|
|
"context": context,
|
|
|
|
|
},
|
|
|
|
|
)
|
2021-03-25 10:48:31 +11:00
|
|
|
Data.load(IfcStore.get_file())
|
2021-04-14 18:40:52 +10:00
|
|
|
material_prop_purge()
|
2021-01-26 11:45:58 +11:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RemoveMaterial(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.remove_material"
|
|
|
|
|
bl_label = "Remove Material"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-26 11:45:58 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.materials.get(self.obj) if self.obj else context.active_object.active_material
|
2021-01-26 11:45:58 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-27 22:52:52 +11:00
|
|
|
result = ifcopenshell.api.run(
|
|
|
|
|
"material.remove_material",
|
|
|
|
|
self.file,
|
|
|
|
|
**{"material": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)},
|
|
|
|
|
)
|
2021-01-26 11:45:58 +11:00
|
|
|
obj.BIMObjectProperties.ifc_definition_id = 0
|
2021-03-25 10:48:31 +11:00
|
|
|
Data.load(IfcStore.get_file())
|
2021-01-26 11:45:58 +11:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2021-01-17 12:46:35 +11:00
|
|
|
class AssignMaterial(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.assign_material"
|
|
|
|
|
bl_label = "Assign Material"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
material_type: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
material_type = self.material_type or obj.BIMObjectMaterialProperties.material_type
|
|
|
|
|
self.file = IfcStore.get_file()
|
2021-07-28 19:55:18 +10:00
|
|
|
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.assign_material",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-07-28 19:55:18 +10:00
|
|
|
"product": element,
|
2021-01-17 12:46:35 +11:00
|
|
|
"type": material_type,
|
|
|
|
|
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-03-25 10:48:31 +11:00
|
|
|
Data.load(IfcStore.get_file())
|
|
|
|
|
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
|
2021-01-17 12:46:35 +11:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UnassignMaterial(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.unassign_material"
|
|
|
|
|
bl_label = "Unassign Material"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.unassign_material",
|
|
|
|
|
self.file,
|
|
|
|
|
**{"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)},
|
|
|
|
|
)
|
2021-08-08 20:56:31 +10:00
|
|
|
Data.purge()
|
2021-01-17 12:46:35 +11:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AddConstituent(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.add_constituent"
|
|
|
|
|
bl_label = "Add Constituent"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
constituent_set: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.add_constituent",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-01-17 12:46:35 +11:00
|
|
|
"constituent_set": self.file.by_id(self.constituent_set),
|
|
|
|
|
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_constituents()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RemoveConstituent(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.remove_constituent"
|
|
|
|
|
bl_label = "Remove Constituent"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
constituent: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.remove_constituent", self.file, **{"constituent": self.file.by_id(self.constituent)}
|
|
|
|
|
)
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_constituents()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2021-04-08 08:57:45 +10:00
|
|
|
class AddProfile(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.add_profile"
|
|
|
|
|
bl_label = "Add Profile"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-08 08:57:45 +10:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
profile_set: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-04-08 08:57:45 +10:00
|
|
|
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()
|
2021-07-23 10:41:08 +10:00
|
|
|
ProfileData.load(self.file)
|
2021-04-08 08:57:45 +10:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RemoveProfile(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.remove_profile"
|
|
|
|
|
bl_label = "Remove Profile"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-08 08:57:45 +10:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
profile: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-04-08 08:57:45 +10:00
|
|
|
self.file = IfcStore.get_file()
|
2021-06-09 11:23:34 +10:00
|
|
|
ifcopenshell.api.run("material.remove_profile", self.file, **{"profile": self.file.by_id(self.profile)})
|
2021-04-08 08:57:45 +10:00
|
|
|
Data.load_profiles()
|
2021-07-23 10:41:08 +10:00
|
|
|
ProfileData.load(self.file)
|
2021-04-08 08:57:45 +10:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2021-01-17 12:46:35 +11:00
|
|
|
class AddLayer(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.add_layer"
|
|
|
|
|
bl_label = "Add Layer"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
layer_set: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.add_layer",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-01-17 12:46:35 +11:00
|
|
|
"layer_set": self.file.by_id(self.layer_set),
|
|
|
|
|
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_layers()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2021-03-08 16:19:26 +11:00
|
|
|
class ReorderMaterialSetItem(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.reorder_material_set_item"
|
|
|
|
|
bl_label = "Reorder Material Set Item"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-03-08 14:20:43 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
old_index: bpy.props.IntProperty()
|
|
|
|
|
new_index: bpy.props.IntProperty()
|
2021-03-08 16:19:26 +11:00
|
|
|
material_set: bpy.props.IntProperty()
|
2021-03-08 14:20:43 +11:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-03-08 14:20:43 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-08 16:19:26 +11:00
|
|
|
material_set = self.file.by_id(self.material_set)
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.reorder_set_item",
|
2021-03-08 14:20:43 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-03-08 16:19:26 +11:00
|
|
|
"material_set": material_set,
|
2021-03-08 14:20:43 +11:00
|
|
|
"old_index": self.old_index,
|
|
|
|
|
"new_index": self.new_index,
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-03-08 16:19:26 +11:00
|
|
|
if material_set.is_a("IfcMaterialConstituentSet"):
|
|
|
|
|
Data.load_constituents()
|
|
|
|
|
elif material_set.is_a("IfcMaterialLayerSet"):
|
|
|
|
|
Data.load_layers()
|
|
|
|
|
elif material_set.is_a("IfcMaterialProfileSet"):
|
|
|
|
|
Data.load_profiles()
|
2021-07-23 10:41:08 +10:00
|
|
|
ProfileData.load(self.file)
|
2021-03-08 16:19:26 +11:00
|
|
|
elif material_set.is_a("IfcMaterialList"):
|
|
|
|
|
Data.load_lists()
|
2021-03-08 14:20:43 +11:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2021-01-17 12:46:35 +11:00
|
|
|
class RemoveLayer(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.remove_layer"
|
|
|
|
|
bl_label = "Remove Layer"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
layer: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run("material.remove_layer", self.file, **{"layer": self.file.by_id(self.layer)})
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_layers()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AddListItem(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.add_list_item"
|
|
|
|
|
bl_label = "Add List Item"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
list_item_set: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.add_list_item",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-01-17 12:46:35 +11:00
|
|
|
"material_list": self.file.by_id(self.list_item_set),
|
|
|
|
|
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_lists()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RemoveListItem(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.remove_list_item"
|
|
|
|
|
bl_label = "Remove List Item"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
list_item_set: bpy.props.IntProperty()
|
|
|
|
|
list_item: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.remove_list_item",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-01-17 12:46:35 +11:00
|
|
|
"material_list": self.file.by_id(self.list_item_set),
|
|
|
|
|
"material": self.file.by_id(self.list_item),
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_lists()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EnableEditingAssignedMaterial(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.enable_editing_assigned_material"
|
|
|
|
|
bl_label = "Enable Editing Assigned Material"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
props = obj.BIMObjectMaterialProperties
|
|
|
|
|
props.is_editing = True
|
|
|
|
|
product_data = Data.products[obj.BIMObjectProperties.ifc_definition_id]
|
|
|
|
|
|
|
|
|
|
if product_data["type"] == "IfcMaterial":
|
|
|
|
|
props.material = str(product_data["id"])
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-03-05 18:27:19 +11:00
|
|
|
material_set_class = product_data["type"]
|
2021-01-17 12:46:35 +11:00
|
|
|
if product_data["type"] == "IfcMaterialConstituentSet":
|
|
|
|
|
material_set_data = Data.constituent_sets[product_data["id"]]
|
|
|
|
|
elif product_data["type"] == "IfcMaterialLayerSet":
|
|
|
|
|
material_set_data = Data.layer_sets[product_data["id"]]
|
2021-03-05 18:27:19 +11:00
|
|
|
elif product_data["type"] == "IfcMaterialLayerSetUsage":
|
2021-06-09 11:23:34 +10:00
|
|
|
material_set_usage = Data.layer_set_usages[product_data["id"]]
|
|
|
|
|
material_set_data = Data.layer_sets[material_set_usage["ForLayerSet"]]
|
2021-03-05 18:27:19 +11:00
|
|
|
material_set_class = "IfcMaterialLayerSet"
|
2021-01-17 12:46:35 +11:00
|
|
|
elif product_data["type"] == "IfcMaterialProfileSet":
|
|
|
|
|
material_set_data = Data.profile_sets[product_data["id"]]
|
2021-04-15 18:38:28 +10:00
|
|
|
elif product_data["type"] == "IfcMaterialProfileSetUsage":
|
2021-06-09 11:23:34 +10:00
|
|
|
material_set_usage = Data.profile_set_usages[product_data["id"]]
|
|
|
|
|
material_set_data = Data.profile_sets[material_set_usage["ForProfileSet"]]
|
2021-04-15 18:38:28 +10:00
|
|
|
material_set_class = "IfcMaterialProfileSet"
|
2021-01-17 12:46:35 +11:00
|
|
|
elif product_data["type"] == "IfcMaterialList":
|
|
|
|
|
material_set_data = Data.lists[product_data["id"]]
|
|
|
|
|
else:
|
|
|
|
|
material_set_data = {}
|
|
|
|
|
|
2021-06-09 11:23:34 +10:00
|
|
|
while len(props.material_set_usage_attributes) > 0:
|
|
|
|
|
props.material_set_usage_attributes.remove(0)
|
|
|
|
|
|
|
|
|
|
if "Usage" in product_data["type"]:
|
|
|
|
|
blenderbim.bim.helper.import_attributes(
|
|
|
|
|
product_data["type"], props.material_set_usage_attributes, material_set_usage, self.import_attributes
|
|
|
|
|
)
|
|
|
|
|
|
2021-01-17 12:46:35 +11:00
|
|
|
while len(props.material_set_attributes) > 0:
|
|
|
|
|
props.material_set_attributes.remove(0)
|
|
|
|
|
|
2021-03-05 18:27:19 +11:00
|
|
|
for attribute in IfcStore.get_schema().declaration_by_name(material_set_class).all_attributes():
|
2021-01-17 12:46:35 +11:00
|
|
|
if "<string>" not in str(attribute.type_of_attribute):
|
|
|
|
|
continue
|
|
|
|
|
if attribute.name() in material_set_data:
|
|
|
|
|
new = props.material_set_attributes.add()
|
|
|
|
|
new.name = attribute.name()
|
|
|
|
|
new.is_null = material_set_data[attribute.name()] is None
|
|
|
|
|
new.string_value = "" if new.is_null else material_set_data[attribute.name()]
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-06-09 11:23:34 +10:00
|
|
|
def import_attributes(self, name, prop, data):
|
|
|
|
|
if name == "CardinalPoint":
|
|
|
|
|
# TODO: complain to buildingSMART
|
|
|
|
|
cardinal_point_map = {
|
|
|
|
|
1: "bottom left",
|
|
|
|
|
2: "bottom centre",
|
|
|
|
|
3: "bottom right",
|
|
|
|
|
4: "mid-depth left",
|
|
|
|
|
5: "mid-depth centre",
|
|
|
|
|
6: "mid-depth right",
|
|
|
|
|
7: "top left",
|
|
|
|
|
8: "top centre",
|
|
|
|
|
9: "top right",
|
|
|
|
|
10: "geometric centroid",
|
|
|
|
|
11: "bottom in line with the geometric centroid",
|
|
|
|
|
12: "left in line with the geometric centroid",
|
|
|
|
|
13: "right in line with the geometric centroid",
|
|
|
|
|
14: "top in line with the geometric centroid",
|
|
|
|
|
15: "shear centre",
|
|
|
|
|
16: "bottom in line with the shear centre",
|
|
|
|
|
17: "left in line with the shear centre",
|
|
|
|
|
18: "right in line with the shear centre",
|
|
|
|
|
19: "top in line with the shear centre",
|
|
|
|
|
}
|
|
|
|
|
prop.data_type = "enum"
|
|
|
|
|
prop.enum_items = json.dumps(cardinal_point_map)
|
|
|
|
|
if data[name]:
|
|
|
|
|
prop.enum_value = str(data[name])
|
|
|
|
|
return True
|
|
|
|
|
|
2021-01-17 12:46:35 +11:00
|
|
|
|
|
|
|
|
class DisableEditingAssignedMaterial(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.disable_editing_assigned_material"
|
|
|
|
|
bl_label = "Disable Editing Assigned Material"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
props = obj.BIMObjectMaterialProperties
|
|
|
|
|
props.is_editing = False
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EditAssignedMaterial(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.edit_assigned_material"
|
|
|
|
|
bl_label = "Edit Assigned Material"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
material_set: bpy.props.IntProperty()
|
2021-06-09 11:23:34 +10:00
|
|
|
material_set_usage: bpy.props.IntProperty()
|
2021-01-17 12:46:35 +11:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
props = obj.BIMObjectMaterialProperties
|
|
|
|
|
product_data = Data.products[obj.BIMObjectProperties.ifc_definition_id]
|
|
|
|
|
|
|
|
|
|
if product_data["type"] == "IfcMaterial":
|
|
|
|
|
bpy.ops.bim.unassign_material(obj=obj.name)
|
|
|
|
|
bpy.ops.bim.assign_material(obj=obj.name, material_type="IfcMaterial")
|
2021-03-25 10:48:31 +11:00
|
|
|
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
|
2021-01-17 12:46:35 +11:00
|
|
|
bpy.ops.bim.disable_editing_assigned_material(obj=obj.name)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-07-17 09:13:37 +10:00
|
|
|
material_set = self.file.by_id(self.material_set)
|
|
|
|
|
|
2021-01-17 12:46:35 +11:00
|
|
|
attributes = {}
|
|
|
|
|
for attribute in props.material_set_attributes:
|
|
|
|
|
attributes[attribute.name] = None if attribute.is_null else attribute.string_value
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.edit_assigned_material",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-06-09 11:23:34 +10:00
|
|
|
**{"element": material_set, "attributes": attributes},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-03-25 10:48:31 +11:00
|
|
|
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
|
2021-06-09 11:23:34 +10:00
|
|
|
|
|
|
|
|
if self.material_set_usage:
|
|
|
|
|
material_set_usage = self.file.by_id(self.material_set_usage)
|
|
|
|
|
attributes = blenderbim.bim.helper.export_attributes(props.material_set_usage_attributes)
|
|
|
|
|
if material_set_usage.is_a("IfcMaterialLayerSetUsage"):
|
2021-07-17 17:00:43 +10:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.edit_layer_usage",
|
|
|
|
|
self.file,
|
|
|
|
|
**{"usage": material_set_usage, "attributes": attributes},
|
|
|
|
|
)
|
2021-06-09 11:23:34 +10:00
|
|
|
Data.load_layer_usages()
|
|
|
|
|
elif material_set_usage.is_a("IfcMaterialProfileSetUsage"):
|
2021-07-17 17:00:43 +10:00
|
|
|
if attributes.get("CardinalPoint", None):
|
|
|
|
|
attributes["CardinalPoint"] = int(attributes["CardinalPoint"])
|
|
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.edit_profile_usage",
|
|
|
|
|
self.file,
|
|
|
|
|
**{"usage": material_set_usage, "attributes": attributes},
|
|
|
|
|
)
|
2021-06-09 11:23:34 +10:00
|
|
|
Data.load_profile_usages()
|
|
|
|
|
|
2021-01-17 12:46:35 +11:00
|
|
|
if material_set.is_a("IfcMaterialConstituentSet"):
|
|
|
|
|
Data.load_constituents()
|
|
|
|
|
elif material_set.is_a("IfcMaterialLayerSet"):
|
|
|
|
|
Data.load_layers()
|
|
|
|
|
elif material_set.is_a("IfcMaterialProfileSet"):
|
|
|
|
|
Data.load_profiles()
|
|
|
|
|
bpy.ops.bim.disable_editing_assigned_material(obj=obj.name)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EnableEditingMaterialSetItem(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.enable_editing_material_set_item"
|
|
|
|
|
bl_label = "Enable Editing Material Set Item"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
material_set_item: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
self.file = IfcStore.get_file()
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-04-08 21:03:37 +10:00
|
|
|
self.props = obj.BIMObjectMaterialProperties
|
|
|
|
|
self.props.active_material_set_item_id = self.material_set_item
|
2021-01-17 12:46:35 +11:00
|
|
|
product_data = Data.products[obj.BIMObjectProperties.ifc_definition_id]
|
|
|
|
|
material_set_item = self.file.by_id(self.material_set_item)
|
|
|
|
|
|
|
|
|
|
if product_data["type"] == "IfcMaterialConstituentSet":
|
|
|
|
|
material_set_item_data = Data.constituents[self.material_set_item]
|
2021-03-05 18:27:19 +11:00
|
|
|
elif product_data["type"] == "IfcMaterialLayerSet" or product_data["type"] == "IfcMaterialLayerSetUsage":
|
2021-01-17 12:46:35 +11:00
|
|
|
material_set_item_data = Data.layers[self.material_set_item]
|
2021-04-15 18:38:28 +10:00
|
|
|
elif product_data["type"] == "IfcMaterialProfileSet" or product_data["type"] == "IfcMaterialProfileSetUsage":
|
2021-01-17 12:46:35 +11:00
|
|
|
material_set_item_data = Data.profiles[self.material_set_item]
|
|
|
|
|
else:
|
|
|
|
|
material_set_item_data = {}
|
|
|
|
|
|
2021-04-08 21:03:37 +10:00
|
|
|
self.props.material_set_item_material = str(material_set_item_data["Material"])
|
2021-01-17 12:46:35 +11:00
|
|
|
|
2021-04-08 21:03:37 +10:00
|
|
|
self.load_set_item_attributes(material_set_item, material_set_item_data)
|
|
|
|
|
if material_set_item.is_a("IfcMaterialProfile"):
|
|
|
|
|
self.load_profile_attributes(material_set_item, material_set_item_data)
|
|
|
|
|
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
def load_set_item_attributes(self, material_set_item, material_set_item_data):
|
|
|
|
|
while len(self.props.material_set_item_attributes) > 0:
|
|
|
|
|
self.props.material_set_item_attributes.remove(0)
|
2021-01-17 12:46:35 +11:00
|
|
|
|
|
|
|
|
for attribute in IfcStore.get_schema().declaration_by_name(material_set_item.is_a()).all_attributes():
|
2021-03-24 16:09:29 +11:00
|
|
|
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
|
|
|
|
if data_type == "entity":
|
2021-01-17 12:46:35 +11:00
|
|
|
continue
|
|
|
|
|
if attribute.name() in material_set_item_data:
|
2021-04-08 21:03:37 +10:00
|
|
|
new = self.props.material_set_item_attributes.add()
|
2021-01-17 12:46:35 +11:00
|
|
|
new.name = attribute.name()
|
|
|
|
|
new.is_null = material_set_item_data[attribute.name()] is None
|
2021-03-24 16:09:29 +11:00
|
|
|
new.data_type = data_type
|
|
|
|
|
if data_type == "string":
|
2021-01-17 12:46:35 +11:00
|
|
|
new.string_value = "" if new.is_null else material_set_item_data[attribute.name()]
|
2021-03-24 16:09:29 +11:00
|
|
|
elif data_type == "float":
|
2021-01-17 12:46:35 +11:00
|
|
|
new.float_value = 0.0 if new.is_null else material_set_item_data[attribute.name()]
|
2021-03-24 16:09:29 +11:00
|
|
|
elif data_type == "integer":
|
2021-01-17 12:46:35 +11:00
|
|
|
new.int_value = 0 if new.is_null else material_set_item_data[attribute.name()]
|
2021-03-24 16:09:29 +11:00
|
|
|
elif data_type == "boolean":
|
2021-01-17 12:46:35 +11:00
|
|
|
new.bool_value = False if new.is_null else material_set_item_data[attribute.name()]
|
2021-04-08 21:03:37 +10:00
|
|
|
|
|
|
|
|
def load_profile_attributes(self, material_set_item, material_set_item_data):
|
|
|
|
|
while len(self.props.material_set_item_profile_attributes) > 0:
|
|
|
|
|
self.props.material_set_item_profile_attributes.remove(0)
|
|
|
|
|
|
|
|
|
|
if not material_set_item_data["Profile"]:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
profile = self.file.by_id(material_set_item_data["Profile"])
|
|
|
|
|
profile_data = ProfileData.profiles[material_set_item_data["Profile"]]
|
|
|
|
|
|
|
|
|
|
for attribute in IfcStore.get_schema().declaration_by_name(profile.is_a()).all_attributes():
|
|
|
|
|
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
|
|
|
|
if data_type == "entity":
|
|
|
|
|
continue
|
|
|
|
|
if attribute.name() in profile_data:
|
|
|
|
|
new = self.props.material_set_item_profile_attributes.add()
|
|
|
|
|
new.name = attribute.name()
|
|
|
|
|
new.is_null = profile_data[attribute.name()] is None
|
|
|
|
|
new.is_optional = attribute.optional()
|
|
|
|
|
new.data_type = data_type
|
|
|
|
|
if data_type == "string":
|
|
|
|
|
new.string_value = "" if new.is_null else profile_data[attribute.name()]
|
|
|
|
|
elif data_type == "float":
|
|
|
|
|
new.float_value = 0.0 if new.is_null else profile_data[attribute.name()]
|
|
|
|
|
elif data_type == "integer":
|
|
|
|
|
new.int_value = 0 if new.is_null else profile_data[attribute.name()]
|
|
|
|
|
elif data_type == "boolean":
|
|
|
|
|
new.bool_value = False if new.is_null else profile_data[attribute.name()]
|
|
|
|
|
elif data_type == "enum":
|
|
|
|
|
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
|
|
|
|
|
if profile_data[attribute.name()]:
|
|
|
|
|
new.enum_value = profile_data[attribute.name()]
|
|
|
|
|
|
|
|
|
|
# Force null to be false if the attribute is mandatory because when we first assign a profile, all of
|
|
|
|
|
# its fields are null (which is illegal).
|
|
|
|
|
# TODO: find a better solution.
|
|
|
|
|
if not new.is_optional:
|
|
|
|
|
new.is_null = False
|
2021-01-17 12:46:35 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DisableEditingMaterialSetItem(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.disable_editing_material_set_item"
|
|
|
|
|
bl_label = "Disable Editing Material Set Item"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
props = obj.BIMObjectMaterialProperties
|
|
|
|
|
props.active_material_set_item_id = 0
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EditMaterialSetItem(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.edit_material_set_item"
|
|
|
|
|
bl_label = "Edit Material Set Item"
|
2021-07-05 18:58:55 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-17 12:46:35 +11:00
|
|
|
obj: bpy.props.StringProperty()
|
|
|
|
|
material_set_item: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-05 18:58:55 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-07-29 23:08:17 +02:00
|
|
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
props = obj.BIMObjectMaterialProperties
|
|
|
|
|
product_data = Data.products[obj.BIMObjectProperties.ifc_definition_id]
|
|
|
|
|
|
2021-08-16 09:15:43 +10:00
|
|
|
attributes = blenderbim.bim.helper.export_attributes(props.material_set_item_attributes)
|
2021-01-17 12:46:35 +11:00
|
|
|
|
|
|
|
|
if product_data["type"] == "IfcMaterialConstituentSet":
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.edit_constituent",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-01-17 12:46:35 +11:00
|
|
|
"constituent": self.file.by_id(self.material_set_item),
|
|
|
|
|
"attributes": attributes,
|
|
|
|
|
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material_set_item_material)),
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_constituents()
|
2021-03-05 18:27:19 +11:00
|
|
|
elif product_data["type"] == "IfcMaterialLayerSet" or product_data["type"] == "IfcMaterialLayerSetUsage":
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.edit_layer",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-01-17 12:46:35 +11:00
|
|
|
"layer": self.file.by_id(self.material_set_item),
|
|
|
|
|
"attributes": attributes,
|
|
|
|
|
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material_set_item_material)),
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_layers()
|
2021-04-15 18:38:28 +10:00
|
|
|
elif product_data["type"] == "IfcMaterialProfileSet" or product_data["type"] == "IfcMaterialProfileSetUsage":
|
2021-08-16 09:15:43 +10:00
|
|
|
profile_attributes = blenderbim.bim.helper.export_attributes(props.material_set_item_profile_attributes)
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.edit_profile",
|
2021-01-17 12:46:35 +11:00
|
|
|
self.file,
|
2021-03-27 22:52:52 +11:00
|
|
|
**{
|
2021-01-17 12:46:35 +11:00
|
|
|
"profile": self.file.by_id(self.material_set_item),
|
|
|
|
|
"attributes": attributes,
|
2021-04-08 21:03:37 +10:00
|
|
|
"profile_attributes": profile_attributes,
|
2021-01-17 12:46:35 +11:00
|
|
|
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material_set_item_material)),
|
|
|
|
|
},
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-01-17 12:46:35 +11:00
|
|
|
Data.load_profiles()
|
2021-04-08 21:03:37 +10:00
|
|
|
ProfileData.load(self.file)
|
2021-01-17 12:46:35 +11:00
|
|
|
else:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
bpy.ops.bim.disable_editing_material_set_item(obj=obj.name)
|
|
|
|
|
return {"FINISHED"}
|
2021-08-08 20:13:24 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CopyMaterial(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.copy_material"
|
|
|
|
|
bl_label = "Copy Material"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
|
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
material = ifcopenshell.util.element.get_material(
|
|
|
|
|
self.file.by_id(context.active_object.BIMObjectProperties.ifc_definition_id)
|
|
|
|
|
)
|
|
|
|
|
for obj in context.selected_objects:
|
|
|
|
|
if obj == context.active_object:
|
|
|
|
|
continue
|
|
|
|
|
if not obj.BIMObjectProperties.ifc_definition_id:
|
|
|
|
|
continue
|
|
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"material.copy_material",
|
|
|
|
|
self.file,
|
|
|
|
|
**{
|
|
|
|
|
"material": material,
|
|
|
|
|
"element": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
Data.load(self.file, obj.BIMObjectProperties.ifc_definition_id)
|
|
|
|
|
self.set_default_material(obj, material)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
def set_default_material(self, obj, material):
|
|
|
|
|
object_material_ids = [
|
|
|
|
|
om.BIMObjectProperties.ifc_definition_id
|
|
|
|
|
for om in obj.data.materials
|
|
|
|
|
if om is not None and om.BIMObjectProperties.ifc_definition_id
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if material.id() in object_material_ids:
|
|
|
|
|
return
|
|
|
|
|
obj.data.materials.append(IfcStore.get_element(material.id()))
|