Flatten List

From Director Online Wiki
Jump to: navigation, search

Copy and paste on a movie script:


--------------------------------------
on flattenList ll, fAvoidDuplicates
  -- flattens any nested linear or prop list 
  -- ll is the list we want to flatten
  -- set fAvoidDuplicates flag to TRUE if you want to eliminate duplicated values
  -- returns void (if parameter is not a list) or a linear list
  -- by Iñigo de Gracia
    ------------------------------------------
  if not listp (ll) then return void
  lResult = []
  repeat with atom in ll
    if not listp (atom) then 
      if not (lResult.getOne (atom) and fAvoidDuplicates) then lResult.add (atom)
 
    else
      lowestList = flattenList (atom, fAvoidDuplicates)
      repeat with lowestAtom in lowestList
        if not (lResult.getOne (lowestAtom) and fAvoidDuplicates) then lResult.add (lowestAtom)
      end repeat
    end if
  end repeat
  return lResult
end