Notifications
Clear all

[Closed] My curve rebuild script

According to my spline growing thread I wrote a spline rebuilding script for learning purposes.
As far it doesn’t produce errors.
If somebody could revise it and advise how to make it interactive I’d be grateful.


macroScript TW_uniform_rebuild category:"kojak How To"
(
	if selection.count !=0 then
	(
		rollout rebuild_control "twardo_rebuild_control"
		(
			button rebuild "Rebuild curve"
			spinner knotcount "number of knots" range:[2,500,10] type:#integer
			radiobuttons curvetype labels:#("Linear", "Smooth") default:1
			
			On rebuild pressed do
			(
				myShape = selection[1]
				myShapeLength = curveLength myShape
				divs = knotcount.value as float
				newlength = myShapeLength/divs 
				

				myNewShape = SplineShape()
				addNewSpline myNewShape
				
					for i = 0 to divs do
					(
						case curvetype.state of
						(
							1: cornertype = #corner
							2: cornertype = #smooth
						)
						lengthParam = ((newLength * i) / myShapeLength)
						myNewParam = lengthToPathParam myShape 1 lengthParam
						if myNewParam > 1 do myNewParam = 1
						myNewKnotPos = pathinterp myShape 1 myNewParam
						
						addknot myNewShape 1 cornertype #curve myNewKnotPos
						if i > 1 then (updateShape myNewShape)
					)
				myNewShape.vertexTicks = on
				myNewShape.wirecolor = red
				select myNewShape
			)
		)
		createDialog rebuild_control 200 80
	)
	else (messageBox "Select a single-spline Shape")
)


Thanks for any help