Keep the edge indices as they were, after deleting vertices?


I am working on a network with leaf vertices, at one point I remove the leaves. This leads to the automatic removal of their corresponding edges and the rearrangement of the edge indices. Is there a way to keep the indices for the rest of the edges as they were before the vertex removal?


can you give a visual example of what the result is now, before/after?





ha okay, now i understand.

there are no real edge indices. what is displayed is just the order (and corresponding “index”) in which the edges are looped over. nothing really changed in the data structure.

if you would like to be able to refer to the edges by an index or to the display the same indices in the drawing, use a map:

import compas
from compas.datastructures import Network
from compas.plotters import NetworkPlotter

network = Network.from_obj(compas.get('lines.obj'))

plotter = NetworkPlotter(network)

uv_index = {uv: index for index, uv in enumerate(network.edges())}

# do some deleting

plotter.draw_edges(text={uv: str(uv_index[uv]) for uv in network.edges()})

let me know if that is not what you meant…



Thanks for the response. I already had a mapping dict. For some reason, I got confused and thought that the indices for edges are like keys for vertices!