ScriptSpot

Forum topic · Scripts Wanted

open/break ~400 splines

By Holzi · 2014-04-05

Description

Hi there,

this should be a really simple script. But I can't fathom out how to do this:
I need to open up a couple of hundred splines. They are all closed but I need them now to be open. I use them as a spline for forest pack. Exploding them will not bring the right result. They need to stay intact, but need to be open.

I was thinking of selecting every first vertex of every spline and braking that.
However I don't know how to select the vertex by number nor what the break function is. MaxScript recorder will only show me the subObjectlevel = 1 but not what happens after that.

Any help is much appreciated

Comments (6)

.

miauu · 2014-04-06

For some reason ths code below will open only the last spline in the selection.
TRy to fix it. :)


(
	splinesArr = for s in selection where classOf s == SplineShape or classOf s == Line collect s
	for s in 	splinesArr do
	(
		select s
		max modify mode
		splineNum = numSplines s
		if splineNum > 0 do
		(
			for n = 1 to splineNum do
			(
				subobjectlevel = 1
				setKnotSelection s n #(1) keep:true
			)
			splineOps.startBreak s
			updateShape s
		)
	)
)

.

jahman · 2021-07-31

processPostedMessages forces max to process GUI messages, why would you need it here?
just move updateShape out of the loop and that's it

obaida · 2021-07-31

its not working with updateShape even its out of the loop !!
it works with 1 shape only and not applied to other selected shapes

.

jahman · 2021-07-31

oh, I see now that it uses modify mode for some unknown reason. In this case you're right that processPostedMessages is needed before switching to next shape.

I'd rather add another extra knot if the spline is closed and just make it open afterwards. This way it should work without switching to modify mode (which is always slower)

smth like this should work


delete shapes
gc()

s1 = Ngon nsides:7 circular:true
convertToSplineShape s1

s2 = copy s1 pos:(s1.pos + [s1.max.x - s1.min.x, 0, 0])

invec  = getInVec  s2 1 1
outvec = getOutVec s2 1 1
kt     = getKnotType s2 1 1
pt     = getKnotPoint s2 1 1
index  = case kt of
(
	#bezier       : addKnot s2 1 kt #line pt invec outvec
	#bezierCorner : addKnot s2 1 kt #line pt invec outvec
	default       : addKnot s2 1 kt #line pt
	
)
setInVec  s2 1 index invec
setOutVec s2 1 index outvec

open s2 1
updateShape s2