Go Back   EnjoyCG > Tutorials > EnjoyCG tutorials
register now

Welcome to EnjoyCG

EnjoyCG is a community and resource for 3d artists, students and designers. Browse our tutorials, read the latest news or ask a question on the forums.

New around here? register
  #1 (permalink)  
Old 26th April 2007
Ceryni's Avatar
Tutorial contributor
 
Join Date: Jan 2007
Location: Uk
Posts: 67
Thanks: 0
Thanked 4 Times in 4 Posts
Send a message via MSN to Ceryni Send a message via Skype™ to Ceryni
MAXScript

For the few that are interested in the scripting side of things here is a brief tutorial explaning the basics behind using MAXScript and MAXScript Listener.

The listener is an "interactive interpreter" for MAXScript language, When you enter the commands in this window, they are executed immediatly.
Its handy for performing interactive work and developing small code fragments, as instant execution can only really be used for small pieces of modelling ( kinda gets complicated if you wanna do a whole project in it )

To Access the Listener:
Utilities > Utlities rollout select MAXScript > Open Listener



Last edited by Ceryni; 26th April 2007 at 11:23 PM.
Reply With Quote
The Following User Says Thank You to Ceryni For This Useful Post:
CHALLENGER (8th October 2007)
  #2 (permalink)  
Old 26th April 2007
Ceryni's Avatar
Tutorial contributor
 
Join Date: Jan 2007
Location: Uk
Posts: 67
Thanks: 0
Thanked 4 Times in 4 Posts
Send a message via MSN to Ceryni Send a message via Skype™ to Ceryni
Basic Modelling

Using the Listener will produce immediate results so here is a simple script for creating a box.

Creating First Model

In the Listener, Type:

b = box()

press enter.



Thats it.. you will get a box with set default parameters Length, width and height = 25; all segments = 1; located at 0,0,0

rather than having the parameters set at default you may change them using a simple piece of code like this

b = box height:50 width:10
pos: (10,10,20) name:"new box"


simply explained "b" is the name you want to give to the object ( the variable ) and "box" is the 3DS command for creating a box, the "()" is left blank for default parameters, and tells the listener to apply the script.
Height and width are self explantory.
pos = the position of the box in space and uses the standard axis "x,y,z"
name:"newbox" is the name given to the box in 3DS itself
you may also use:

--sets the position aswell
b.pos = (10,10,20)


If the command is correctly written you will get a reply from the listener that should read something similiar to this

"$Box:Box01 @ [0.000000,0.000000,0.000000]"

naturally you dont have to create a box: s = sphere() would work just as well.

Adding Comments

The standard practice when writing a script is to add "comment lines" this way it makes the script more understandable to yourself and others.

The syntax for a comment is a double hyphen "--" at the beginning of the comment.

--Create a simple box
b = box()
--the above script will not be affected by these comments

Rotation and Scaling.

These are particularily hard to do as it involves maths.
There are two types of rotation Euler and Quaternion. sadly i only really know how to use Euler so will teach you that.

Euler angles allow you to specify the rotation in degress about teh x,y,z axes, it rotates x axes first, then y , then finally z

Syntax for Euler angles is relatively easy to use.

rotate b (eulerangles 0 45 0)
--rotates the box 45 degrees on the y axes
ang = eulerangles 90 45 -45
--tells the listener to ready the rotation 90 on the x, 45 more on the right, and -45 on the z.
rotate b (ang)
--rotates the box along the axis and degress specified above.


Scaling is much like moving an object:

b.scale.z=3
b.scale.y=3
b.scale.z=3

This scales the objects on the axes. it can also be written

b.scale=(3.0, 3.0, 3.0)

Adding Modifiers.

To add a modifier, use the command "addmodifier",
syntax is: addmodifier objectname (modifiername parameters)

heres an example of how to set the modifier "bend" on a Cylinder.

--Create a cylinder of 50 in height and 20 segments
c = cylinder height:50 height segs:20
--add the modifier "bend" to shape "C" at an angle of 90 degrees
addmodifier c (bend angle:90)



Here is another 1 showing "twist" on a box

--create the angle of the twist and set "t" to the twist variable
t = twist angle:360
--create the box that the modifier will be applied to
b = box height:60 heightsegs:25
--Tell the Listener to apply the modifier.
addmodifier b (t)



Still to come: a short Animation written using MAXScript
Reply With Quote
The Following User Says Thank You to Ceryni For This Useful Post:
CHALLENGER (8th October 2007)
  #3 (permalink)  
Old 26th April 2007
Jelmer's Avatar
Administrator
 
Join Date: Oct 2006
Location: The Netherlands
Posts: 2,635
Thanks: 9
Thanked 180 Times in 84 Posts
Send a message via MSN to Jelmer
That's great, i don't know much about maxscript but with this simple and well explained tutorial I'm getting some more insight into it!
Reply With Quote
  #4 (permalink)  
Old 27th April 2007
geldslaw's Avatar
EnjoyCG Staff
 
Join Date: Nov 2006
Location: London
Posts: 2,294
Thanks: 1
Thanked 45 Times in 44 Posts
Send a message via MSN to geldslaw Send a message via Yahoo to geldslaw Send a message via Skype™ to geldslaw
wow, I've read so many interviews, recently was the one about the Life a rigger or max script writer, I can't remember. But obvioulsy people who know they're scripts and can write scripts to enhance pipelines are worth their weight in gold I suppose?

thak you for the insite, now I just need another me, the week split into two and I'll be fine. lol
Reply With Quote
  #5 (permalink)  
Old 27th April 2007
Ceryni's Avatar
Tutorial contributor
 
Join Date: Jan 2007
Location: Uk
Posts: 67
Thanks: 0
Thanked 4 Times in 4 Posts
Send a message via MSN to Ceryni Send a message via Skype™ to Ceryni
MAXScript Planet animation

If you read the basics section this should make more sense to you and by reading the following script should understand (roughly) how this is working.

MAXScript and the listener are different programs. the listener will execute the funtions immediatly, as previously stated. MAXscript will not execute any functions until u wish to "Evaluate" it. to do this i recommend having Listener AND MAXScript open. to run the script and create the objects >>"file" > "evaulate all" or "Ctrl E"
type in MAXScript and the Listener will give you the feedback, showing where you've got it right and where the mistakes are.
MAXScript is located in the same pulldown tab as Listener. select "New Script"

This Tut will show you how to Animate a planet in orbit around a sun.

Creating the Sun, and the Planet

--Create a Yellow sun, with radius 10
sun = sphere radius:10.0 \
--
set the color of the sun using RGB in square brackets.
Wirecolor:[255,255,50] \
--name the sphere "sun"
name:"sun"

Next step is to create a Planet, and move that planet into an orbit around the sun.

--create a circle for the planets path
orbit1 = circle radius:50.0 name:"orbit"

--create a small red planet and move it to the circle, color it red and name it.

Planet1 = sphere radius:2.0 \
Wirecolor:[200,0,0] \
--the "\" ends a line in this circumstance
name:"planet"

--move planet onto the orbit circle
move planet1 [50,0,0]

Apply a Path Deform Modifier ( path restraint works to )

--create a PD mod, choose "orbit1" to be the path and "Y_axis" to be the axis.
pd1 = pathdeform path: orbit1 axis:1
addmodifier planet1 pd1
--rotate the orbit, just to give it a bit more effect.
rotate orbit1 (quat 5.0 y_axis)
i used Quaterniun angles here as its easier to use that for the rotation then the euler angles. altho i did have to spend 10 minutes working out how to use them enough for it to work. some reason Euler doesnt work here.

this is where math does my head in. using trigonometry we need to move the planet so it remains on the orbit when rotating.

-- Note - 50*sin(5.0) = 4.36 (5.0 is the angle of the orbit, gives me X coordinate)
--Note - 50 - (50*cos(5.0)) = 0.19 ( the x coordinate*cos*angle gives me Z coordinate
move planet1 [-0.19,0,-4.36]

If you did all this correctly, you can now press "evaluate" or "Ctrl E" and the entire scene will be created in front of your eyes.



Animate the Scene.

Select the planet and turn on the "AutoKey",
Move the Timeslider to frame "100"
Click on the modifier panel and under PathDeform change percent to "100"
Turn off "Autokey"

Reselect the first keyframe and right click the keyframe ruler and select "Planet1: percent along path"
Set the In and Out Curves to "Linear"



Play your Animation!






Reply With Quote
The Following User Says Thank You to Ceryni For This Useful Post:
CHALLENGER (8th October 2007)
  #6 (permalink)  
Old 27th April 2007
Ceryni's Avatar
Tutorial contributor
 
Join Date: Jan 2007
Location: Uk
Posts: 67
Thanks: 0
Thanked 4 Times in 4 Posts
Send a message via MSN to Ceryni Send a message via Skype™ to Ceryni
Saving your Animation as a .AVI file.

This can sometimes be a tricky task to do and can take a LONG time to render. luckily it should only be a 3 second animation and in AVI will be a small file. Its not like its got to render lots of detail now has it
this is a typical render formula to give u an insight to how long it might take

lets say u have 45 seconds of animation to render, playback rate = 15/s
each frame takes an average of 2 minutes to render due to detail

Total Rendering Time = 45 sec * 15 frames/sec * 2 minutes/Frame = 1350 minutes or 22.5 hours. =) enjoy that while it lasts.

Rendering a preview

on the Menu bar select "animation" and "make Preview"
just accept the defaults and choose "cinepak codec" from the drop down menu and click OK
Each frame gets drawn individually this shud take about 2 / 3 minutes in total and once its finished will open Windows Media Player with the animation in for you =) yay!

Rendering to a file

If you physically want to save the file then go to the "render scene" dialog by pressing F10 and select common parameters. change range from 0 - 100 and the output size at 320x240 ( under custom )
in the "render output" group choose "files" and find a location to save the file.
In the save dropdown list choose "AVI" file. and name your file
Once again choose Cinepak Codec and select your quality. and click ok
Back to the render scene dialog and click Render.
Once its finished rendering just find the render in the directory and open it.

there you have it. and here is the finished product.


Attached Files
File Type: avi solar.avi (245.5 KB, 253 views)
Reply With Quote
The Following User Says Thank You to Ceryni For This Useful Post:
CHALLENGER (8th October 2007)
  #7 (permalink)  
Old 27th April 2007
geldslaw's Avatar
EnjoyCG Staff
 
Join Date: Nov 2006
Location: London
Posts: 2,294
Thanks: 1
Thanked 45 Times in 44 Posts
Send a message via MSN to geldslaw Send a message via Yahoo to geldslaw Send a message via Skype™ to geldslaw
I think after my course is finished i would like to spend the summer doing more maxscript, thank you for the tutorials and the inspiration.
Reply With Quote
  #8 (permalink)  
Old 27th April 2007
Jelmer's Avatar
Administrator
 
Join Date: Oct 2006
Location: The Netherlands
Posts: 2,635
Thanks: 9
Thanked 180 Times in 84 Posts
Send a message via MSN to Jelmer
nice work ceryni, Although it would have been even better if you did the actual animation with maxscript too, I know it's possible but not exactly how, the last issue of 3dworld magazine has a tut on maxscript so I'll have to try that and see if I can contribute to this tutorial!
Reply With Quote
  #9 (permalink)  
Old 29th April 2007
chickentech's Avatar
"The Titleless"
 
Join Date: Jan 2007
Location: Wouldn't you like to know
Posts: 124
Thanks: 7
Thanked 0 Times in 0 Posts
Send a message via AIM to chickentech
excelent tutorial, thanks. I have been trying to learn Java lately and this language is sort of like it, this tutorial gave me a good senario for when a constant would be used.

now that I know this language is so much like the others I'm learning I think I'll have to go and find out how to use this too. maybe I can then also help, and make some tutorials.

Last edited by chickentech; 29th April 2007 at 04:36 AM.
Reply With Quote
  #10 (permalink)  
Old 29th April 2007
geldslaw's Avatar
EnjoyCG Staff
 
Join Date: Nov 2006
Location: London
Posts: 2,294
Thanks: 1
Thanked 45 Times in 44 Posts
Send a message via MSN to geldslaw Send a message via Yahoo to geldslaw Send a message via Skype™ to geldslaw
Perhaps to research the differences between Object Orientated Programming and Procedural programming. The first is event driven and the second is procedural.

With an event driven environement you can slot in code that allows sub code to respond to events. Windows is an eevent driven environement and slots in programs that you launch that have other programs that respond to events from keyboard and mouse events.

Procedural is very much like th eprograms that are used to get your pc up and running when you tuen it on, they just follow a sequence without any event interuptions and will stop when the list of instructions have been completed.

hope thats helps also?
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads for: MAXScript
Thread Thread Starter Forum Replies Last Post
Learn the basics of maxscript! Jelmer Industry news 0 26th April 2007 11:26 PM

All times are GMT +2. The time now is 03:04 AM.
Copyright © 2006-2008, EnjoyCG