how to make this script working on spline object with several splines.

Hi, I made a little script to add knot spline at a given distance.

- how it works :
select a segment
enter a value
positive value add at the distance a knot at the beginnig of the segment
negative value add it at the end.
if "corner" is checked, add a corner knot, if not, knot have tangents.

- how it don't work :
It don't work with several splines in spline object.

I can't manage to tell script in wich spline is the selected segment.
If somebody can help. Thanks

(
	(
	try destroyDialog rlslice catch()
	global rlslice = rollout rlslice "REFINEbyDIST" 
	(		
		button butconnect "GO" pos:[2,2]
		spinner DDD "d " width:90 range:[-10000,10000,1] type:#float pos:[55,5]
		checkbutton CORN "CORNER"  offset:[0,0] width:60 highlightColor:(color 95 138 193) checked:true
 
		on DDD changed DIST do
		(
		SEG=getSegSelection $ 1				
		LLLF = getSegLengths $ 1
		verts = numKnots $
		LLL = LLLF[SEG[1]+(verts-1)]
 
		if DIST>=0 then
			(
			XXX = refineSegment $ 1 SEG[1] (DIST/LLL)			
			) 
			else
			(
			XXX = refineSegment $ 1 SEG[1] (1-(abs(DIST)/LLL))
			)
		if CORN.checked==true then setKnotType $ 1 XXX #corner
		updateshape $
		)
 
		on butconnect pressed do
		(
		SEG=getSegSelection $ 1				
		LLLF = getSegLengths $ 1
		verts = numKnots $
		LLL = LLLF[SEG[1]+(verts-1)]
		DIST=DDD.value
		if DIST>=0 then
			(
			XXX = refineSegment $ 1 SEG[1] (DIST/LLL)			
			) 
			else
			(
			XXX = refineSegment $ 1 SEG[1] (1-(abs(DIST)/LLL))
			)
		if CORN.checked==true then setKnotType $ 1 XXX #corner
		updateshape $
		)
 
	)	
createDialog rlslice 160 60
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

on butconnect pressed do
(
	curO = selection[1]
	if selection.count == 1 and ( classOf curO == splineShape or classOf curO == line ) do
	(
		splCnt = numSplines curO
		if splCnt != 0 do
		(
			for ss = 1 to splCnt do
			(
				SEG= getSegSelection curO ss
				if SEG.count != 0 do
				(
					LLLF = getSegLengths curO ss
					verts = numKnots curO ss
					LLL = LLLF [SEG[1]+(verts-1)]
					DIST=DDD.value
					if DIST>=0 then
					(
						XXX = refineSegment curO ss SEG[1] (DIST/LLL)			
					) 
					else
					(
						XXX = refineSegment curO ss SEG[1] (1-(abs(DIST)/LLL))
					)
					if CORN.checked==true then setKnotType curO ss XXX #corner
					updateshape curO
				)
			)
		)
	)
)
titane357's picture

Hi, Miauu, as usual it works perfectly

As usual it works perfectly !!! Thanks a lot !!! :-)

If it can help somebody, here is the code of the script :

(
	try destroyDialog rollrefine catch()
	global rollrefine = rollout rollrefine "REFINEbyDIST" 
	(	
		checkbutton CORN "CORNER"  pos:[2,5] width:60 highlightColor:(color 95 138 193) checked:true
		spinner DDD "" offset:[-3,-23] width:90 range:[-10000,10000,1] type:#float 
		button butconnect "GO" width:60 offset:[14,2]
 
on butconnect pressed do
(
	curO = selection[1]
	if selection.count == 1 and ( classOf curO == splineShape or classOf curO == line ) do
	(
		splCnt = numSplines curO
		if splCnt != 0 do
		(
			for ss = 1 to splCnt do
			(
				SEG= getSegSelection curO ss
				if SEG.count != 0 do
				(
					LLLF = getSegLengths curO ss
					verts = numKnots curO ss
					LLL = LLLF [SEG[1]+(verts-1)]
					DIST=DDD.value
					if DIST>=0 then
					(
						XXX = refineSegment curO ss SEG[1] (DIST/LLL)			
					) 
					else
					(
						XXX = refineSegment curO ss SEG[1] (1-(abs(DIST)/LLL))
					)
					if CORN.checked==true then setKnotType curO ss XXX #corner
					updateshape curO
				)
			)
		)
	)
)
 
	)	
createDialog rollrefine 160 60
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.