[Closed] splineCode | Usefull-ish function
So I want to generate splineshapes for some script I have and I want to use an existing spline as a template.
This function generates code that generates a spline shape, it also generates a scale variable that you can then use to scale the spline at will.
(
fn splineCode node:selection[1] =
(
-- returns a string with code
if isValidNode node and (isKindOf node SplineShape or isKindOf node line) then
(
clearListener()
local res = stringStream ""
format "
ss = SplineShape()
" to:res
format "scl = 1.0
" to:res
for spl = 1 to numSplines node do
(
format "addNewSpline ss
" to:res
for knot = 1 to numKnots node spl do
(
in coordsys node
(
local segType = getSegmentType node spl knot
local inVec = getInVec node spl knot
local pVec = getKnotPoint node spl knot
local outVec = getOutVec node spl knot
local knotType = getKnotType node spl knot
)
format "addKnot ss % % % (% * scl) (% * scl) (% * scl) %
" spl knotType segType pVec inVec outVec knot to:res
)
if isClosed node spl then
format "close ss %
" spl to:res
)
format "updateShape ss
" to:res
res as string
) else (
false
)
)
-- Select a spline shape
print (splineCode())
ok
)
So on a custom shape that generates:
ss = SplineShape()
scl = 2.0
addNewSpline ss
addKnot ss 1 #bezier #curve ([-23.8239,-15.1542,0] * scl) ([-21.9166,-0.689846,0] * scl) ([-25.7312,-29.6185,0] * scl) 1
addKnot ss 1 #bezier #curve ([-1.87113,-39.2203,0] * scl) ([-8.22427,-36.4951,0] * scl) ([4.482,-41.9456,0] * scl) 2
addKnot ss 1 #bezier #curve ([18.6321,-42.5361,0] * scl) ([13.4698,-52.6562,0] * scl) ([23.7944,-32.4159,0] * scl) 3
addKnot ss 1 #bezier #line ([22.4952,-17.3432,0] * scl) ([25.7183,-25.207,0] * scl) ([19.2721,-9.47944,0] * scl) 4
addKnot ss 1 #bezier #curve ([13.1464,-2.8932,0] * scl) ([20.5654,-5.9245,0] * scl) ([5.72743,0.138096,0] * scl) 5
addKnot ss 1 #bezier #line ([-21.1431,9.70307,0] * scl) ([-9.70549,7.40523,0] * scl) ([-32.5807,12.0009,0] * scl) 6
addKnot ss 1 #bezier #curve ([-13.1005,29.8254,0] * scl) ([-27.979,44.4597,0] * scl) ([1.77809,15.191,0] * scl) 7
addKnot ss 1 #bezier #curve ([-5.31821,14.1593,0] * scl) ([-20.8772,6.45415,0] * scl) ([10.2408,21.8645,0] * scl) 8
addKnot ss 1 #bezier #curve ([-4.73726,45.3788,0] * scl) ([12.9076,40.0901,0] * scl) ([-22.3821,50.6675,0] * scl) 9
addKnot ss 1 #corner #line ([-37.9191,30.7246,0] * scl) ([-30.1506,40.696,0] * scl) ([-29.9178,15.0174,0] * scl) 10
close ss 1
updateShape ss
Usage: Select a splineshape or line and run the code. In the listener there’s new code generated. Copy/paste and run it to produce an exact duplicate of the other spline. Usefull for rigginng controls etc.
It’s not fully tested for all cases, but so far it works out.
Hope it’s of any use to someone,
-Johan
i can make life more easier for absolutely lazy person… just by putting the generated code not in the listener but directly in the clipboard
It shocks me to you hear you saying that, oh great maxscript teacher
But if I get enough likes or +1’s I will make the necessary adjustments
-Johan