multiple script objects problem

Hi,
I made a little script to "straighten" a spline to have its overall slope.
It works but I want to apply the script to selected splines ( loop ) and then it don't work anymore... Anybody can help ? :-)

BS = selection[1]
BSW = BS.wirecolor
SP = copy BS
select SP
macros.run "Modifier Stack" "Convert_to_Spline"
verts = numKnots SP
NP=SplineShape pos:[0,0,0]
addNewSpline NP
PO = getKnotPoint SP 1 1
addKnot NP 1  #corner #line [0,0,PO.z]
NEWD = 0
for i=1 to (verts-1) do
(
PA = getKnotPoint SP 1 i
PB = getKnotPoint SP 1 (i +1) 
PAF = [PA.x,PA.y,0]
PBF = [PB.x,PB.y,0]
DISTx=  (( distance PAF PBF ))
NEWD = DISTx + NEWD
--print ( DISTx as string)
addKnot NP 1  #corner #line [NEWD,0,PB.z]
)
updateShape NP
NP
NP.wirecolor = BSW
NP.name = BS.name + "_red"
delete SP

Comments

Comment viewing options

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

...

Your code will work for the first spline in a shape. If you have a shape with 2 or more splines only the first one will be processed.

Do you want to create a script which works like this one: http://www.scriptspot.com/3ds-max/scripts/stretch-spline

Here is your code, modified to process shapes with multiple splines.

(
	BS = selection[1]
	BSW = BS.wirecolor
	SP = copy BS
 
	convertToSplineShape SP
 
	NP = SplineShape pos:[0,0,0]
	for s = 1 to numSplines SP do
	(
		yPos = s * 10
		verts = numKnots SP s		
		addNewSpline NP
		PO = getKnotPoint SP s 1
		addKnot NP s #corner #line [0, yPos, PO.z]
		NEWD = 0
		for i = 1 to (verts-1) do
		(
			PA = getKnotPoint SP s i
			PB = getKnotPoint SP s (i +1) 
			PAF = [PA.x, PA.y, 0]
			PBF = [PB.x, PB.y, 0]
			DISTx=  (( distance PAF PBF ))
			NEWD = DISTx + NEWD
			--print ( DISTx as string)
			addKnot NP s  #corner #line [NEWD, yPos, PB.z]
		)
		updateShape NP
		NP
		NP.wirecolor = BSW
		NP.name = BS.name + "_red"
	)
 
	delete SP
)
titane357's picture

Hi Miauu ! Thanks for answer

Hi, thanks very much ! It works like a charm :-)

Is there a way to make another for separate spline objects with :

for sp in selection do ( ) ? So I can have separate wirecolor ?

Thanks a lot !

miauu's picture

...

This will get all splines of a shape and will create separate objects from each spline:

(
	BS = selection[1]
	BSW = BS.wirecolor
	SP = copy BS
 
	convertToSplineShape SP
 
 
	for s = 1 to numSplines SP do
	(
		NP = SplineShape pos:[0,0,0]
		yPos = s * 10
		verts = numKnots SP s		
		addNewSpline NP
		PO = getKnotPoint SP s 1
		addKnot NP 1 #corner #line [0, yPos, PO.z]
		NEWD = 0
		for i = 1 to (verts-1) do
		(
			PA = getKnotPoint SP s i
			PB = getKnotPoint SP s (i +1) 
			PAF = [PA.x, PA.y, 0]
			PBF = [PB.x, PB.y, 0]
			DISTx=  (( distance PAF PBF ))
			NEWD = DISTx + NEWD
			--print ( DISTx as string)
			addKnot NP 1  #corner #line [NEWD, yPos, PB.z]
		)
		updateShape NP
		NP
		NP.wirecolor = BSW
		NP.name = BS.name + "_red"
	)
 
	delete SP
)

Comment viewing options

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