mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
@@ -178,23 +178,23 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
||||
|
||||
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
||||
|
||||
element = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||
result = add_representation.Usecase(
|
||||
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||
new_representation = add_representation.Usecase(
|
||||
self.file,
|
||||
{
|
||||
"context": element.ContextOfItems,
|
||||
"context": old_representation.ContextOfItems,
|
||||
"geometry": obj.data,
|
||||
"total_items": max(1, len(obj.material_slots)),
|
||||
},
|
||||
).execute()
|
||||
if not result:
|
||||
if not new_representation:
|
||||
print("Failed to write shape representation")
|
||||
return {"FINISHED"}
|
||||
|
||||
assign_styles.Usecase(
|
||||
self.file,
|
||||
{
|
||||
"shape_representation": result,
|
||||
"shape_representation": new_representation,
|
||||
"styles": [
|
||||
self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id)
|
||||
for s in obj.material_slots
|
||||
@@ -204,9 +204,12 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
||||
).execute()
|
||||
|
||||
# TODO: move this into a replace_representation usecase or something
|
||||
for inverse in self.file.get_inverse(element):
|
||||
ifcopenshell.util.element.replace_attribute(inverse, element, result)
|
||||
obj.data.BIMMeshProperties.ifc_definition_id = int(result.id())
|
||||
for inverse in self.file.get_inverse(old_representation):
|
||||
ifcopenshell.util.element.replace_attribute(inverse, old_representation, new_representation)
|
||||
|
||||
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)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -6,4 +6,17 @@ class Usecase:
|
||||
self.settings[key] = value
|
||||
|
||||
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