How do I build Unconnected Edges Selections from EPoly Edge Selection?

MAXScript FAQ > Working With Editable Polys > How do I build Unconnected Edges Selections from EPoly Edge Selection?

A user asked:

I want to filter the edge selection and create arrays containing connected edges, something like "edge selection elements". Edges from two arrays will never be connected, in other words will not share vertices.

Answer:

The following pseudo-code describes a possible approach:

The function is ready when there are no edges left in the main array.

This will give you as many sub-arrays are there are unconnected edge selections.

The following function implements the pseudo-code in MAXScript code:

SCRIPT

fn getEPolyUnconnectedEdgesSelections thePoly =
(
--get the edge selection
mainSelection = (polyOp.getEdgeSelection thePoly) as array
--init. an array to collect sub-arrays with selections "elements"
unconnectedSelections = #()
--repeat until the main selection array is empty
while mainSelection.count > 0 do
(
--append a new empty sub-array:
append unconnectedSelections #()
--remember the current sub-array's index:
currentSelCount = unconnectedSelections.count
--append the first edge from the main selectionarrayto the sub-array:
append unconnectedSelections[currentSelCount] mainSelection[1]
--and remove the first edge from the main selectionarray:
deleteItem mainSelection 1
--initializea counter:
cnt = 0
--while the counter is less than the edges in the sub-array
while cnt < unconnectedSelections[currentSelCount].count do
(
 cnt += 1--increase the counter by 1  --get the vertices of the current edge in the current sub-array:
 currentEdgeVerts = (polyOp.GetVertsUsingEdge thePoly  unconnectedSelections[currentSelCount][cnt]) as array
 neigborEdges = #()--init. an array to collect neighbor  --for every vertex in the current edge,
 for v in currentEdgeVerts do
 --add theedges used by the vertex to the neighbors array
  join neigborEdges ((polyOp.GetEdgesUsingVert thePoly v) as array)
 --for each neighbor edge,
 for edge in neigborEdges do
 (
  --see if the edge is in the main selection array
  checkInSelection = findItem mainSelection edge
  --if it is,
  if checkInSelection > 0 do
  (
   --delete the edge from the main array
   deleteItem mainSelection checkInSelection
   --and add it to the current sub-array
   append unconnectedSelections[currentSelCount] edge
  )--end if
 )--end for edge loop
)--end while cnt
)--end while mainSelection.count --finally, return the array containing the sub-arrays of connected edges:
unconnectedSelections
)--end fn
 
getEPolyUnconnectedEdgesSelections $Box01--call the function 

See Also