Script for select only Mergeable edges

 From:  mkdm
7914.1 
Hi Michael,

I'm trying to write a little plugin that should show to the user, a graphical list containing the names, if there are, and the lengths, of just all the edges that are eligible for the Merge command.

I know that it's possible to select any object and run the Merge command on it, in order to globally merge all its mergeable splitted edges, but in this case,
i want to explicitly show to the user the list of that edges, ordered by the edge's length, so the user can directly use the list to navigate through that set of edges,
in order to visually identify the edges that he wants to merge.

Now, since i'm not adequately skilled in Moi's Api, the quality of my .js code is very poor, so i want to ask you if in the Api there's some method or properties that can help me to recognize if an edge is splitted or not.

Or maybe, could you tell me some sort of heuristic technique to recognize that particular kind of edges ?

That's the code i'm using to simply get all the edges, grouping them by the parent brep, and order the list based on the length of the edges.

********* .JS CODE START *************
code:
function edgesGroup(groupId, edgesList, shorterLenght) {
	this.groupId = groupId;
	this.edgesList = edgesList;
	this.shorterLenght = shorterLenght;
}

function edgeItem(parentBrepId, edge) {
	this.parentBrepId = parentBrepId;
	this.edge = edge;
}

function loadEdgesList() {
	edgesList = []; // is the flattened list that contains all the edges
	
	var breps = moi.geometryDatabase.getObjects().getBReps();
	var edgesGroups = [];

	for ( var i = 0; i < breps.length; ++i ) {
		var minLength = -1;

		var brep = breps.item(i);
		if ( !brep.hidden ) {
			var brepEdges = brep.getEdges();
			var brepId = brep.id;
			var edgesToProcess = [];
			
			for ( j = 0; j < brepEdges.length; ++j) {
				var edge = brepEdges.item(j);
				if (!edge.isClosed && !edge.hidden) {
					edgesToProcess.push(edge);
				}
			}
			
			edgesToProcess.sort(function (a, b) {return (a.getLength() - b.getLength());});
			if (edgesToProcess.length> 0) {
				minLength = edgesToProcess[0].getLength();
			}
			
			edgesGroups.push(new edgesGroup(brepId, edgesToProcess, minLength));
		}
	}
	
	edgesGroups.sort(function (a, b) {return (a.shorterLenght - b.shorterLenght);});

	for ( i = 0; i < edgesGroups.length; ++i) {
		var egdes = edgesGroups[i].edgesList;
		var groupId = edgesGroups[i].groupId;

		for ( j = 0; j < egdes.length; ++j) {
			var edgeIt = new edgeItem(groupId, egdes[j]);
			edgesList.push(edgeIt);
		}
	}						
	
}

********* .JS CODE END *************

Thank's for all, and nice day!

Marco.

EDITED: 8 Apr 2016 by MKDM