
! script name: draft.d/textfile
! topic: read and place ascii file

!A
!A NAME:
!A
!A 	Text File
!A
!A DESCRIPTION:
!A
!A 	This script will read an ASCII file in and place it at the specified
!A 	location.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT ABS X,Y,Z: Enter the X,Y,Z coordinates to be used for the
!B 		location of the text file.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	INPUT TEXT FILE NAME: Enter the name of the file to be read in and
!B 		placed at the specified location.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: text file ")

DIM Answer$[256]
DIM Destination$[256]
DIM Dir$[256],New_dir$[256]
DEG

DeActivateUndo
Split_text=0
Text_loop:!

Stat= NamedVarStr("text dir",WsSystemVars,".",Dir$)
Stat=UserFileBox(Dir$,"*","DIRECTORY","SUB DIRECTORIES","FILES","FILE TO OPEN")
Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT TEXT FILE NAME",Answer$)
IF ExitScript(Destination$) OR Answer$= "CANCEL" THEN Leave
LowerFileBox
IF NamedVarVal("save dirs",WsSystemVars,0) THEN V1=CreateVariable("text dir",WsSystemVars,PathNameDirectory(Answer$))

Stat=SetInputFormat("n4=","")
Pc=XyzInput("INPUT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

T1=TextFile(Pc,Answer$)
Stat=DeleteEntity(Pc)

IF Split_text THEN
	Group= SplitMultiLineText(T1)
	IF ValidGeometry(Group) THEN
		PlotOff
		Stat= DeleteEntity(T1)
		PlotOn
		Stat= DeleteEntity(Group)
	END IF
END IF



!This is to strip out the basename
Dir$= Answer$
J= POS(Answer$,"/")
WHILE (J AND J<LEN(Answer$))
	Answer$= Answer$[J+1]
	J= POS(Answer$,"/")
END WHILE
J= POS(Dir$,"/"&Answer$)
New_dir$= Dir$[1,J-1]
V1= CreateVariable("text dir",WsSystemVars,New_dir$)

GOTO Text_loop

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