Beginner – 05 Vray material, maps, textures

  1. set active renderer…
     
    --This sets the current renderer to 
    --the latest version of Vray if you 
    --have it installed
    
    renderers.current = Vray()
    
    -- Store the current render in a variable
    MyVray = renderers.current
    
    -- Now you can inspect what properties 
    -- you can reach from maxscipt
    -- Just press shift + enter to run this line
    ShowProperties MyVray
    
    -- and look in the listener to see what 
    -- properties are available
    
    --Quite a few ;-)
  2. print all texture paths in all bitmapTextures in the current scene
    AllBitmapsInMyScene = GetClassInstances bitmapTex
    for bm in AllBitmapsInMyScene do
    (
    print bm.filename	
    )
    
    
  3. Update all bitmap paths to a new root folder
    --This updates all paths to a new root folder
    --IMPORTANT it ONLY updates bitmaps... NOT
    --VrayHdri or other map. If you want to support more maps
    --You have to get all instances of that class
    
    NewRootFolder = "c:\\temp"
    --you can use this command to show 
    --a dialog to select a folder
    --NewRootFolder = getSavePath() 
    
    AllBitmapsInMyScene = GetClassInstances bitmapTex
    
    for bm in AllBitmapsInMyScene do
    (
      TheFilename = getFileNameFile bm.filename
      TheFileType = getFileNameType bm.filename
    
      bm.filename = (NewRootFolder + "\\" + TheFilename + TheFileType)
    )
    
    
    
  4. change names on materials
    --this prints all the names of the materials..
    for m in sceneMaterials do (
      print m.name
    )
    
    --this changes the names
    for m in sceneMaterials do (
       m.name = ("Test" + m.name )
    )
    
    
  5. Select objects with a certain material
    --This is the name of the material
    FindThisMat = "03 - Default"
    
    --This tries to find the instance of the Material with the name "03 - Default"
    --Remember the for where collect always returns an array
    mat = for m in sceneMaterials where m.name == FindThisMat collect m
    
    --This selects all objects in the scene with that material applied to it
    --check all objects if they have the same material as the first Material in 
    --our array created above
    TheMats = for item in objects where item.material == mat[1] collect item
    	
    Select TheMats
    
  6. update some materials in scene