mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
fix issue removing currently active representation
previously it would remove the object, now it's going to switch to some other representation
This commit is contained in:
@@ -183,18 +183,18 @@ def remove_representation(
|
|||||||
for element in geometry.get_elements_of_type(element_type):
|
for element in geometry.get_elements_of_type(element_type):
|
||||||
obj = ifc.get_object(element)
|
obj = ifc.get_object(element)
|
||||||
if obj:
|
if obj:
|
||||||
obj = geometry.replace_object_with_empty(obj)
|
geometry.switch_from_representation(obj, representation)
|
||||||
obj = ifc.get_object(element_type)
|
obj = ifc.get_object(element_type)
|
||||||
if obj:
|
if obj:
|
||||||
obj = geometry.replace_object_with_empty(obj)
|
geometry.switch_from_representation(obj, representation)
|
||||||
ifc.run("geometry.unassign_representation", product=element_type, representation=representation)
|
ifc.run("geometry.unassign_representation", product=element_type, representation=representation)
|
||||||
ifc.run("geometry.remove_representation", representation=representation)
|
|
||||||
else:
|
else:
|
||||||
data = geometry.get_representation_data(representation)
|
data = geometry.get_representation_data(representation)
|
||||||
if data and geometry.has_data_users(data):
|
if data and geometry.has_data_users(data):
|
||||||
geometry.replace_object_with_empty(obj)
|
geometry.switch_from_representation(obj, representation)
|
||||||
ifc.run("geometry.unassign_representation", product=element, representation=representation)
|
ifc.run("geometry.unassign_representation", product=element, representation=representation)
|
||||||
ifc.run("geometry.remove_representation", representation=representation)
|
|
||||||
|
ifc.run("geometry.remove_representation", representation=representation)
|
||||||
if data:
|
if data:
|
||||||
geometry.delete_data(data)
|
geometry.delete_data(data)
|
||||||
|
|
||||||
|
|||||||
@@ -862,6 +862,42 @@ class Geometry(blenderbim.core.tool.Geometry):
|
|||||||
apply_openings=True,
|
apply_openings=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def switch_from_representation(cls, obj: bpy.types.Object, representation: ifcopenshell.entity_instance) -> None:
|
||||||
|
"""Switch object representation to any other besides `representation`.
|
||||||
|
|
||||||
|
If no other representation present, will replace object with an empty.
|
||||||
|
Method assumes that `obj` does have a current representation (it could be not `representation`).
|
||||||
|
"""
|
||||||
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
assert element
|
||||||
|
|
||||||
|
active_representation = tool.Geometry.get_active_representation(obj)
|
||||||
|
active_representation = tool.Geometry.resolve_mapped_representation(active_representation)
|
||||||
|
if active_representation != representation:
|
||||||
|
return
|
||||||
|
|
||||||
|
new_representation = None
|
||||||
|
for r in cls.get_representations_iter(element):
|
||||||
|
if r != representation:
|
||||||
|
new_representation = r
|
||||||
|
break
|
||||||
|
|
||||||
|
# `representation` is the only representation for object.
|
||||||
|
if new_representation is None:
|
||||||
|
cls.replace_object_with_empty(obj)
|
||||||
|
return
|
||||||
|
|
||||||
|
blenderbim.core.geometry.switch_representation(
|
||||||
|
tool.Ifc,
|
||||||
|
tool.Geometry,
|
||||||
|
obj=obj,
|
||||||
|
representation=new_representation,
|
||||||
|
should_reload=False,
|
||||||
|
should_sync_changes_first=False,
|
||||||
|
is_global=True,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def remove_representation_item(cls, representation_item: ifcopenshell.entity_instance) -> None:
|
def remove_representation_item(cls, representation_item: ifcopenshell.entity_instance) -> None:
|
||||||
# NOTE: we assume it's not the last representation item
|
# NOTE: we assume it's not the last representation item
|
||||||
|
|||||||
Reference in New Issue
Block a user