MEP

from topologicpy.Vertex import Vertex
from topologicpy.Edge import Edge
from topologicpy.Wire import Wire
from topologicpy.Cluster import Cluster
from topologicpy.Topology import Topology
from topologicpy.Dictionary import Dictionary
from topologicpy.Graph import Graph
from topologicpy.Plotly import Plotly
edges_file = open("edges.csv")
lines = edges_file.readlines()
edges = []
for line in lines:
    tokens = line.split(",")
    edge_id, sx, sy, sz, ex, ey, ez = tokens
    sv = Vertex.ByCoordinates(float(sx), float(sy), float(sz))
    ev = Vertex.ByCoordinates(float(ex), float(ey), float(ez))
    e = Edge.ByVertices([sv,ev])
    d = Dictionary.ByKeyValue("id", edge_id)
    e = Topology.SetDictionary(e, d)
    edges.append(e)

nodes_file = open("nodes.csv")
lines = nodes_file.readlines()
vertices = []
for line in lines:
    tokens = line.split(",")
    v_id = tokens[0]
    x = float(tokens[1])
    y = float(tokens[2])
    z = float(tokens[3])
    v = Vertex.ByCoordinates(x,y,z)
    adj_edges = tokens[4:]
    adj_edges = [e.strip("\n") for e in adj_edges]
    d = Dictionary.ByKeysValues(["id","adj_edges"], [v_id, adj_edges])
    v = Topology.SetDictionary(v, d)
    vertices.append(v)

cluster = Cluster.ByTopologies(vertices+edges)
Topology.Show(cluster)
new_edges = []
for i, v in enumerate(vertices):
    v_d = Topology.Dictionary(v)
    edge_ids = Dictionary.ValueAtKey(v_d, "adj_edges")
    for edge_id in edge_ids:
        for edge in edges:
            e_d = Topology.Dictionary(edge)
            e_id = Dictionary.ValueAtKey(e_d, "id")
            if e_id == edge_id:
                nearest_v = Vertex.NearestVertex(v, edge, useKDTree=False)
                new_edges.append(Edge.ByVertices([nearest_v, v]))
cluster = Cluster.ByTopologies(edges+new_edges)
wire = Topology.SelfMerge(cluster)
w_vertices = Topology.Vertices(wire)
w_edges = Topology.Edges(wire)
g = Graph.ByVerticesEdges(w_vertices, w_edges)

v1 = Graph.NearestVertex(g, Vertex.ByCoordinates(-1,-0.5,0.5))
v2 = Graph.NearestVertex(g, Vertex.ByCoordinates(1,0.5,-0.5))
shortest_path = Graph.ShortestPath(g, v1, v2, edgeKey="length")
data01 = Plotly.DataByTopology(shortest_path, edgeWidth=6, edgeColor="red", vertexSize=3)
data02 = Plotly.DataByTopology(Graph.Topology(g))
figure = Plotly.FigureByData(data01+data02)
Plotly.Show(figure)