Maxscript tutorial: Abbreviations
Abbreviations in Maxscript is one of the powerful tools in scripting, yet not all artists know about. Frankly it was found to make our scripting life much easier, have you ever thought of a short cut to your codes instead of writing them over and over again or at best case you would copy and paste from your collected library of codes.
Well the good news is that abbreviations in Maxscript was found for this exact reason, so instead of defining a Functions the old way why don't we just type fn and then hit Ctrl+Shift+A and it will throw us a full code:
FN _NAME =
(
"Your code"
)
We can do it for loops or rollout templates etc.....
And to know how this magic works we are going to follow those simple steps:
1- Create a new script and in Tools > Open abbreviations file, this will open an empty script for you (in case you didn't edit it before) were you can define your abbreviations.
2- An abbreviation is defined in the form:
<AbbrevName>=<Expanded Form>
for example let's define a for loop
fordo=for i in 1 to 10 do ()
save it. Now open a new script and type fordo and hit Ctrl+Shift+A or go to Edit > Expand abbreviations. Voila! a for loop appeared.
3- There are some rules you should follow here, AbbrevName is case sensitive and it detects spaces. So if you define it like:
For do =, when you want to call it the F should be capital and there is a space inbetween and after do.
4- If you want to arrange the expanded forms to have tabs and on different lines then we have to use (\n) to move the following into another line and (\t) to add a tab, our loop example would change to be:
fordo=for i in 1 to 10 do \n(\n\t "your code" \n)
As simple as this. So when we call fordo it's gonna give us:
for i in 1 to 10 do
(
"your code"
)
And here a couple of abbreviations you can add to your library:
fordo=for i in 1 to 10 do \n(\n\t "your code" \n)
rol=rollout _name "name" \n(\n \n)\n createdialog _name
fn=fn NAME arg_a arg_b =\n(\n\tfnBody\n)
if=if ARG then\n(\n\tState\n)\nelse\n(\n\tState2\n)
sh=shellLaunch @"your file" ""
mfn=maxfilename
mfp=maxfilepath
Thanx for your time I hope you benefited from this tutorial, any question please send them here or if you built your own library we will be happy if you shared it with us
Regards ^_^
Alaa Alnahlawi