
! script name: ShapeCorp.d/savecnccode
! topic: save cnc code

!A
!A NAME:
!A
!A 	Save CNC Code
!A
!A DESCRIPTION:
!A
!A	This script saves the cnc code to a separate file. The files
!A	are named O0001, O0002, etc.
!A
!A	The cnc code files are saved in a sub-folder of the folder
!A	C:/CADCAM/Parts the name of the sub-folder is the project name.
!A
!B INSTRUCTIONS:
!B
!B
!# see also - htdocs/help.d/shape_help.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: save cnc code ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM A$[256]
DIM Copyname$[256]
DIM Project_name$[256]
DIM Cnc_code_dir$[255]
DIM Dir$[512]

Start:!

Name$="tapefile"
Stat= NamedVarStr("shape cnc code dir",WsSystemVars,"/CADCAM/CNC_code/",Cnc_code_dir$)

IF NOT DoesFileExist(Cnc_code_dir$) THEN
       CREATE DIR Cnc_code_dir$
END IF
V1=CreateVariable("Cnc_code_dir",WsSystemVars,Cnc_code_dir$)

Prop_ent= FindUserData("ShapeProjectInfo",10272)
IF ValidGeometry(Prop_ent) THEN
	Project_name$= UserDataStr(Prop_ent,"Project name:")
ELSE
	Project_name$="noname"
END IF
Dir$= Cnc_code_dir$&"/"&Project_name$&"/"
IF NOT DoesFileExist(Dir$) THEN
       CREATE DIR Dir$
END IF
Project_name$=TRIM$(Project_name$)
IF LEN(Project_name$)=0 THEN
   Stat=SetInputFormat("a99","")
   Stat=GetValue("PROJECT NAME",Answer$)
   IF (ExitScript(Destination$)) THEN Leave
   Project_name$=UniformPathName(Answer$)
   Stat=SetInputFormat("n4","")
END IF


A$= VariableString("CNC_program_name")
Copyname$=Dir$&A$
IF NOT DoesFileExist(Name$) THEN
   Stat=SetInputFormat("a99","")
   Stat=GetValue("CNC CODE NOT GENERATED  Proceed",Answer$)
   IF (ExitScript(Destination$)) THEN Leave
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF

Stat= CopyFile(Name$,Copyname$)

A$= "CNC CODE SAVED:"&Copyname$
Stat= MessageStringBox(A$,"CNC CODE SAVED")

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

