mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 22:31:55 +00:00
Fix #2936. Unassigning a type now also unmaps representations.
This commit is contained in:
@@ -64,19 +64,51 @@ class UnassignType(bpy.types.Operator):
|
|||||||
return IfcStore.execute_ifc_operator(self, context)
|
return IfcStore.execute_ifc_operator(self, context)
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
|
def exclude_callback(attribute):
|
||||||
|
return attribute.is_a("IfcProfileDef") and attribute.ProfileName
|
||||||
|
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
related_objects = (
|
objs = (
|
||||||
[bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects
|
[bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects
|
||||||
)
|
)
|
||||||
for related_object in related_objects:
|
for obj in objs:
|
||||||
oprops = related_object.BIMObjectProperties
|
element = tool.Ifc.get_entity(obj)
|
||||||
ifcopenshell.api.run(
|
if not element or element.is_a("IfcElementType"):
|
||||||
"type.unassign_type",
|
continue
|
||||||
self.file,
|
ifcopenshell.api.run("type.unassign_type", self.file, related_object=element)
|
||||||
**{
|
|
||||||
"related_object": self.file.by_id(oprops.ifc_definition_id),
|
active_representation = tool.Geometry.get_active_representation(obj)
|
||||||
},
|
active_context = active_representation.ContextOfItems
|
||||||
)
|
new_active_representation = None
|
||||||
|
|
||||||
|
if element.Representation:
|
||||||
|
representations = []
|
||||||
|
for representation in element.Representation.Representations:
|
||||||
|
resolved_representation = ifcopenshell.util.representation.resolve_representation(representation)
|
||||||
|
if representation == resolved_representation:
|
||||||
|
print('appending', representation)
|
||||||
|
representations.append(representation)
|
||||||
|
else:
|
||||||
|
print('copying', representation)
|
||||||
|
# We must unmap representations.
|
||||||
|
copied_representation = ifcopenshell.util.element.copy_deep(
|
||||||
|
tool.Ifc.get(), resolved_representation, exclude=["IfcGeometricRepresentationContext"], exclude_callback=exclude_callback
|
||||||
|
)
|
||||||
|
representations.append(copied_representation)
|
||||||
|
if representation.ContextOfItems == active_context:
|
||||||
|
new_active_representation = copied_representation
|
||||||
|
element.Representation.Representations = representations
|
||||||
|
|
||||||
|
if new_active_representation:
|
||||||
|
blenderbim.core.geometry.switch_representation(
|
||||||
|
tool.Ifc,
|
||||||
|
tool.Geometry,
|
||||||
|
obj=obj,
|
||||||
|
representation=new_active_representation,
|
||||||
|
should_reload=False,
|
||||||
|
is_global=False,
|
||||||
|
should_sync_changes_first=False,
|
||||||
|
)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user