(
fn CreateShp A B = (
spl = splineshape wirecolor:black
addnewspline spl
addKnot spl 1 #corner #line A
addKnot spl 1 #corner #line B
updateShape spl
spl
)
undo "Unfold Shape" on (
local Allshps = #()
for SP in selection where isKindOf SP shape and converttosplineshape SP != undefined do (
max create mode
for i = 1 to (numSplines SP) do (
local CW
local shp = splineshape wirecolor:black
local numS = numSegments SP i
local segL = getSegLengths SP i
local p1 = getKnotPoint SP i 1 , p2 = getKnotPoint SP i 2
---- check if the shape is CW or CCW (Work if the Shape is Flat on Z Axis only)
if p1.x >= p2.x then (if p1.y >= p2.y then CW = 1 else CW = -1)
else (if p1.y <= p2.y then CW = 1 else CW = -1)
----
for s = 1 to numS do (
local spl, A = [0,0,0], B = [segL[numS+s]*CW,0,0]
spl = CreateShp A B
spl.Pivot = A
local V = 0
if s != 1 do (
for k = numS+1 to numS+s-1 do V += segL[k]*CW
spl.pos = [V,0,0]
)
addAndWeld shp spl -1
)
weldSpline shp 0.1
for i = 1 to (numSplines shp) do (
setKnotSelection shp i #()
for v = 1 to numKnots shp i do setKnotType shp i v #corner
)
updateShape shp ; CenterPivot shp
shp.pos = SP.pos
shp.name = SP.name+" Spl"+(i as string)+"_Flatten"
append Allshps shp
)
)
select Allshps
)
clearListener()
)