
! script name: parasolids.d/endsession
! solids: end a parasolids session

!A
!A NAME:
!A
!A 	End Session
!A
!A DESCRIPTION:
!A
!A	This function will end the parasolids session. It will destroy
!A	all parasolids data contained in the current synergy session.
!A	This function cannot be undone.
!A
!# see also - htdocs/help.d/parasolids.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: end solids session ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[512]
DIM Dir$[512]
DIM Dir1$[512]
DIM Default$[512]
DIM D_label$[256],Sub_label$[256],F_label$[256],Choice$[256]
DIM Mask$[256],Space$[256],Jobname$[256]


Default$= "C:/usr/weber/ST/solids/"
Stat= NamedVarStr("solid file dir",WsSystemVars,Default$,Dir$)

Start:!
Stat=SetInputFormat("a1=",",S,E,C,")
Stat= SetEqualsValue(0,"S")
Stat=GetValue(" Save model, End, Cancel ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "S" THEN Save_file
IF Answer$= "C" THEN Leave
IF Answer$="E" THEN
	Stat=SetInputFormat("a1=",",Y,N,")
	Stat= SetEqualsValue(0,"Y")
	Stat=GetValue("THIS WILL DESTROY THE SOLID MODEL: Yes or No",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	IF Answer$= "Y" THEN End_session
END IF
GOTO Start

Save_file:!
Question:!
D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Choice$="FILE TO SAVE"
Mask$="[A-Za-z0-9]*"
Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$,"Synergy")
Ques2:!
Stat=SetInputFormat("a99","")
Stat=GetValue("SAVE JOB AS: "&Space$,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NamedVarVal("save dirs",WsSystemVars,0) THEN V1=CreateVariable("solid file dir",WsSystemvars,PathNameDirectory(Answer$))

!   IF POS(Answer$," ") THEN
!         Space$= " (NO SPACES) "
!         GOTO Ques2
!   ELSE
!        Space$= " "
!   END IF
IF NOT POS(Answer$,"/") THEN
        Jobname$= FileNameString(Dir$,Answer$)
ELSE
        Testposr=1
        REPEAT
            Testpos=POS(Answer$[Testposr],"/")
            Testposr=Testposr+Testpos
        UNTIL (NOT Testpos)
        Namelen=LEN(Answer$)-Testposr+1

        IF NOT Namelen THEN Ques2
        Jobname$= Answer$
END IF
LowerFileBox


Name$= Jobname$
n1= POS(Name$,".x_t")
IF N1 THEN Name$= Name$[1,n1-1]
n1= POS(Name$,".X_T")
IF N1 THEN Name$= Name$[1,n1-1]

Stat= WPKSaveFile(Name$)
GOTO End_session


End_session:!
DeActivateUndo
WPKEndSession
PlotAll

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