PolyOps on Large Selection

Hey folks.

So I've got this script that is designed to divide two edges, connect the verts created, and further connect the edges created by the first connection.

I'm having trouble with my edge and vert indices, because they keep changing, which makes sense since I'm adding verts and edges with the ops I'm doing.

Could someone give me a hand figuring out how to do these operations to more than 2 edges?

<code>

(

 

wantedDistance = "2.25m";

alignment = "center";

 

undo on (

 

es=(polyop.getEdgeSelection $) as array;

 

spacing = units.decodeValue wantedDistance;

mD = 0;

 

nVs = #();

 

for i in es do (

v1 = $.GetEdgeVertex i 1;

v2 = $.GetEdgeVertex i 2;

p1 = $.GetVertex v1;

p2 = $.GetVertex v2;

dis = distance p1 p2;

mD += dis;

nV = polyOp.divideEdge $ i 0.5;

append nVs nV;

)

 

esT = polyOp.getEdgesUsingVert $ nVS;

 

mD /= es.count;

cnt = floor(mD / spacing);

initial = cnt * spacing / 2;

 

nSs = #();

 

for i = 1 to nVs.count - 1 do (

nS = polyop.createEdge $ nVs[i] nVs[i+1];

append nSs nS;

)

 

for i = 1 to nSs.count do (

polyop.chamferEdges $ nSs initial;

)

 

cEdges = polyOp.getEdgeSelection $;

cVerts = polyOp.getVertsUsingEdge $ cEdges;

nEdges = polyOp.getEdgesUsingVert $ cVerts;

 

tEdges = nEdges - cEdges;

tEdges = tEdges - esT;

 

tEdges

 

polyOp.setEdgeSelection $ tEdges;

 

CholdC = $.connectEdgeSegments;

CholdP = $.connectEdgePinch;

CholdS = $.connectEdgeSlide;

 

$.connectEdgeSegments = cnt - 1;

$.connectEdgePinch = 0;

$.connectEdgeSlide = 0;

$.buttonOp #ConnectEdges;

 

$.connectEdgeSegments = CholdC;

$.connectEdgePinch = CholdP;

$.connectEdgeSlide = CholdS;

 

)

redrawViews();

 

)</code>

Attached herein is a before and after of the script working.

Before: http://i.imgur.com/qreXO9T.jpg

After: http://i.imgur.com/bEm4nfm.jpg