mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 09:02:29 +00:00
@@ -178,23 +178,23 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
|||||||
|
|
||||||
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
||||||
|
|
||||||
element = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||||
result = add_representation.Usecase(
|
new_representation = add_representation.Usecase(
|
||||||
self.file,
|
self.file,
|
||||||
{
|
{
|
||||||
"context": element.ContextOfItems,
|
"context": old_representation.ContextOfItems,
|
||||||
"geometry": obj.data,
|
"geometry": obj.data,
|
||||||
"total_items": max(1, len(obj.material_slots)),
|
"total_items": max(1, len(obj.material_slots)),
|
||||||
},
|
},
|
||||||
).execute()
|
).execute()
|
||||||
if not result:
|
if not new_representation:
|
||||||
print("Failed to write shape representation")
|
print("Failed to write shape representation")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
assign_styles.Usecase(
|
assign_styles.Usecase(
|
||||||
self.file,
|
self.file,
|
||||||
{
|
{
|
||||||
"shape_representation": result,
|
"shape_representation": new_representation,
|
||||||
"styles": [
|
"styles": [
|
||||||
self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id)
|
self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id)
|
||||||
for s in obj.material_slots
|
for s in obj.material_slots
|
||||||
@@ -204,9 +204,12 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
|||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
# TODO: move this into a replace_representation usecase or something
|
# TODO: move this into a replace_representation usecase or something
|
||||||
for inverse in self.file.get_inverse(element):
|
for inverse in self.file.get_inverse(old_representation):
|
||||||
ifcopenshell.util.element.replace_attribute(inverse, element, result)
|
ifcopenshell.util.element.replace_attribute(inverse, old_representation, new_representation)
|
||||||
obj.data.BIMMeshProperties.ifc_definition_id = int(result.id())
|
|
||||||
|
obj.data.BIMMeshProperties.ifc_definition_id = int(new_representation.id())
|
||||||
|
obj.data.name = f"{old_representation.ContextOfItems.id()}/{new_representation.id()}"
|
||||||
|
bpy.ops.bim.remove_representation(ifc_definition_id=old_representation.id())
|
||||||
Data.load(obj.BIMObjectProperties.ifc_definition_id)
|
Data.load(obj.BIMObjectProperties.ifc_definition_id)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,17 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
self.file.remove(self.settings["representation"])
|
styles = []
|
||||||
|
for subelement in self.file.traverse(self.settings["representation"]):
|
||||||
|
if subelement.is_a("IfcRepresentationItem") and subelement.StyledByItem:
|
||||||
|
styles.append(subelement)
|
||||||
|
for style in styles:
|
||||||
|
self.remove_deep(style)
|
||||||
|
self.remove_deep(self.settings["representation"])
|
||||||
|
|
||||||
|
def remove_deep(self, element):
|
||||||
|
subgraph = list(self.file.traverse(element))
|
||||||
|
subgraph_set = set(subgraph)
|
||||||
|
for ref in subgraph[::-1]:
|
||||||
|
if ref.id() and len(set(self.file.get_inverse(ref)) - subgraph_set) == 0:
|
||||||
|
self.file.remove(ref)
|
||||||
|
|||||||
Reference in New Issue
Block a user