|Very introductory Maxscript tutorial 1|
This tut should take about 5 mins to complete.
I'll hopefully do a few of these over the next while. I'll start off really really basic for those who have always wanted to learn maxscript but haven't been able to get started. (that was me for a long time!)
The best way to learn maxscript is to learn a few basic tricks that you can use in your everyday work. You can then extend your knowledge as you come across tasks that you can *almost do with your current knowledge.
Ok, first of all I'll go over a few basics.
To follow allong with these tuts, open the maxscript listener by hitting F11.
The pink area up the top is the listener where if you enable the macrorecorder, it will tell you what max is doing in maxscript terms as you do regular tasks in max. We won't pay attention to this area in this tut.
The white area is where everything will be happening. Delete the "Welcome to maxscript" message so we have a blank slate to start with.
Create a sphere in the scene so we have an object to talk to.
There are two simple ways to refer to an existing scene object in max. You can select it and refer to the selection or you can refer to it by name. The way maxscript refers to objects is by their name with a $ in front. So to refer to the sphere you just created, type:
Now, with the cursor at the end of that, hit the enter on the numeric keypad. That will execute the current line. If you want to execute more than one line, select them all and hit numeric enter.
once you hit enter, maxscript will return the following in blue:
$Sphere:Sphere01 @ [10,-5,0]
The last numbers will vary depending on where you created the sphere in the scene.
This is confirmation that you are talking about the sphere and that your syntax is correct.
Now lets try something slightly more useful. Type:
and hit numeric enter to execute. maxscript will return the radius of the sphere!
Notice how there is a hierarchy to the command. You started with the object itself then a period (.) then the parameter belonging to the object. You can refer to other parameters the same way. ie;
$Sphere01.segments will return the segments value.
Setting attribute values
Now what we want to do is change the values not just look at them.
$Sphere01.segments = 35
You'll notice as soon as you execute the line, the sphere changes it's segments to 35!
Well you could have done that faster with the GUI right? What if you have 25 spheres all with different radii and you want to just change their segment count? (a common problem)
Working on selections of many objects
I referred earlier to the fact we can refer to objects by referring to the current selection. In maxscript the shortcut to this is to simply select an object (select your sphere) and type:
When you execute this, you'll get the same result as if you had typed $Sphere01
Now we are going to exploit the power of "mapped functions"
Create 10 spheres of random radii and position. Select them all. Now type the following and execute it:
$.segments = 10
All the spheres will retain all their setting except the segments on all of them will be set to 10.
Thats it for now!
Play around with other objects and other attributes.
if you want to know what parameters are availiable to you on a given object, type:
For the sphere, that will return the following list:
.smooth : boolean
.radius : float
.segs : integer
.mapcoords : boolean
.slice : boolean
.hemisphere : float
.sliceFrom : angle
.sliceTo : angle
.chop : integer
.recenter : boolean
.realWorldMapSize : boolean
read 61974 times
11/21/2006 2:50:48 PM (last edit: 11/6/2009 3:51:32 PM)
Never even tried to write any max-scripts, so "really basic" sounds good.
Terribly boring signature.
read 61953 times
11/21/2006 3:12:21 PM (last edit: 11/21/2006 3:12:21 PM)
same here timon.
Nice one Dub. I'll have a go at this later when my headache subsides.
Do A Barrel Roll!!!
read 61948 times
11/21/2006 3:14:06 PM (last edit: 11/21/2006 3:14:06 PM)
woot tried it...when can we expect the next one, it's great but a bit short, need more need more now that I started
read 61930 times
11/21/2006 3:55:56 PM (last edit: 11/21/2006 3:55:56 PM)
I hoped it would have that effect.
I'll do another tomorrow.
I want it to be very simple so that people won't get scared off and instead have their appetite whetted for other more difficult tutorials.
read 61927 times
11/21/2006 4:01:57 PM (last edit: 11/21/2006 4:01:57 PM)
I'm scared of nuttin!!!
give me a tut
read 61923 times
11/21/2006 4:09:40 PM (last edit: 11/21/2006 4:09:40 PM)
good stuff man!
I keep tellin myself that I should learn scripts one day; and you have given me a much needed push.
read 61919 times
11/21/2006 4:15:41 PM (last edit: 11/21/2006 4:15:41 PM)
GREAT DUB... I really want to learn MXS :)
read 61904 times
11/21/2006 4:56:40 PM (last edit: 11/21/2006 4:56:40 PM)
| Nik Clark
Nice one, Dub. Maxscript is awesome, and is an invaluable tool.
read 61897 times
11/21/2006 5:02:24 PM (last edit: 11/21/2006 5:02:24 PM)
/me sends a hit squad to Dub's house for giving away the secrets :P
j/k man. Good job
read 61884 times
11/21/2006 5:47:18 PM (last edit: 11/21/2006 5:47:18 PM)
I think this is Dubs subtle plan to run Boomer labs out of bussiness
read 61877 times
11/21/2006 6:32:41 PM (last edit: 11/21/2006 6:32:41 PM)
As people reach the limits of maxscript, they will realise where C++ code is the better way to go and thats where Boomer comes in :-)
read 61869 times
11/21/2006 7:38:04 PM (last edit: 11/21/2006 7:38:04 PM)
Real nice of you to do this Dub, cheers.
Maxscript looks sooo useful and it's an area of Max I never got to...'til now :)...........more, more
read 61850 times
11/21/2006 10:49:11 PM (last edit: 11/21/2006 10:49:11 PM)
Just logged in to thank you very much. I'm working as a programmer, dreaming of getting a job in 3ds someday and raising money so I could go to college somewhere where it's beying thought.
Great thanks for this , please keep it up, I will follow the series =)
I have somewhat changed the fluffy avatar.
read 61776 times
11/23/2006 2:57:54 AM (last edit: 11/23/2006 2:57:54 AM)
Really nice, Dub. After some years of maxing, 1st time I open the thingy -on purpose-. Looks highly promising.
read 61742 times
11/23/2006 8:09:05 PM (last edit: 11/23/2006 8:09:05 PM)