Script for select only Mergeable edges

Next
 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

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7914.2 In reply to 7914.1 
Hi Marco, I'm not sure that there is a good way for a script to do that currently.

The way the merge command works internally is that it actually processes things at a vertex level, a vertex is part of the topological structure of a brep but currently the brep vertices (the topological brep vertex structure, not the control points of a spline or surface which is a different type of vertex) are not exposed to be accessible by script.

The criteria for determining whether 2 edges are mergeable is if they share a removable vertex, and a removable vertex is defined by this process:

- Must be a vertex with exactly 2 edges coming off of it.

- If either of the 2 edges is closed the vertex is not removable.

- Both edges must be either seam edges or non-seam edges, not a mix.

- The end tangents of the edge curves must be colinear (G1 continuity).

- The vertex must not be at a singularity such as the pole of a sphere.


Currently several of these steps that you would need to know are not exposed in the script interface for scripts to access so I don't think there is any way to make an accurate "mergeable edge detector" in script right now, more stuff would need to be added to the script interface to be able to do that.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  mkdm
7914.3 In reply to 7914.2 
Hi Michael,

I can't deny that i'm sorry to hear that is not practically possible to do what i wanted,
but....anyway, i'll continue to write some other kind of plugins.
I've two or three parked in the garage.... :)

Thanks anyway for your prompt reply and for telling me what a removable vertex is.

Have a good day,

Marco.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All