
! script name: filing.d/exportgrouptodxf
! topic: export a group to dxf and/or dwg files

!A
!A NAME:
!A
!A 	Export Group To DXF/DWG
!A
!A DESCRIPTION:
!A
!A
!B INSTRUCTIONS:
!B
!B
!# see also - htdocs/help.d/fileextensions.htm

DIM Answer$[512],Destination$[512]
DIM A$[512],Sdevice$[256]
DIM Filename$[512],Space$[25]
DIM Dir$[512],Mask$[512]

Stat=ChangeLabelStr("ScriptNameStatus","Function: export group to dxf ")

Stat= NamedVarStr("dxf storage dir",WsSystemVars,"/usr/weber/ST/dxf",Sdevice$)
DeActivateUndo

Start:!

Group_loop:!
Group=CreateGroup("TEMPGROUP")

Vnum= LastPickView
Stat=PickBox(Group,Vnum,WsPickPen)
IF (ExitScript(Destination$)) THEN Leave

IF NOT GroupCount(Group) THEN Group_loop

Space$= " "
Question:!
D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Choice$="FILE TO SAVE"
!    Mask$="[A-Za-z0-9]*"
Mask$= "Drawing Exchange Format (*.dxf)|*.dxf|"
Mask$= Mask$&"Drawing File (*.dwg)|*.dwg||"
Stat=UserFileBox(Sdevice$,Mask$,D_label$,Sub_label$,F_label$,Choice$,"Synergy")
Ques2:!
Stat=SetInputFormat("a99","")
Stat=GetValue("SAVE FILE AS: "&Space$,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave
IF POS(Answer$," ") THEN
	Space$= " (NO SPACES) "
	GOTO Ques2
ELSE
	Space$= " "
END IF
IF NOT POS(Answer$,"/") THEN
	Filename$= FileNameString(Sdevice$,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
	Filename$= Answer$
END IF

IF NOT (POS(Filename$,".dxf") OR POS(Filename$,".DXF")) THEN
	IF NOT (POS(Filename$,".dwg") OR POS(Filename$,".DWG")) THEN
                Filename$= Filename$&".dxf"
	END IF
END IF

LowerFileBox
F_type= DoesFileExist(Filename$)
SELECT F_type
CASE 1
        Stat=SetInputFormat("a1",",Y,N,")
        Stat=GetValue("FILE EXISTS: OVERWRITE  Yes or No",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$= "N" THEN
		GOTO Question
        END IF
CASE 2
        Stat=SetInputFormat("a1",",P,")
        Stat=GetValue("COPY NAME IS A DIRECTORY: Proceed ",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
	GOTO Question
END SELECT


Stat= WriteDxfGroup(Group,Filename$)
Stat=DeleteEntity(Group)
LowerFileBox
GOTO Start

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