mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Fix #2106. You can now assign an opening to another element.
This commit is contained in:
@@ -34,25 +34,34 @@ class AddOpening(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
props = context.scene.BIMModelProperties
|
props = context.scene.BIMModelProperties
|
||||||
if len(context.selected_objects) != 2:
|
if len(context.selected_objects) != 2:
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
# The convention is that element1 is the element and element2 is the opening.
|
||||||
obj1, obj2 = context.selected_objects
|
obj1, obj2 = context.selected_objects
|
||||||
element1 = tool.Ifc.get_entity(obj1)
|
element1 = tool.Ifc.get_entity(obj1)
|
||||||
element2 = tool.Ifc.get_entity(obj2)
|
element2 = tool.Ifc.get_entity(obj2)
|
||||||
if type(element1) == type(element2):
|
|
||||||
if (
|
if not element1 and not element2:
|
||||||
element1
|
return {"FINISHED"} # Both are not IFC objects.
|
||||||
and element2
|
|
||||||
and not element1.is_a("IfcOpeningElement")
|
if element1 and element2:
|
||||||
and not element2.is_a("IfcOpeningElement")
|
if element1.is_a("IfcOpeningElement") and element2.is_a("IfcOpeningElement"):
|
||||||
):
|
return {"FINISHED"} # You can't add an opening to another opening.
|
||||||
if element1.is_a("IfcWindow") or element1.is_a("IfcDoor"):
|
elif not element1.is_a("IfcOpeningElement") and not element2.is_a("IfcOpeningElement"):
|
||||||
|
if element1.is_a("IfcWindow") or element1.is_a("IfcDoor"): # Add a fill to an element.
|
||||||
obj1, obj2 = obj2, obj1
|
obj1, obj2 = obj2, obj1
|
||||||
FilledOpeningGenerator().generate(obj2, obj1, target=obj2.matrix_world.translation)
|
FilledOpeningGenerator().generate(obj2, obj1, target=obj2.matrix_world.translation)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
elif element1.is_a("IfcOpeningElement") or element2.is_a("IfcOpeningElement"):
|
||||||
|
if element1.is_a("IfcOpeningElement"): # Reassign an opening to another element.
|
||||||
|
obj1, obj2 = obj2, obj1
|
||||||
|
element1, element2 = element2, element1
|
||||||
|
|
||||||
if element2 and not element1:
|
if element2 and not element1:
|
||||||
obj1, obj2 = obj2, obj1
|
obj1, obj2 = obj2, obj1
|
||||||
element1, element2 = element2, element1
|
element1, element2 = element2, element1
|
||||||
|
|
||||||
if element1.is_a("IfcOpeningElement"):
|
if element1.is_a("IfcOpeningElement"):
|
||||||
return {"FINISHED"}
|
return {"FINISHED"} # You can't add an opening to another opening.
|
||||||
|
|
||||||
if tool.Ifc.is_moved(obj1):
|
if tool.Ifc.is_moved(obj1):
|
||||||
blenderbim.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj1)
|
blenderbim.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj1)
|
||||||
@@ -64,17 +73,21 @@ class AddOpening(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
break
|
break
|
||||||
|
|
||||||
body_context = ifcopenshell.util.representation.get_context(IfcStore.get_file(), "Model", "Body")
|
body_context = ifcopenshell.util.representation.get_context(IfcStore.get_file(), "Model", "Body")
|
||||||
element2 = blenderbim.core.root.assign_class(
|
if not element2:
|
||||||
tool.Ifc,
|
element2 = blenderbim.core.root.assign_class(
|
||||||
tool.Collector,
|
tool.Ifc,
|
||||||
tool.Root,
|
tool.Collector,
|
||||||
obj=obj2,
|
tool.Root,
|
||||||
ifc_class="IfcOpeningElement",
|
obj=obj2,
|
||||||
should_add_representation=True,
|
ifc_class="IfcOpeningElement",
|
||||||
context=body_context,
|
should_add_representation=True,
|
||||||
)
|
context=body_context,
|
||||||
|
)
|
||||||
ifcopenshell.api.run("void.add_opening", tool.Ifc.get(), opening=element2, element=element1)
|
ifcopenshell.api.run("void.add_opening", tool.Ifc.get(), opening=element2, element=element1)
|
||||||
|
|
||||||
|
if tool.Ifc.is_moved(obj2):
|
||||||
|
blenderbim.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj2)
|
||||||
|
|
||||||
voided_objs = [obj1]
|
voided_objs = [obj1]
|
||||||
for subelement in ifcopenshell.util.element.get_decomposition(element1):
|
for subelement in ifcopenshell.util.element.get_decomposition(element1):
|
||||||
subobj = tool.Ifc.get_object(subelement)
|
subobj = tool.Ifc.get_object(subelement)
|
||||||
|
|||||||
Reference in New Issue
Block a user