
! script name: wscmill.d/litesave
! topic: copy ascii tapefile to named location

!A
!A NAME:
!A
!A 	Export Current CNC gcode file
!A
!A DESCRIPTION:
!A
!A 	Export generated gcode to named location.  This script saves generated
!A 	CNC gcode to a named location with a .ngc extension.
!A	It also has the option to store the entire ( geometry, tooling and
!A	process ) job to the Synergy storage area.
!A

stat=ChangeLabelStr("ScriptNameStatus","Function: export ascii tapefile to CNC ")

DIM Answer$[256]
DIM Destination$[256]
DIM Dir$[256]
DIM Post_name$[256]
DIM File_name$[256]
DIM Storage_dir$[256]
DIM Job_name$[256]

StdWorkplane
Stat= NamedVarStr("Dnc tape storage dir",WsSystemVars,"/home/",Storage_dir$)
IF DoesFileExist(Storage_dir$)<>2 THEN Storage_dir$="/home"
Dir$= NamedVariableStr("post dir",WsSystemVars,"/usr/weber/post_formats/")

Post_name$=FileNameString(Dir$,"EMC2")

Stat= AddEndOfBlock("tapefile","tdata",Post_name$,Tape_format$)

File_name$="tdata"

Save_file_as:!
Num_lines=FileLineCount(File_name$)
FOR J= 1 TO Num_lines
        Stat= GetFileLine(File_name$,J,Job_name$)
	IF Job_name$[1,1]="P" THEN
		Answer$= Job_name$[1,5]
		Answer$=FileNameString(Storage_dir$,Job_name$)
		GOTO Copy_file
	END IF
NEXT J
Stat=UserFileBox(Storage_dir$,"*","","","","","SAVE")
Stat=SetInputFormat("a99","")
Stat=GetValue("NC CODE FILE NAME TO STORE",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "CANCEL" THEN Leave

IF NOT POS(Answer$,".ngc") THEN
Answer$=Answer$&".ngc"
END IF

Copy_file:!
	Stat= DisplayMessage("Storing Job: "&Job_name$)
	Stat= SynergySleep(1)
	Stat=CopyFile(File_name$,Answer$)

LoadToControl: !
Stat=SetInputFormat("a1=",",Y,N,")
Stat=SetEqualsValue(0,"N")
Stat=GetValue("SAVE GEOMETRY DATA - Yes, No ",A$)
IF POS(A$,"Y")>0 THEN
	 LOAD "wsccommon.d/storageas"
END IF

Leave:!
LowerFileBox
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

