Grow Selection with Splines


#1

I know that you can grow selection with poly objects, but is it possible to do this with spline objects? I would like to grow the selection from the selected vertex, can’t find anything in the documentation :frowning:


#2

Somethig like this, but only for open splines:

(
	if selection.count == 1 do
	(
		curO = selection[1]
		if classOf curO == line or classOf curO == splineShape do
		(
			if subobjectlevel == 1 do
			(
				numSpl = numSplines curO
				if numSpl != 0 do
				(
					for i = 1 to numSpl do
					(
						selKnotsArr = getKnotSelection curO i
						lastKnotIdx = numKnots curO i
						if isClosed curO i then
						(
							
						)
						else
						(
							if selKnotsArr.count != 0 do
							(
								prevKnot = if selKnotsArr[1] != 1 then selKnotsArr[1] - 1 else 1
								nextKnot = if selKnotsArr[selKnotsArr.count] != lastKnotIdx then selKnotsArr[selKnotsArr.count] + 1 else lastKnotIdx
								setKnotSelection curO i #(prevKnot, nextKnot) keep:true
							)
						)
					)
				)
			)
		)
	)
)

#3

What don’t you know? Thank you :wink:


#4

I’ll add some.

 (
    	Lobj = selection[1]
    	if classOf Lobj == line or classOf Lobj == splineShape do
    	(
    		if subobjectlevel == 1 do
    		(
    			for i = 1 to numSplines Lobj do
    			(
    				NewVertArr = #()
    				selKnotsArr = getKnotSelection Lobj i
    				if isClosed Lobj i then
    				(
    					for a in selKnotsArr do
    					(
    						if a == 1 then
    						(
    							appendIfUnique NewVertArr a
    							appendIfUnique NewVertArr (a+1)
    							appendIfUnique NewVertArr (numKnots Lobj i)
    						)else if a == numKnots Lobj i then
    						(
    							appendIfUnique NewVertArr a
    							appendIfUnique NewVertArr (a-1)
    							appendIfUnique NewVertArr (1)
    						)else
    						(
    							appendIfUnique NewVertArr a
    							appendIfUnique NewVertArr (a+1)
    							appendIfUnique NewVertArr (a-1)
    						)
    					)
    				)
    				else
    				(
    					for a in selKnotsArr do
    					(
    						appendIfUnique NewVertArr a
    						if a+1 <= numKnots Lobj i then (appendIfUnique NewVertArr (a+1))
    						if a-1 != 0 then (appendIfUnique NewVertArr (a-1))
    					)
    				)
    				setKnotSelection Lobj i NewVertArr keep:true
    			)
    		)
    	)
    )

#5

you don’t actually need these uniqueness checks
what about shrink function?

fn SplineGrowVertSelection shp =
(
	local splineCount = numSplines shp

	for i=1 to splineCount where (knotSelection = getKnotSelection shp i).count > 0 do
	(
		local knotCount    = numKnots shp i
		local closedSpline = isClosed shp i
		
		local modifiedSelection = #{}
		
		if knotCount != knotSelection.count do
		(
			if closedSpline then
			(
				for k in knotSelection do
				(			
					if k > 1 then modifiedSelection[k-1] = true else modifiedSelection[knotCount] = true 
					if k + 1 <= knotCount then modifiedSelection[k+1] = true else modifiedSelection[1] = true		
				)
			
			)
			else
			(
				for k in knotSelection do
				(
					if k > 1 do modifiedSelection[k-1] = true
					if k + 1 <= knotCount do modifiedSelection[k+1] = true		
				)
			
			)

			setKnotSelection shp i (join knotSelection (modifiedSelection as array))

		)
	)
)