1. Home
  2. Docs
  3. renderStacks
  4. Maxscript


renderStacks is a maxscript which means I do whatever I do with Macscript. That also means you can do, too!
This is some examples of how you can control renderStacks with Maxscript.

Make sure to run renderStacks once to get a rstck instance.

-- Clear renderStacks data from the scene. "rstck" is the instance of renderStacks struct.
rstck.addPass "Bty"
-- Adding "Bty" pass.
campmod = (rstck.addPmodifier "Bty" "Camera" returnguid:true pmodname:"MainCam" type:#pass)
-- Adding "Camera" pmodifier to "Bty" pass. 
-- "Camera" is a pmodifier type. You can set name with "pmodname" optional argument.
-- Make sure to use the exactly same case for pmodifier type as you are seeing in the UI. 
-- If you want to see the exact name of all pmodifiers. You can use... 
-- print( rstck.pmodifierTypes)	
-- To get the guid of newly added pmodifier, returnguid need to be "true".
-- "type" defines if "Bty" is #pass or #passgroup. The default is #pass
rstck.setPmodProp campmod "camObj__" (Freecamera name:"MainCam") update:false
-- campmod is the guid which was returned by the above code.
-- "camObj__" is the property name to set.
-- (Freecamera name:"MainCam") is the value. In this case, we are making a new Free Camera. 
-- update is for the pmodifier that dynamically changes properties like ObjParams. For non-dynamic property pmodifiers just set as "false"

resmod = (rstck.addPmodifier "Bty" "Resolution" returnguid:true pmodname:"HDRes" type:#pass)
-- Adding a Resolution pmodifier to "Bty" pass

rstck.getPmodDataValNames "Resolution"
-- Returns propery names of a pmodifier type.
rstck.getPmodDataVal resmod "width" classObj:undefined default:undefined autodefault:false
-- Returns the current value of the property 
rstck.setPmodProp resmod "width" 1920 update:false 
rstck.setPmodProp resmod "height" 1080 update:false 
rstck.setPmodProp resmod "scale" true update:false 
rstck.setPmodProp resmod "scalePercent" 50.0 update:false 
-- Setting resolution properties. Make sure to use the correct value class.

-- If you want to change the value of properties in a exissing pmodifier, you need to know the guid of the pmodifier. You can use collectPmodDataForPass function for that.
-- To collect the same pmodifiers which used by pass activation. You need to use the following arguments. 
-- includeBase:true means it will include base pmodifiers to the collection.
-- includePassgroup:true means it will include pmodifiers in passgroup to the collection.
-- activeOnly:true means it will include only to-be-activated pmodifiers to the collection
-- vpfilter:false means viewport actication filter will be ignored.
-- isPassgroup:false means the given fullpassname is passname. If you want to collect pmodifiers in a passgroup, you need to set this to true.

pmoddata  = (rstck.collectPmodDataForPass "Camera001/ivory" includeBase:true includePassgroup:true activeOnly:true vpfilter:false isPassgroup:false)

-- This will return an array of data of modifiers in the pass like this.
#("baseDepot", "{37E33B85-CB2D-4654-9DC5-2B246F0EE62F}", "Exposure", "Base_Exposure", true, #(), false, false)
#("passgroup", "{7EF12325-83ED-4D0C-8859-B858382732AF}", "ObjParams:invis", "ObjParams:invis_001", true, #(), false, false)
#("pass", "{177A5167-FFC6-4110-81BA-540F72C42A64}", "Material", "Material_002", true, #(), false, false)
#("pass", "{1530089B-5199-4E39-A01C-BDA175E65E1C}", "Camera", "Camera_001", true, #(), false, false)
-- In each itemn, the first element "pass" means, it is under pass. 
-- If a pmodifier is in ::base, it will be "baseDepot". If a pmodifier is under a passsgroup, it will be "passgroup".
-- The 2nd element is pmodifier guid. You need to use this to do any opration for pmodifier.
-- The 3rd element is pmodifier type. 
-- The 4th element is pmodifier name.
-- Other elements are internal use only.

-- Then you can filter pmod you want like this
passpmoddata = (rstck.collectPmodDataForPass "Camera001/ivory" includeBase:true includePassgroup:true activeOnly:true vpfilter:false isPassgroup:false)
campmods = (for pmoddata in passpmoddata where pmoddata[3] == "Camera" collect pmoddata)
campmod_guid = campmods[1][2]

-- Now we can get the value of a prop
rstck.getPmodDataVal campmod_guid "apertureWidth" classObj:undefined default:undefined autodefault:false

-- Or set the value of a prop
rstck.setPmodProp campmod_guid "apertureWidth" 24.0 update:false 

-- Usually it is a good idea to modity while UI is closed. 
-- But, if you really want to keep open UI, this command will refresh the treeview.
rstck.removePmodifier "Bty" resmod type:#pass
-- remove a pmodifier with given guid from #pass "Bty"

rstck.removePass "Bty"
-- remove pass "Bty"

apple_pass_elem = (rstck.addPass "Apple" returnguid:true)
-- Make a "Apple" pass. It returns xmlElement.
apple_pass_guid = (rstck.rsXml.getAttr apple_pass_elem "guid" default:undefined)
-- get pass guid from xmlElemement
rstck.addPassgroup "Fruits" passguids:#(apple_pass_guid) 
-- add a "Fruits" passgroup with "Apple" pass.

rstck.addPass "Orange" returnguid:true
rstck.add2Passgroup "Fruits" #("Orange") byguid:false
-- Make another  "Orange" pass and adde to "Fruits" passgroup.

rstck.renamePass "Fruits/Apple" "Fruits/Banana" dosave:true 
-- rename "Apple" pass to "Banana". Remember all passname argument means full pass name(passgroup/pass).


-- How to make layer set / pathname / objset and add to Viability pmodifier
-- setPmodObjData <pmodguid> <settype> <setname> <inexclude>

vismod2guid = (rstck.addPmodifier pass2_name "Visibility" returnguid:true pmodname:"")
rstck.addPathnames "T*" dosave:true
rstck.setPmodObjData vismod2guid "pathname" "T*" true

vismod3guid = (rstck.addPmodifier pass3_name "Visibility" returnguid:true pmodname:"")
rstck.setLayerSet "Ts" #("Teapot", "Torus", "Tube")
rstck.setPmodObjData vismod3guid "layerset" "Ts" true

vismod4guid = (rstck.addPmodifier pass4_name "Visibility" returnguid:true pmodname:"")
rstck.setLayerSet "HasRadius" #("Teapot", "Sphere")
local itemdata = #()
append itemdata #(true, #add, "HasRadius", #layerset)
append itemdata #(true, #add, "GEOS", #layer)
rstck.setObjSet "BallOnPlane" itemdata msg:false apply:true
rstck.setPmodObjData vismod4guid "objset" "BallOnPlane" true


I collected some of MXS samples that I have made for users.

-- How to add Maxscript pmodifier script.

pmodData = rstck.getPmodifierData [pmoidifier guid] full:true
rstck.curMXS = "print \"Hello\""
rstck.capturePmod pmodData doapply:false
-- I would like to create a lot of passes. Every next pass should have pmodifier [FrameRange] frame 1, second pass frame 2 etc.... 

    rstck.reset() -- if you want to reset before add the new setup.
    local passnames2add = #("Apple", "Banana", "Orange","Pineapple")
    for i = 1 to passnames2add.count do (
    local pn = passnames2add[i]
    rstck.addPass pn
    frsmod = (rstck.addPmodifier pn "FrameRange" returnguid:true pmodname:"FrameRange" type:#pass)
    rstck.setPmodProp frsmod "type" 4 update:false
    rstck.setPmodProp frsmod "frames" (i as string) update:false