Question. How can I simplify adding knots to spline using for loop so they can animate?

--Hello,
--I was wondering if someone could give me some advice on how to simplify the last section of this script.
--the script creates a spline with all the knots positioned at the first array value.
--The challenge is setting up the controllers for the knots. This example works but I need to simplify the last part to handle possibilty of greater than 4 values in the array.
--Does anyone have suggestions? If You run this script as I have it just drag only the point helpers to change the spline.
--
--I attached this script to this post if you cant select all and copy paste into your --maxscript editor

resetMaxFile #noPrompt
myarray = #([0,0,20],[20,0,20],[40,0,20],[60,0,20]) --total number of items in array varies. I use 4 items for testing

ScanTail = splineShape name:"ScanTail_Spline" wirecolor:blue --create spline
addnewSpline ScanTail
-------------------------------------------------
m = 0
for m in 1 to myarray.count do
(
addknot ScanTail 1 #smooth #curve myarray[1] ---creates a bunch of knots on spline based on the total number of values in array and place all of them at the 1st value in the array
)
updateShape ScanTail
animateVertex ScanTail #all
-----------------------------------------------

u = (myarray.count * 3) --total number of values in the array * 3 gives you the total number of X,Y Z point controllers you need to make in this loop
for m = 2 to u by 3 do
(
ScanTail[#Object__Editable_Spline][#Master][m].controller = Point3_XYZ()
)
----------------------------------------------------------------------------------------------SECTION BELOW NEED TO SIMPLIFY
-----------Create Point Helpers for all knots on the spline
for s in 1 to myarray.count do
(
nm = "ScanTail_Helper_" + s as string
PointHelperObj name:nm pos:[0,0,0] size:258 centermarker:true axistripod:false cross:false drawnontop:true wirecolor:green
)

--------------------------------This section works but is limited to 4 helpers. I need to simplify it
(
for i = 1 to 3 by 1 do (ScanTail[#Object__Editable_Spline][#Master][2].controller[i].controller = $ScanTail_Helper_1.position.controller[i].controller)
--------------------------------------------------------------------------------------
for i = 1 to 3 by 1 do (ScanTail[#Object__Editable_Spline][#Master][5].controller[i].controller = $ScanTail_Helper_2.position.controller[i].controller)
--------------------------------------------------------------------------------------
for i = 1 to 3 by 1 do (ScanTail[#Object__Editable_Spline][#Master][8].controller[i].controller = $ScanTail_Helper_3.position.controller[i].controller)
------------------------------------------------------------------------------------
for i = 1 to 3 by 1 do (ScanTail[#Object__Editable_Spline][#Master][11].controller[i].controller = $ScanTail_Helper_4.position.controller[i].controller)
)

max zoomext sel all

--I attached this script to this post if you cant select all and copy paste into your --maxscript editor

AttachmentSize
movesplineknotstoadjustspline.ms2.79 KB

Comments

Comment viewing options

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

.

you can use <code> ... </code> tag to put your code in

delete shapes 
delete helpers
knots = 13
 
-- shape
shp = splineShape wirecolor:yellow vertexTicks:on
addnewspline shp
for i=1 to knots do addKnot shp 1 #smooth #curve [30*(i-1),0,0]
updateShape shp
animateVertex shp #all
 
-- helpers
pointHelpers = for i=1 to knots collect point pos:(getKnotPoint shp 1 i) centermarker:off cross:on wirecolor:((yellow*0.25 + white*0.75)) size:15 drawontop:true
 
master = shp[4][#Master]
for i=1 to knots do
(
	master[ i * 3 - 1 ].controller = Point3_XYZ()
	master[ i * 3 - 1 ].controller[1].controller = pointHelpers[i].position.controller[1].controller
	master[ i * 3 - 1 ].controller[2].controller = pointHelpers[i].position.controller[2].controller
	master[ i * 3 - 1 ].controller[3].controller = pointHelpers[i].position.controller[3].controller
)

Comment viewing options

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