Beginner – 01 Basics

  • –The 3ds max maxscript helpfile is probably the best place to look for your scripting questions. Since 3dsmax 2012 it is now available online…
    –Make a bookmark of this… it is your best friend in the scripting djungle
    3dsmax 2012 maxscript Help File
  • –Comments
    --The two -- is used to comment out a single line
    --this line will be ignored
    You can also do this if you want to comment 
    out many lines of code... 
  • –Variables
    myVarWithMyOwnNameString = "test"
    myVarWithMyOwnNameInteger = 34
    myVarWithMyOwnNameFloat = 3.14523
    myVarWithMyOwnNameVector = [0,23,1]
    myVarWithMyOwnNameBoolean = true
  • –Debug – Print Variables
    –To print out a value you can use the Print() command

    print myVarWithMyOwnNameString -- prints out "test"
    print myVarWithMyOwnNameInteger -- prints out 34
    print myVarWithMyOwnNameFloat -- prints out 3.14523
    print myVarWithMyOwnNameVector -- prints out [0,23,1]
    print myVarWithMyOwnNameBoolean --prints out true
  • –Properties
    myBoxObject = box() -- create a box and store it in 
                        -- the myBoxObject variable
  • -- show what properties that is available on the object

    showProperties myBoxObject —

  • –Edit some properties
    myBoxObject.length --get the length of the box
    myBoxObject.height = 150 --set the height of the box
    myBoxObject.width = 34.54
    myBoxObject.lengthsegs = 4
    myBoxObject.pos = [0,10,20]
  • –Iteration – For Loop
    --For Loop, biggest benefit you get a number you can use...
    for x = 1 to 100 do ( 
        print x --this prints the values from 1 to 100 
  • –You can create for loops inside other loops
     -- first we create a box and store it inside variable b
    b = box width:1 length:1 height:1 name:"OS3D_exampleBox"
    for x = 1 to 10 do (
      for y = 1 to 10 do (
      tmp = instance b
      tmp.pos = [x*10,y*10,0]
  • –Arrays, lists of xx
     --this creates a new array "myListOfStrings" with three strings in it...
    myListOfStrings = #("name1", "name2", "name3"  )
    --for you who program other languages, yes arrays starts "usually" on 1, --there is some cases like bitArrays where it is 0 based
    myListOfStrings[1]  -- get the first name in the list
  • –Loop through all values in an array
    --To do a for loop you need to know how many 
    -- items that are in the list/array..
    myListOfStrings = #("name1", "name2", "name3"  )
    -- this gets the number of items in the array
    nmbr_of_items =  myListOfStrings.count
    --We can now do a for loop from 1 to "nmbr_of_items"
    --to loop through all items...
    for i = 1 to  nmbr_of_items do (
    --this prints all the items in the array
    print myListOfStrings[i]
  • –“For each” loop
    --It is very common that you want to loop through all items in an array 
    --and do something and therefor you have a another way of writing a loop 
    --called "for each" loop...
    --First we need a fresh array again
    myListOfStrings = #("name1", "name2", "name3"  )
    -- Second lets loop through them all and print out the values
    for item in myListOfStrings do (  print item ) --"item" is a name I choose...
    for myVarName in myListOfStrings do (  print myVarName) --"myVarName" is another name I choose..., it does the same thing