[Closed] spline explode update
I have a script that should explode a spline so that every segment is a spline. That works fine. Then the script should look at the knots of each spline, and if either knot (since each spline should only have 2 knots at this point) is above a certain height, it tags that spline to be deleted. Once it checks them all, it deletes the tagged ones. Let’s say my shape is made up of 4 rectangles. before it explodes, I have 4 splines and after I have 16. The problem is when the script checks the knots, it acts like there’s still 4 splines. I feel like I need to update the shape or something, but that function is in there and it doesn’t seem to help. Here’s my script.
setCommandPanelTaskMode mode:#modify
max select none
select spl
subObjectLevel = 3
max select all
splineOps.explode spl
updateshape spl
subObjectLevel = 0
global knot_array = #()
global deleter = 0
for s = 1 to (numSplines $) do
(
tracker = 0
for k = 1 to (numKnots $ s) do
(
knt = getKnotPoint $ s k
in_vec = getInVec spl s k
out_vec = getOutVec spl s k
if knt.z > ($.pos.z+50000) do
(
if tracker == 0 do
(
deleter = (deleter + 1)
knot_array [deleter] = s
print (knt.z)
print (knot_array[deleter])
tracker = 1
)
)
setInVec spl s k in_vec
setOutVec spl s k out_vec
setKnotPoint spl s k knt
)
)
for d = 1 to deleter do
(
deletespline $ knot_array[deleter-d+1]
)
updateshape $
The first chunk explodes the spline, and the second chunk checks and deletes the splines. If anyone knows how I can get the second chunk to acknowledge what happened in the first chunk, I would appreciate any advice.
Here try this. Someone had some good code for part of this and I wrote the rest.
New_Name = "Spline_Parts_"
TheObj = for o in selection where superClassOf o == Shape collect o
for i = 1 to theObj.count do(
convertToSplineShape theObj[i]
with undo off (
The_splines = theObj[i].numsplines
for spl = 1 to The_splines do(
ns = splineShape ()
addnewspline ns
for k = 1 to (numKnots TheObj[i] spl) do(
knotpos = getKnotPoint TheObj[i] spl k
segtype=getSegmentType TheObj[i] spl k
knottype= getKnotType TheObj[i] spl k
if knottype == #bezier or knottype== #bezierCorner then (
addknot ns 1 knottype segtype knotpos (getInVec TheObj[i] spl k) (getOutVec TheObj[i] spl k)
)
else(
addknot ns 1 knottype segtype knotpos
)
)
if (isClosed theobj[i] spl) then close ns 1
updateshape ns
ns.wirecolor = color(random 70 255) (random 70 255) (random 70 255)
ns.name = uniquename New_Name
ns.pivot = ns.center
MY_Count = numSegments ns 1
for s = 1 to MY_Count do(
if s == MY_Count then (
P1 = getKnotPoint ns 1 MY_Count
P2 = getKnotPoint ns 1 1
New_Spline = SplineShape pos:P1
addNewSpline New_Spline
addKnot New_Spline 1 #corner #line P1
addKnot New_Spline 1 #corner #line P2
New_Spline.name = uniquename New_Name
New_Spline.wirecolor = color(random 70 255) (random 70 255) (random 70 255)
delete ns
)
else(
P1 = getKnotPoint ns 1 s
P2 = getKnotPoint ns 1 (s+1)
New_Spline = SplineShape pos:P1
addNewSpline New_Spline
addKnot New_Spline 1 #corner #line P1
addKnot New_Spline 1 #corner #line P2
New_Spline.name = uniquename New_Name
New_Spline.wirecolor = color(random 70 255) (random 70 255) (random 70 255)
)
)
)
progressEnd()
)
delete theObj[i]
)