mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
You can now reinsert windows and doors into other hosts
This commit is contained in:
@@ -40,29 +40,33 @@ class AddElementOpening(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.add_element_opening"
|
||||
bl_label = "Add Element Opening"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
voided_building_element: bpy.props.StringProperty()
|
||||
filling_building_element: bpy.props.StringProperty()
|
||||
voided_obj: bpy.props.StringProperty()
|
||||
filling_obj: bpy.props.StringProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
voided_obj = bpy.data.objects.get(self.voided_building_element)
|
||||
filling_obj = bpy.data.objects.get(self.filling_building_element)
|
||||
voided_obj = bpy.data.objects.get(self.voided_obj)
|
||||
filling_obj = bpy.data.objects.get(self.filling_obj)
|
||||
filling = tool.Ifc.get_entity(filling_obj)
|
||||
|
||||
if not voided_obj or not filling_obj:
|
||||
return {"FINISHED"}
|
||||
|
||||
element = tool.Ifc.get_entity(voided_obj)
|
||||
local_location = voided_obj.matrix_world.inverted() @ context.scene.cursor.location
|
||||
raycast = voided_obj.closest_point_on_mesh(local_location, distance=0.01)
|
||||
target = context.scene.cursor.location
|
||||
raycast = voided_obj.closest_point_on_mesh(voided_obj.matrix_world.inverted() @ target, distance=0.01)
|
||||
if not raycast[0]:
|
||||
return {"FINISHED"}
|
||||
target = filling_obj.matrix_world.col[3].to_3d().copy()
|
||||
raycast = voided_obj.closest_point_on_mesh(voided_obj.matrix_world.inverted() @ target, distance=0.5)
|
||||
if not raycast[0]:
|
||||
return {"FINISHED"}
|
||||
|
||||
axis = [voided_obj.matrix_world @ Vector((0, 0, 0)), voided_obj.matrix_world @ Vector((1, 0, 0))]
|
||||
|
||||
# In this prototype, we assume openings are only added to axis-based elements
|
||||
axis = [voided_obj.matrix_world @ Vector((0, 0, 0)), voided_obj.matrix_world @ Vector((1, 0, 0))]
|
||||
new_matrix = voided_obj.matrix_world.copy()
|
||||
new_matrix.col[3] = tool.Cad.point_on_edge(context.scene.cursor.location, axis).to_4d()
|
||||
new_matrix.col[3] = tool.Cad.point_on_edge(target, axis).to_4d()
|
||||
if filling.is_a("IfcWindow"):
|
||||
new_matrix[2][3] = context.scene.cursor.location[2]
|
||||
new_matrix[2][3] = target[2]
|
||||
filling_obj.matrix_world = new_matrix
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
|
||||
@@ -147,9 +147,7 @@ class AddConstrTypeInstance(bpy.types.Operator):
|
||||
):
|
||||
if instance_class in ["IfcWindow", "IfcDoor"]:
|
||||
# TODO For now we are hardcoding windows and doors as a prototype
|
||||
bpy.ops.bim.add_element_opening(
|
||||
voided_building_element=building_obj.name, filling_building_element=obj.name
|
||||
)
|
||||
bpy.ops.bim.add_element_opening(voided_obj=building_obj.name, filling_obj=obj.name)
|
||||
elif self.link_to_scene:
|
||||
if collection_obj and collection_obj.BIMObjectProperties.ifc_definition_id:
|
||||
obj.location[2] = collection_obj.location[2] - min([v[2] for v in obj.bound_box])
|
||||
|
||||
@@ -38,6 +38,10 @@ class AddOpening(bpy.types.Operator, tool.Ifc.Operator):
|
||||
element1 = tool.Ifc.get_entity(obj1)
|
||||
element2 = tool.Ifc.get_entity(obj2)
|
||||
if type(element1) == type(element2):
|
||||
if element1 and element2:
|
||||
if element1.is_a("IfcWindow") or element1.is_a("IfcDoor"):
|
||||
obj1, obj2 = obj2, obj1
|
||||
bpy.ops.bim.add_element_opening(voided_obj=obj1.name, filling_obj=obj2.name)
|
||||
return {"FINISHED"}
|
||||
if element2 and not element1:
|
||||
obj1, obj2 = obj2, obj1
|
||||
|
||||
@@ -49,18 +49,6 @@ class BIM_PT_voids(Panel):
|
||||
row = self.layout.row(align=True)
|
||||
if len(context.selected_objects) == 2:
|
||||
op = row.operator("bim.add_opening", icon="ADD", text="Add Opening")
|
||||
for obj in context.selected_objects:
|
||||
if (
|
||||
"IfcOpeningElement" in obj.name
|
||||
or "IfcOpeningStandardCase" in obj.name
|
||||
or not obj.BIMObjectProperties.ifc_definition_id
|
||||
):
|
||||
op.opening = obj.name
|
||||
elif len(obj.children) == 1 and not obj.children[0].BIMObjectProperties.ifc_definition_id:
|
||||
op.opening = obj.children[0].name
|
||||
else:
|
||||
op.obj = obj.name
|
||||
|
||||
opening_id = None
|
||||
obj_name = None
|
||||
for obj in context.selected_objects:
|
||||
|
||||
Reference in New Issue
Block a user