New MEP utility to select and print debug information about connected system elements

This commit is contained in:
Dion Moult
2021-10-30 18:00:25 +11:00
parent e279fee518
commit 683e316088
3 changed files with 51 additions and 0 deletions
@@ -20,6 +20,7 @@ import bpy
from . import ui, prop, operator
classes = (
operator.GetConnectedSystemElements,
operator.ResizeToStorey,
operator.SetOverrideColour,
operator.SetViewportShadowFromSun,
@@ -139,3 +139,51 @@ class SplitAlongEdge(bpy.types.Operator, Operator):
def _execute(self, context):
core.split_along_edge(tool.Misc, cutter=context.active_object, objs=context.selected_objects)
class GetConnectedSystemElements(bpy.types.Operator, Operator):
bl_idname = "bim.get_connected_system_elements"
bl_label = "Get Connected System Elements"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return context.selected_objects and tool.Ifc.get()
def _execute(self, context):
# Just dumped here for now before the system module gets properly planned
def pprint_element(e):
return '{} ({})'.format(e.Name, e.GlobalId)
start = tool.Ifc.get_entity(bpy.context.active_object)
connected_elements = []
# Note: this code is for IFC2X3. IFC4 has a different approach.
print('Investigating element:', pprint_element(start))
for rel in start.HasPorts:
for rel2 in rel.RelatingPort.ConnectedTo:
print('{} is connected as via {} ({}) TO {} ({}), contained in {}'.format(
pprint_element(start),
rel.RelatingPort.FlowDirection,
rel.RelatingPort.GlobalId,
rel2.RelatedPort.FlowDirection,
rel2.RelatedPort.GlobalId,
[pprint_element(r.RelatedElement) for r in rel2.RelatedPort.ContainedIn]
))
connected_elements.extend([r.RelatedElement for r in rel2.RelatedPort.ContainedIn])
for rel2 in rel.RelatingPort.ConnectedFrom:
print('{} is connected as via {} ({}) FROM {} ({}), contained in {}'.format(
pprint_element(start),
rel.RelatingPort.FlowDirection,
rel.RelatingPort.GlobalId,
rel2.RelatingPort.FlowDirection,
rel2.RelatingPort.GlobalId,
[pprint_element(r.RelatedElement) for r in rel2.RelatingPort.ContainedIn]
))
connected_elements.extend([r.RelatedElement for r in rel2.RelatingPort.ContainedIn])
for element in connected_elements:
obj = tool.Ifc.get_object(element)
if obj:
obj.select_set(True)
@@ -43,3 +43,5 @@ class BIM_PT_misc_utilities(bpy.types.Panel):
row.operator("bim.resize_to_storey").total_storeys = props.total_storeys
row = layout.row()
row.operator("bim.split_along_edge")
row = layout.row()
row.operator("bim.get_connected_system_elements")