Implement assigning material definition representation styles

This commit is contained in:
Dion Moult
2021-07-10 22:06:11 +10:00
parent 6ccb208345
commit 1d523c9636
6 changed files with 105 additions and 7 deletions
@@ -118,7 +118,7 @@ class AddRepresentation(bpy.types.Operator):
]
ifcopenshell.api.run(
"geometry.assign_styles",
"style.assign_representation_styles",
self.file,
**{
"shape_representation": result,
@@ -331,7 +331,7 @@ class UpdateRepresentation(bpy.types.Operator):
]
ifcopenshell.api.run(
"geometry.assign_styles",
"style.assign_representation_styles",
self.file,
**{
"shape_representation": new_representation,
@@ -2,6 +2,7 @@ import bpy
import json
import ifcopenshell.api
import ifcopenshell.util.attribute
import ifcopenshell.util.representation
import blenderbim.bim.helper
from blenderbim.bim.module.material.prop import purge as material_prop_purge
from blenderbim.bim.ifc import IfcStore
@@ -53,6 +54,14 @@ class AddMaterial(bpy.types.Operator):
self.file = IfcStore.get_file()
result = ifcopenshell.api.run("material.add_material", self.file, **{"name": obj.name})
obj.BIMObjectProperties.ifc_definition_id = result.id()
if obj.BIMMaterialProperties.ifc_style_id:
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
if context:
ifcopenshell.api.run("style.assign_material_style", self.file, **{
"material": result,
"style": self.file.by_id(obj.BIMMaterialProperties.ifc_style_id),
"context": context,
})
Data.load(IfcStore.get_file())
material_prop_purge()
return {"FINISHED"}
@@ -1,5 +1,6 @@
import bpy
import ifcopenshell.api
import ifcopenshell.util.representation
import blenderbim.bim.helper
from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.style.data import Data
@@ -74,6 +75,14 @@ class AddStyle(bpy.types.Operator):
settings["external_definition"] = None # TODO: Implement. See #1222
style = ifcopenshell.api.run("style.add_style", self.file, **settings)
material.BIMMaterialProperties.ifc_style_id = style.id()
if material.BIMObjectProperties.ifc_definition_id:
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
if context:
ifcopenshell.api.run("style.assign_material_style", self.file, **{
"material": self.file.by_id(material.BIMObjectProperties.ifc_definition_id),
"style": style,
"context": context,
})
return {"FINISHED"}