Maxscript¶
renderStacks is written in MAXScript. Thus, all that renderStacks does, you can also do with MAXScript.
The examples below show how to control renderStacks with MAXScript.
Run renderStacks once before you use these examples. This makes the rstck instance.
rstck.reset()
-- Removes the renderStacks data from the scene. "rstck" is the instance of the renderStacks struct.
rstck.addPass "Bty"
-- Adds the pass "Bty".
campmod = (rstck.addPmodifier "Bty" "Camera" returnguid:true pmodname:"MainCam" type:#pass)
-- Adds a "Camera" pmodifier to the pass "Bty".
-- "Camera" is the pmodifier type. The optional argument "pmodname" sets the name.
-- Type the pmodifier type with the same case as in the UI.
-- To see the exact names of all pmodifier types, use:
-- print( rstck.pmodifierTypes)
-- To get the GUID of the new pmodifier, set returnguid to true.
-- "type" sets whether "Bty" is a #pass or a #passgroup. The default is #pass.
rstck.setPmodProp campmod "camObj__" (Freecamera name:"MainCam") update:false
-- campmod is the GUID that the code above returned.
-- "camObj__" is the name of the property to set.
-- (Freecamera name:"MainCam") is the value. Here, it makes a new Free Camera.
-- "update" is for pmodifiers with dynamic properties, for example ObjParams. For other pmodifiers, set it to false.
resmod = (rstck.addPmodifier "Bty" "Resolution" returnguid:true pmodname:"HDRes" type:#pass)
-- Adds a Resolution pmodifier to the pass "Bty".
rstck.getPmodDataValNames "Resolution"
-- Returns the property 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
-- Sets the resolution properties. Use the correct value class.
-- To change a property of an existing pmodifier, you need the GUID of the pmodifier. Use the function collectPmodDataForPass to get it.
-- To collect the same pmodifiers that pass activation uses, set these arguments:
-- includeBase:true adds the base pmodifiers to the collection.
-- includePassgroup:true adds the pmodifiers of the passgroup to the collection.
-- activeOnly:true adds only the pmodifiers that activation will run.
-- vpfilter:false ignores the viewport activation filter.
-- isPassgroup:false means that the name is a pass full name. To collect the pmodifiers of a passgroup, set it to true.
pmoddata = (rstck.collectPmodDataForPass "Camera001/ivory" includeBase:true includePassgroup:true activeOnly:true vpfilter:false isPassgroup:false)
-- It returns an array with the data of the pmodifiers 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 item, the 1st element shows where the pmodifier is:
-- "pass" = on the pass. "baseDepot" = in ::base. "passgroup" = on a passgroup.
-- The 2nd element is the pmodifier GUID. Use it for all pmodifier operations.
-- The 3rd element is the pmodifier type.
-- The 4th element is the pmodifier name.
-- The other elements are for internal use only.
-- Then, filter the pmodifiers that 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]
-- Get the value of a property:
rstck.getPmodDataVal campmod_guid "apertureWidth" classObj:undefined default:undefined autodefault:false
-- Or set the value of a property:
rstck.setPmodProp campmod_guid "apertureWidth" 24.0 update:false
-- It is better to make changes while the UI is closed.
-- If the UI must stay open, this command refreshes the tree view.
renderStackRol.defaultFillTV()
rstck.removePmodifier "Bty" resmod type:#pass
-- Removes the pmodifier with the given GUID from the #pass "Bty".
rstck.removePass "Bty"
-- Removes the pass "Bty".
apple_pass_elem = (rstck.addPass "Apple" returnguid:true)
-- Makes the pass "Apple". It returns an xmlElement.
apple_pass_guid = (rstck.rsXml.getAttr apple_pass_elem "guid" default:undefined)
-- Gets the pass GUID from the xmlElement.
rstck.addPassgroup "Fruits" passguids:#(apple_pass_guid)
-- Adds the passgroup "Fruits" with the pass "Apple".
rstck.addPass "Orange" returnguid:true
rstck.add2Passgroup "Fruits" #("Orange") byguid:false
-- Makes the pass "Orange" and adds it to the passgroup "Fruits".
rstck.renamePass "Fruits/Apple" "Fruits/Banana" dosave:true
-- Renames the pass "Apple" to "Banana". Each pass name argument is a full pass name (passgroup/pass).
renderStackRol.defaultFillTV()
-- How to make a LayerSet, a pathname or an ObjSet, and add it to a Visibility 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
Samples¶
These are MAXScript samples that we made for users.
-- How to add a script to a Maxscript pmodifier.
pmodData = rstck.getPmodifierData [pmoidifier guid] full:true
rstck.curMXS = "print \"Hello\""
rstck.capturePmod pmodData doapply:false
-- Makes many passes. Each pass gets a [FrameRange] pmodifier: frame 1 for the 1st pass, frame 2 for the 2nd pass, and so on.
(
rstck.reset() -- Resets renderStacks before the new setup. Optional.
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
)
-- How to capture all property values from the scene for a custom object/property pmodifier.
(
passname = <your pass fullname>
pmodname = "pmodifier name"
-- Find the pmodifier.
passpmoddata = (rstck.collectPmodDataForPass passname includeBase:true includePassgroup:true activeOnly:true vpfilter:false isPassgroup:false)
search_pmod = (for pmoddata in passpmoddata where pmoddata[4] == pmodname collect pmoddata)
-- This example assumes one result. It uses the 1st pmoddata.
pmoddata_u_want = search_pmod[1]
-- Get the full pmoddata with the GUID.
pmodData = rstck.getPmodifierData pmoddata_u_want[2] full:true
pmodPropNames = (for data in pmodData[6] collect data[1])
objParamsParam = pmodData[10]
rstck.capturePropVal pmodData pmodPropNames objparam:objParamsParam
)