
! script name: draft.d/mlinetext
! topic: construct multi line text 

!A
!A NAME:
!A
!A 	Multi Line Text 
!A
!A DESCRIPTION:
!A
!A 	This script constructs a multi line text entry.
!A
!B INSTRUCTIONS:
!B
!B TEXT: Edit,   Proceed , Cancel:
!B
!C NOTES:
!C
!C 	EXTENDED CHARACTER SET: Characters may be input by their ascii
!C 		number. Type in \031 for example to use the character
!C 		in the font assigned to the ascii number 31. The code
!C 		must be a three digit number from 001 to 255.  Some of
!C 		the extended characters like the geometric tolerancing
!C 		symbols take up more than one space so they should be
!C 		bracketed with extra spaces.

stat=ChangeLabelStr("ScriptNameStatus","Function: multi line text ")

DIM Answer$[256]
DIM Destination$[256]
DIM File$[256]
DIM Text$[32000]
DIM Text1$[32000]
DIM Editor$[256]
DEG

ActivateUndo
Start:!
Dynamic_position=1
Dim_type= WsTextLine
New_line$= "\n"
End_line$= CHR$(10)
Stat= NamedVarStr("file editor",WsSystemVars,"notepad.exe",Editor$)
Flip_file= NamedVarVal("flip crlf",WsSystemVars,0)

Start:!
File$= "tempdata"
Text$= ""
stat= OutputString(File$,Text$,WsNewFile)

Dim_loop:! 
Stat=EditFile(Editor$,"tempdata",Flip_file)

Stat=SetInputFormat("a1",",E,P,C,")
Stat=GetValue("TEXT: Edit,   Proceed , Cancel",Answer$)
IF ExitScript(Destination$) THEN Leave
Stat=SetInputFormat("n4","")
SELECT Answer$
CASE "P"
        Stat= ReadToString(File$,Text1$)
        IF LEN(Text1$)< 2 THEN Start
	Stat= BackSlashChars(Text1$,Text$)
CASE "E"
	GOTO Dim_loop
CASE "C"
	GOTO Leave
END SELECT

IF Dynamic_position THEN
	Pend= PointXYZ(0,0,0)
ELSE
	Pend=XyzInput("TEXT POSITION",WsXyOnly)
	IF (ExitScript(Destination$)) THEN Leave
	IF NOT ValidGeometry(Pend) THEN Dim_loop
END IF


PlotOff
E1= TextArrow(Dim_type,Pend,Pend,Text$)
PlotOn
Stat=SetLastPoint(Pend)
Stat=DeleteEntity(Pend)

IF Dynamic_position THEN
        Which_end=0
        Vnum= LastPickView
        Stat= DynamicDimEdit(Vnum,E1,Which_end,"PICK TEXT LOCATION",WsFalse)
	IF (ExitScript(Destination$)) THEN
                Stat= DeleteEntity(E1)
                GOTO Leave
        END IF
END IF

ActivateUndo
Stat= AdvanceUndoNumber("text dim")
Stat= AddDimToUndo(WsUBCreateMode,E1)

GOTO Leave

Leave:!
stat= SetInputFormat("n4","")
Stat=DeleteEntity(Pend)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
