Notifications
Clear all

[Closed] automate spline length

with Maxscript how can I change the length of a spline until it is a specific amount?

I want to move Spline1/Vert 1 (there will only be Spline1)
move in -Z
until
curveLength $Shape01 = 3000 (generic units)

7 Replies

this is my (probably horrific) attempt

$ = theShape
 curLength = curveLength theShape
 remainder = (3000 - curLength)
  v1 = getKnotPoint $ 1 1
  v2 = getKnotPoint $ 1 2
  vec = normalize (v2-v1)
  setKnotPoint $ 1 1 (v1 + remainder * -vec)

I havent yet understood how to apply this to a selection of shapes and have it loop thru 1 by 1…

fn dLBP pointA pointB =
(
	ss = SplineShape pos:pointA
	addNewSpline ss
	addKnot ss 1 #corner #line PointA
	addKnot ss 1 #corner #line PointB
	ss.wirecolor = color 255 246 0
	updateShape ss
	ss
)
nSpl = dLBP  [0.0,0.0,0.0] [150.0,0.0,0.0]

This is a function I was using to do some spine work a little while ago.
Probably from the help file.
To use just use the function call “dLBP [0.0,0.0,0.0] [150.0,0.0,0.0]”
and change the pos in the z to use

edit – oh ok didn’t see your second post

Thanks Lucpet

nSpl = dLBP [0.0,0.0,0.0] [150.0,0.0,0.0]

what does nSpl and dLBP mean?
what does your script do? – I tried it and it made another spline

1 Reply
(@lucpet)
Joined: 11 months ago

Posts: 0

They’re just acronyms posing as variables lol
the dlbp is the function call and I assigned it to the variable nSpl (short for new spline)
so you could do without assigning it and just use dLBP [0.0,0.0,0.0] [0.0,0.0,-17.0]
where dLBP is the function call and you are feeding it pointA = [0.0,0.0,0.0] and
pointB = [0.0,0.0,-17.0]

You can rename these variables to anything that make sense to you.

I was just testing this piece of code:-

fn dLBP pointA pointB =
(
	ss = SplineShape pos:pointA
	addNewSpline ss
	addKnot ss 1 #corner #line PointA
	addKnot ss 1 #corner #line PointB
	ss.wirecolor = color 255 246 0
	updateShape ss
	ss
)
nSpl = dLBP  [0.0,0.0,0.0] [150.0,0.0,0.0]

ikCtrl = spline_IK_Control name: "SplIKMod" helper_size:5 linkTypes:0
ikCtrl.cross = on 
ikCtrl.Box = off
addModifier nSpl ikCtrl
ikCtrl.createHelper (ikCtrl.getKnotCount())

	-- rename the helpers
	for i = 1 to ikCtrl.getKnotCount() do
	(
		ikCtrl.helper_list[i].name = (uniquename "point_") 
		ikCtrl.cross = on 
		ikCtrl.Box = off
	)
	
	tText = text size:10 kerning:0 leading:0 isSelected:on
	pSel = Poly_Select name:"polSel"
	addmodifier tText pSel
	
	pDis =  (distance $point_001 $point_002)
	tText.text = pDis as string
	tText.pos = [(pDis/2), 5.0 , 0.0] 
	tText.wirecolor = color 255 246 0
	tText.rotation = angleaxis 90 [1,0,0] 

I posted my reply before seeing your second post

Sorry for taking so long but life keeps getting in the way

anyhow using the previous code Function

fn dLBP pointA pointB =
(
	ss = SplineShape pos:pointA
	addNewSpline ss
	addKnot ss 1 #corner #line PointA
	addKnot ss 1 #corner #line PointB
	ss.wirecolor = color 255 246 0
	updateShape ss
	ss
)
dLBP  [0.0,0.0,0.0] [10.0,0.0,0.0]


setKnotPoint $Shape001 1 1 [0.0, 0.0, -3000.0]
updateShape $Shape001

from the helpfile http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012//index.html?query=addKnot

setKnotPoint $Shape001 1 1 [0.0, 0.0, -3000.0] –the code, the spine name, the spline index, the knot index, then the position in 3 point
updateShape $Shape001 –then you have to use the update fn thingymabob

setting the knot two is just as simple

I hope this helps

Here is a (badly written) test script on how you can move the knots to locations in “Z”

rollout testme "Testme"
(
	button goMe "Go!" width:150
	spinner k1 "Knot 1" range:[-100000.0,100000.0,0.0] width:140 align:#center
	spinner k2 "Knot2" range:[-100000.0,100000.0,-100.0] width:140 align:#center
	
	fn dLBP pointA pointB =
(
	ss = SplineShape pos:pointA
	addNewSpline ss
	addKnot ss 1 #corner #line PointA
	addKnot ss 1 #corner #line PointB
	ss.wirecolor = color 255 246 0
	updateShape ss
	ss
)

	on goMe pressed do
	(
		dLBP [0.0,0.0,0.0] [0.0,0.0,-100.0]
	)
	
		on k1 changed val do
	(
		setKnotPoint $Shape001 1 1 [0.0, 0.0, val]
		updateShape $Shape001
	)
	
	on k2 changed val do
	(
		setKnotPoint $Shape001 1 2 [0.0, 0.0, val]
		updateShape $Shape001
	)
)
createdialog testme style:#(#style_toolwindow, #style_sysmenu)

Thanks very much lucpet