Beginner – 04 Files and paths

  • concatenating / adding two strings
    --to get ONE "\" in the end you need to write "\\"
    TheFirstString = "c:\\temp"
    TheSecondString = "myFile.max"
    
    --Add them together
    
    newString = ( TheFirstString + TheSecondString )
    
    --result: newString = "c:\tempmyFile.max"
    --NOT a VERY good filePath...
    --remember to add the \\ when needed..
    
    newString = ( TheFirstString + "\\" + TheSecondString )
    --result: newString = "c:\temp\myFile.max"
  • Working with filePaths…
    
    
  • Working with filePaths: Filterstring
    MyPath = "c:\\dir1\\dir2\\dir3\\test_Diffuse.png"
    MyPathArray = filterstring MyPath "\\"
    
    for s in MyPathArray do ( print s )
    
    --Get the name of the Last Folder
    MyPathArray[4]
    
    -- This always takes the Last dir
    -- Even if it is a long path
    MyPathArray[MyPathArray.count - 1]
     
    
  • How to find files from disk
    --gets all files in a folder
    TheFiles = getfiles "c:\\temp\\*"
    for f in TheFiles do (print f )
    
    --gets all png files in a folder
    TheFiles = getfiles "c:\\temp\\*.png"
    for f in TheFiles do (print f )
    
  • Load or Merge a max file, Read more in the script manual
    
    --To reset max from maxscript is very useful when
    --Batching alot of files, #noPrompts forces max to 
    --Just reset without warnings...
    resetMaxFile #noPrompt
    
    
    --if you want to load a maxfile from disk
    loadMaxFile "c:\\temp\\myFile.max"
    
    --if you want to merge.. there is many options that you can use
    --the #select option selects the merged objects so that you can
    --store the selection in a variable
    mergeMaxfile "c:\\temp\\myFile.max" #select
    StoreSelection = selection as array --store the merged objects
    
    --for example if you know the name of some objects in the scene
    --you merge from you can add an array and only merge them
    mergeMaxfile "c:\\temp\\myFile.max" #("box01","box02","box03") #select