mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 11:18:18 +00:00
quickly connect mep elements if they have matching ports
Demo - https://imgur.com/a/o9u8M1u
This commit is contained in:
@@ -34,6 +34,7 @@ classes = (
|
|||||||
operator.RemovePort,
|
operator.RemovePort,
|
||||||
operator.RemoveSystem,
|
operator.RemoveSystem,
|
||||||
operator.SelectSystemProducts,
|
operator.SelectSystemProducts,
|
||||||
|
operator.MEPConnectElements,
|
||||||
operator.SetFlowDirection,
|
operator.SetFlowDirection,
|
||||||
operator.ShowPorts,
|
operator.ShowPorts,
|
||||||
operator.UnassignSystem,
|
operator.UnassignSystem,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import blenderbim.core.system as core
|
|||||||
import blenderbim.bim.handler
|
import blenderbim.bim.handler
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim.module.system.data import PortData
|
from blenderbim.bim.module.system.data import PortData
|
||||||
|
from mathutils import Matrix
|
||||||
|
|
||||||
|
|
||||||
class Operator:
|
class Operator:
|
||||||
@@ -215,6 +216,46 @@ class DisconnectPort(bpy.types.Operator, Operator):
|
|||||||
core.disconnect_port(tool.Ifc, port=element)
|
core.disconnect_port(tool.Ifc, port=element)
|
||||||
|
|
||||||
|
|
||||||
|
class MEPConnectElements(bpy.types.Operator, Operator):
|
||||||
|
bl_idname = "bim.mep_connect_elements"
|
||||||
|
bl_label = "Connect MEP Elements"
|
||||||
|
bl_description = "Connects two selected elements if they have ports with matching location"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return len(context.selected_objects) == 2
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
obj1 = context.active_object
|
||||||
|
obj2 = next(o for o in context.selected_objects if o != obj1)
|
||||||
|
|
||||||
|
el1 = tool.Ifc.get_entity(obj1)
|
||||||
|
el2 = tool.Ifc.get_entity(obj2)
|
||||||
|
|
||||||
|
obj1_ports = [p for p in tool.System.get_ports(el1) if not tool.System.get_connected_port(p)]
|
||||||
|
obj2_ports = [p for p in tool.System.get_ports(el2) if not tool.System.get_connected_port(p)]
|
||||||
|
|
||||||
|
if not obj1_ports or not obj2_ports:
|
||||||
|
self.report({"ERROR"}, "Couldn't find free ports to connect.")
|
||||||
|
return
|
||||||
|
|
||||||
|
def get_element_matrix(element):
|
||||||
|
placement = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement)
|
||||||
|
return Matrix(placement)
|
||||||
|
|
||||||
|
for port1 in obj1_ports:
|
||||||
|
port1_location = get_element_matrix(port1).translation
|
||||||
|
for port2 in obj2_ports:
|
||||||
|
port2_location = get_element_matrix(port2).translation
|
||||||
|
if tool.Cad.are_vectors_equal(port1_location, port2_location):
|
||||||
|
core.connect_port(tool.Ifc, port1, port2)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
self.report({"ERROR"}, "Couldn't find any matching ports to connect.")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
|
||||||
class SetFlowDirection(bpy.types.Operator, Operator):
|
class SetFlowDirection(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.set_flow_direction"
|
bl_idname = "bim.set_flow_direction"
|
||||||
bl_label = "Set Flow Direction"
|
bl_label = "Set Flow Direction"
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ class BIM_PT_ports(Panel):
|
|||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
total_ports = PortData.data["total_ports"]
|
total_ports = PortData.data["total_ports"]
|
||||||
row.label(text=f"{total_ports} Ports Found", icon="PLUGIN")
|
row.label(text=f"{total_ports} Ports Found", icon="PLUGIN")
|
||||||
|
row.operator("bim.mep_connect_elements", text="", icon="PLUGIN")
|
||||||
row.operator("bim.show_ports", icon="HIDE_OFF", text="")
|
row.operator("bim.show_ports", icon="HIDE_OFF", text="")
|
||||||
row.operator("bim.hide_ports", icon="HIDE_ON", text="")
|
row.operator("bim.hide_ports", icon="HIDE_ON", text="")
|
||||||
row.operator("bim.add_port", icon="ADD", text="")
|
row.operator("bim.add_port", icon="ADD", text="")
|
||||||
|
|||||||
Reference in New Issue
Block a user