Notifications
Clear all

[Closed] maxscript newbie

howya!

i’m currently trying to get my head round maxscript- i havn’t done any sort of coding since feckin around with basic on my trusty amiga 500 all those years ago so i’m rusty as hell.

what i’d like to do is write a script that generates a spline with a variable amount of knots in it, that randomly trails from left to right, so what you are left with is a squiggly line like a snails trail… except i want it to generate hundreds of them that all go in the same direction, but still have a random quality. i’m sure once i’ve sorted the code i’ll be able to tweak it so it looks like what i have in my brain.

so get ready to laugh coz this is what i have so far:

x=0

y=0

for i=1 to 30 do

(

s=splineshape()

idx=addNewSpline s

r=random 10 30

for k in knot_positions do addKnot s idx #smooth #curve k

updateshape s

s.thickness=0.5

s.displayrendermesh=true

)

its gibberish to a good coder i’m sure. and no way does it work in any form or manner.

i’ve heard splineshape things are one of the harder things to do in max, so any help would be extremely appreciated and firmly stuck on the credits of the film i’m making.

www.delicious9.com

4 Replies

Your code does work… as you’ve written it…

I’ve added a bit to it…

(

knot_positions = #([0,0,0],[10,10,0],[20,10,0],[30,20,0])
BasePoint = [ 0,0,0 ]

for i=1 to 30 do
(
s=splineshape()
idx=addNewSpline s
r=random 10 30
for k in knot_positions do
(
PointVari = [ (Random -2 2),(Random -2 2),0 ]
addKnot s idx #smooth #curve ( BasePoint + k + PointVari)
)
updateshape s
s.thickness=0.5
s.displayrendermesh=true
)

You can select the text above and drag it to a tool bar in max and it will create a “Drag_and_Drop” macro and button so you can check it out… or paste into a new .ms

Change the base point to move the beginning of the line, add points to the array to make it longer…

Maybe a loop to build it out…

for i=1 to (random 10 20) do append basepoint ([((i10)+( random -5 5)),((i10)+( random -5 5)),0 ]

Good luck

Keith Morrison

wow thanks a million
buuuttt…

everytime i go to run the script i get ‘compile error- unexpected end of script’

and i cant see what i’m doing wrong!

ok i’m an idiot i saw i was missing a bracket at the end. anyway, nice one.

but i kind of want to stay away from arrays, so it could go on for infinity.
like this:

(

BasePoint = [ 0,0,0 ]

x=0

y=0

for i=1 to 10 do

(

x=x+(i*10)

y=random 0 50

s=splineshape()

idx=addNewSpline s

r=random 10 30

k=[x,y,0]

PointVari = [ (Random -2 2),(Random -2 2),0 ]

addKnot s idx #smooth #curve ( BasePoint + k + PointVari)

updateshape s

s.thickness=0.5

)

)

now, why doesn’t that work??

you stated :

“except i want it to generate hundreds of them that all go in the same direction, but still have a random quality”

Which is why you want an array as base shape information + [±2,±2,0] , so they are similar but different… try varying the ±2 in the random statement to get more variance.

to answer your qeustion, I’m guessing you now want to ADD the [x,y,0] to the basepoint to get it to string out in a completely random fasion…

Good luck

Keith Morrison