Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography


Featured Threads
  Maxforums Tournament 7 - Round 3
(11 replies)
  Maxforums Tournament 7 - Round 2
(37 replies)
  Maxforums Tournament 7 - Round 1
(84 replies)
  The Life of a Sea Turtle - Tutorial by mrgrotey
(85 replies)
  So what are you working on? =)
(1624 replies)
  Want free webspace?
(16 replies)
  spam alert!!!
(2663 replies)
  Maxforums member photo gallery index
(93 replies)
  Maxforums Member Tutorials
(82 replies)
  three cheers to maxforums...
(178 replies)
  The Grotorial Index Page
(57 replies)
  101 Things you didnt know in Max...
(159 replies)
  A Face tutorial from MDB101 :D
(95 replies)
  Free textures thread
(72 replies)
  Maxforums.org Members Gallery
(474 replies)
  SON OF POST YOURSELF
(582 replies)
  Dub's Maxscript Tutorial Index
(115 replies)
  The Best Art of Maxforums [56k warning]
(101 replies)


 
First page  Go to the previous page   [01]  [02]  Go to the next page  Last page
 
Maxscript fun: A couple of examples
show user profile  Nik Clark

Maxscript fun: A couple of examples

Maxscript provides two main things for a max user. The ability to create new features in max, and a way to perform repetitive, or difficult tasks. Even if some of this makes no sense to you, I hope some of it teaches you something new

Take the example of a light which flickers. This would be tedious to animate by hand, but a parametric light flickering tool can be made quickly in maxscript, which can be used over and over again.

Here's a couple of examples of using of maxscript to reduce repetitive or difficult tasks. The more you see of maxscript, the more you can imagine what you can do with it. This is less of a tutorial than the Dub's excellent work, but I hope the experience of this will help you write maxscripts in the future.

This picture illustrates the use of maxscript to alter the color of a group of objects. As you can see, the colors blend nicely. Coloring the objects this way manually would be possible, but would be time consuming.

Here is the complete script.

color_01 = color 0 0 80
color_02 = color 255 255 255

stepsize_r = (color_02.r - color_01.r)/$.count
stepsize_g = (color_02.g - color_01.g)/$.count
stepsize_b = (color_02.b - color_01.b)/$.count

for i = 1 to $.count do
   (
   newColor = (color ((i*stepsize_r)+ color_01.r-stepsize_r) ((i*stepsize_g)+color_01.g-stepsize_g) ((i*stepsize_b)+color_01.b-stepsize_b))
    $[i].wirecolor = newColor
   )

To use it, select a row of objects, and run the script. If there are no errors, your objects will be given a new wire color. There is supposed to be 2 lines of code between the brackets above, but the forum is making it wrap. I hope this doesn't confuse people.


---- Explanation-----

color_01 = color 0 0 80
color_02 = color 255 255 255

color_01 and color_02 are the start and end colors to use for the color fade

This is how you would define pure white in maxscript
color 255 255 255
Pretty obvious, right?

stepsize_r = (color_02.r - color_01.r)/$.count
stepsize_g = (color_02.g - color_01.g)/$.count
stepsize_b = (color_02.b - color_01.b)/$.count

This bit divides the difference between the start and end color divided by the number of objects. One for red, green and blue. This gives us the amount of change of color in each step for use later in the script. Don't worry if this makes no sense, it's the technique rather than the math I want you to experience.

A "for" loop repeats a number of times, and gives an incrementing value for each cycle in the loop

For i = 1 to 10 do (print i) would print all the numbers from one to ten in the listener. Using Print is a great way of having feedback from your calculations, like a debugger would be used by a programmer (if you are doing this tutorial, you are a programmer!)

In the code

for i = 1 to $.count do
  (
  blah blah blah
  )

Any code in the brackets (blah blah blah) will be executed a number of times. In this case, the number ($.count) equals the number of selected objects. "i" will be incremented every time the loop repeats, until it reaches the ($.count) last number.

$ in max means "the selected object"
$.count gives a number of how many selected objects you have.

When working on a selection of objects, FOR and $ are really useful.

The next lines of code do the actual work of coloring the objects. First, I calculate the new color of the object.

newColor = (color ((i*stepsize_r)+ color_01.r-stepsize_r) ((i*stepsize_g)+color_01.g-stepsize_g) ((i*stepsize_b)+color_01.b-stepsize_b))

This defines a new color I have called newColor. The code here calculates the new color based on i (the step in the loop) and the step sizes calculated above. Don't worry if this bit is gibberish to you right now, all experience is good.

$[i].wirecolor = newColor

This line applies the "newColor" to the objects.

$[1] would be the first object in the selection
$[2] would be the second object in the selection
$[3] would be the third object in the selection

When we use $[i], we can use i to define which object in the selection we are referring to. This is where the i in the "FOR loop" comes in.

You might want to use something other than the wire color. You can create a material and apply the color to the diffuse channel with script instead. To find out what code to use. Manually make a material in the material editor, and watch the code that appears in the listener window. Use this code to create your material

This method can be used to do almost anything to a group of selected objects. You could randomly scale objects, rotate them, adjust the material, apply modifiers. The possibilities are almost endless.

 

Here's a slightly more advanced example of something I could not do without maxscript.


The script can be found HERE.

This is one I made years ago, so please ignore the horrible, awful formatting, and lengthy calculations in the code. Select your grid of objects (has to be an even square), select the four colors by clicking on them and using the color picker, then click on the button.

I don't expect you to understand this script, but there may be something of use to you in it. Part of the problem with maxscript is not knowing what it can do, and the more exposure to various scripts, the better. Steal ideas (even code) from other scripts, use the listener and the help to work out what you need to do. Select a word in the Maxscript editor, and press F1. The help will go straight to the relevent article (mostly).

Happy scripting, and please ask any questions you may have.

-

Nik



Click here to send me an emailClick here to visit my websiteClick here to visit my photo gallery on Flickr

read 13561 times
12/1/2006 9:44:42 AM (last edit: 12/1/2006 10:02:41 AM)
show user profile  yeah_right
Very Cool!!!

I should get a sig

read 13552 times
12/1/2006 9:53:20 AM (last edit: 12/1/2006 9:53:20 AM)
show user profile  Jetkon
Nice, so thats how powerful MaxScripts is xD
Must take years to learn it.
Eyes after using 3ds max for hours

read 13525 times
12/1/2006 10:40:51 AM (last edit: 12/1/2006 10:40:51 AM)
show user profile  MrBurns
Great stuff!
I'm glad I used to program several years back, that knowledge should make it easier to learn MaxScript.
read 13511 times
12/1/2006 11:06:26 AM (last edit: 12/1/2006 11:06:26 AM)
show user profile  Nik Clark
>>Must take years to learn it.

If you know any BASIC programming at all, or any other programming languages, then it's not that hard to get to grips with. The biggest problem is figuring out what to tell it to achieve what you want.




Click here to send me an emailClick here to visit my websiteClick here to visit my photo gallery on Flickr

read 13481 times
12/1/2006 12:51:45 PM (last edit: 12/1/2006 12:51:45 PM)
show user profile  Dub.
Nice work Nik!

I've added it to the index.


read 13476 times
12/1/2006 12:57:40 PM (last edit: 12/1/2006 12:57:40 PM)
show user profile  Loud
Love it! Can't wait to get home to try it out. I've done Maxscript and expressions here and there, but I would love to delve into it more. Thanks for this.


read 13467 times
12/1/2006 1:05:40 PM (last edit: 12/1/2006 1:05:40 PM)
show user profile  paconavarro
Great and usefull tnks nik

--- http://www.exododw.com

read 13446 times
12/1/2006 2:39:43 PM (last edit: 12/1/2006 2:39:43 PM)
show user profile  brazz
great nik thanks. Gonna do it after doing dub´s one. Thanks a lot all you guys.





read 13441 times
12/1/2006 2:58:59 PM (last edit: 12/1/2006 2:58:59 PM)
show user profile  zzoka
Congratulations for this work.
You are truly an expert!

read 13407 times
12/1/2006 4:01:39 PM (last edit: 12/1/2006 4:01:39 PM)
show user profile  soontekk
omg nik, thats awesome
between u and me, i'm an elite programmer deep deep down inside, i just have no clue about the vocabulary

*adds new line to CV*
-Programmer !

Seriously tho, this is very very interesting stuff.
Making things easier is what it is all about.

I remember wanting to learn it years back (and actually made some silly scripts doing absolutely silly stuff but with very nice interfaces and menus (making teapots etc :P )
I also remember i could not find any resources to get me to the next step.
I experienced the same with expressions (never got any further than NT*pi*x where x is an integer, yay)

U guys are providing that next step, thx for that.

*makes some more space in brain*
*delete 1% pron in brain, are you absolutely very immensely sure [Y/N]*
*space available for knowledge*




Static page .. for now..

read 13380 times
12/1/2006 5:52:02 PM (last edit: 12/1/2006 5:52:02 PM)
show user profile  Bobbyboy
Nice work Nik :)
you mind if add this to the pdf version?


http://img.photobucket.com/albums/v322/bob9909/xmassig.jpg


read 13368 times
12/1/2006 6:58:33 PM (last edit: 12/1/2006 6:58:33 PM)
show user profile  Nik Clark
Please do, and take any future ones from me too. Thanks for doing the PDF, by the way :o)

Thanks for the positive comments, guys.

Kurt, lol! Why delete? That's what DVD+R's are for!




Click here to send me an emailClick here to visit my websiteClick here to visit my photo gallery on Flickr

read 13366 times
12/1/2006 7:02:32 PM (last edit: 12/1/2006 7:20:10 PM)
show user profile  Bobbyboy
Hey Nik, i've added your examples as well as made some other changes, if you see anything wrong please let me know. I'll continue to add to this as you create more :)

oh, and I couldn't think of a different way to present your really long teapot script, so i put it at the end in an appendix

Click Me

Cheers


http://img.photobucket.com/albums/v322/bob9909/xmassig.jpg


read 13341 times
12/1/2006 8:36:11 PM (last edit: 12/1/2006 8:36:11 PM)
show user profile  soontekk
Nik, doh, deleted crucial knowledge like that ages ago to store more pron :o

Very nice Bob, stored the new version, really clear with the blue code, thx for that !

regards
stkk
Static page .. for now..

read 13331 times
12/1/2006 10:15:15 PM (last edit: 12/1/2006 10:15:15 PM)
 
First page  Go to the previous page   [01]  [02]  Go to the next page  Last page
 
#Maxforums IRC
Open chat window


Support Maxforums.org