mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 02:31:09 +00:00
IFC Join - fix error joining representation items (6ce4b5d)
It was trying to reaccess already removed ifc_definition_id leading to an error. Now we update id with a new item.
This commit is contained in:
@@ -1586,24 +1586,31 @@ class OverrideJoin(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
if tool.Geometry.is_meshlike_item(item):
|
if tool.Geometry.is_meshlike_item(item):
|
||||||
tool.Geometry.dissolve_triangulated_edges(self.target)
|
tool.Geometry.dissolve_triangulated_edges(self.target)
|
||||||
item_objs = [i.obj for i in props.item_objs if i.obj]
|
item_objs = [i.obj for i in props.item_objs if i.obj]
|
||||||
joined_objs: list[bpy.types.Object] = []
|
joined_ifc_item_objs: list[bpy.types.Object] = []
|
||||||
for selected_obj in context.selected_editable_objects:
|
for selected_obj in context.selected_editable_objects:
|
||||||
if selected_obj in item_objs:
|
if selected_obj in item_objs:
|
||||||
if selected_obj != self.target:
|
if selected_obj != self.target:
|
||||||
tool.Geometry.dissolve_triangulated_edges(selected_obj)
|
tool.Geometry.dissolve_triangulated_edges(selected_obj)
|
||||||
joined_objs.append(selected_obj)
|
joined_ifc_item_objs.append(selected_obj)
|
||||||
else:
|
else:
|
||||||
selected_obj.select_set(False)
|
selected_obj.select_set(False)
|
||||||
bpy.ops.object.join()
|
|
||||||
tool.Geometry.edit_meshlike_item(self.target)
|
|
||||||
|
|
||||||
for joined_obj in joined_objs:
|
bpy.ops.object.join()
|
||||||
|
new_item = tool.Geometry.edit_meshlike_item(self.target)
|
||||||
|
for joined_obj in joined_ifc_item_objs:
|
||||||
tool.Geometry.delete_ifc_item(joined_obj)
|
tool.Geometry.delete_ifc_item(joined_obj)
|
||||||
|
|
||||||
items_data = [dict(i) for i in props.item_objs if i.obj]
|
# Refresh `item_objs`.
|
||||||
|
items_data = {i.obj: i.ifc_definition_id for i in props.item_objs if i.obj}
|
||||||
props.item_objs.clear()
|
props.item_objs.clear()
|
||||||
for item_data in items_data:
|
if new_item:
|
||||||
props.add_item_object(item_data["obj"], ifc_file.by_id(item_data["ifc_definition_id"]))
|
items_data[self.target] = new_item.id()
|
||||||
|
for obj, ifc_id in items_data.items():
|
||||||
|
props.add_item_object(obj, ifc_file.by_id(ifc_id))
|
||||||
|
|
||||||
|
if new_item is None:
|
||||||
|
tool.Root.reload_item_decorator()
|
||||||
|
return
|
||||||
|
|
||||||
assert (rep_obj := props.representation_obj)
|
assert (rep_obj := props.representation_obj)
|
||||||
tool.Geometry.reload_representation(rep_obj)
|
tool.Geometry.reload_representation(rep_obj)
|
||||||
|
|||||||
@@ -1872,7 +1872,10 @@ class Geometry(bonsai.core.tool.Geometry):
|
|||||||
tool.Feature.get_boolean_props().is_editing = False
|
tool.Feature.get_boolean_props().is_editing = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def edit_meshlike_item(cls, obj: bpy.types.Object) -> None:
|
def edit_meshlike_item(cls, obj: bpy.types.Object) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
|
"""
|
||||||
|
:return: New IfcRepresentationItem or ``None`` if mesh hasn't changed.
|
||||||
|
"""
|
||||||
item = tool.Geometry.get_active_representation(obj)
|
item = tool.Geometry.get_active_representation(obj)
|
||||||
assert item
|
assert item
|
||||||
assert isinstance(obj.data, (bpy.types.Curve, bpy.types.Mesh))
|
assert isinstance(obj.data, (bpy.types.Curve, bpy.types.Mesh))
|
||||||
@@ -1902,6 +1905,7 @@ class Geometry(bonsai.core.tool.Geometry):
|
|||||||
ifcopenshell.util.element.remove_deep2(tool.Ifc.get(), item)
|
ifcopenshell.util.element.remove_deep2(tool.Ifc.get(), item)
|
||||||
tool.Ifc.link(new_item, obj.data)
|
tool.Ifc.link(new_item, obj.data)
|
||||||
cls.reload_representation(rep_obj)
|
cls.reload_representation(rep_obj)
|
||||||
|
return new_item
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def split_by_loose_parts(cls, obj: bpy.types.Object) -> List[bpy.types.Mesh]:
|
def split_by_loose_parts(cls, obj: bpy.types.Object) -> List[bpy.types.Mesh]:
|
||||||
|
|||||||
Reference in New Issue
Block a user