' Name: SEd_SaveAll
' Author: Michael Silberbauer 2001-05
' Title:  Back up scripts in a project to text files (Sternberg H)
' Function:    Writes all scripts in a project to a directory
' Description: Writes all scripts in a project to a directory
'              Script.FileWrite and 5-99 Howie Sternberg, State of Connecticut, DEP
'              Hacked 5-2001 Mike Silberbauer IWQS DWAF RSA   
' Version      0.0

theProject = av.GetProject
theProjectName = av.GetProject.AsString
theProjectName = theProjectName.Left((theProjectName.Count-4))
lastScript = "(no scripts in"+theProjectName+")"
i = 0
for each d in theProject.GetDocs
  if (d.Is(Sed)) then    
    i = i+1
    theScript = d.AsString
    theFName = (d.GetName.Substitute(" ","").Translate(".","_")+".ave").AsFileName
    theDirectory = "D:\DATA\AV\SCRIPTS\AUTOSAVE\"+theProjectname+"\"
    theFName = theDirectory+theFName.GetBaseName.AsString
    theFName = theFName.AsFileName
    f = LineFile.Make(theFName,#FILE_PERM_WRITE)
    if (f=nil) then
      MsgBox.Error("Cannot open file:"++theFName.GetName,"")
      return nil
    end
    f.WriteElt(d.GetSource)
    av.ShowMsg("("+i.AsString+")"++"Script written to"++theFName.GetFullName)
    f.close
    end
end
MsgBox.Info(i.AsString++"scripts written to"++theDirectory,"Scripts Saved")