
! script name: draft.d/edittext
! topic: edit multi line text 

!A
!A NAME:
!A
!A 	Edit Multi Line Text 
!A
!A DESCRIPTION:
!A
!A 	This script edits a text dimension. The legal forms of text
!A 	are those created as Single or Multiple Line Text, Text Leaders, and
!A 	Text Arrows. This script cannot be used for changing the numbers
!A 	inside dimensions. To change numbers inside dimensions Replace Text
!A 	must be used.
!A
!A      NOTE: Release 9.0: Text that is less than 50 characters will now
!A	         be placed in the input line. <Returns> or new lines will
!A	         show up as \n.  Special font characters will show up as
!A	         their three digit code (i.e. degree= \031)
!A
!B INSTRUCTIONS:
!B
!B 	PICK ITEM TO BE CHANGED: Pick the text item to be changed.
!B
!B 	IMPROPER DIMENSION TYPE:  This text may bot be edited by this
!B 		function.	
!B
!B	ENTER TEXT: LEAVE , BACKUP: Enter new text line.  The old text
!B		will appear in the input line already.
!B
!B	TEXT: Restore, Proceed, Leave:  After editing the data in the editor
!B		window, choose one of the following:
!B
!B		Restore - Discard changes and choose new item.
!B		Proceed - Make changes and choose new item.
!B		 Leave  - Discard changes and leave script.
!B
!B

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

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

ActivateUndo
Dynamic_position=1
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= SetInputFormat("n4","")
E1=PickEntity("PICK ITEM TO BE CHANGED", Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Dim_loop
Dim_ent= ParentDimEnt(E1)
IF NOT ValidGeometry(Dim_ent) THEN 
	IF EntityType(E1)= WsTextEnt THEN
		Simple_text=1
		Text_ent= E1
		GOTO Edit_text
	ELSE
		GOTO Dim_loop
	END IF
END IF
Simple_text=0
Dim_type= CompositeDimType(Dim_ent)
SELECT Dim_type
CASE 4 
!	text arrow dimension
	IF IsEntReferenced(E1) OR IsEntReferenced(Dim_ent) THEN
		Stat= SetInputFormat("a1",",E,C,")
		Stat= GetValue("REF. ENTITY. EDIT MAY CORRUPT VDM. Edit or Cancel",Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF Answer$="E" THEN GOTO Edit_text
	ELSE
		GOTO Edit_text
	END IF
CASE ELSE
	Stat=SetInputFormat("a1",",P,C,")
	Stat=GetValue("IMPROPER DIMENSION TYPE:  Proceed , Cancel",Answer$)
	IF ExitScript(Destination$) THEN Leave
	Stat=SetInputFormat("n4","")
	IF Answer$= "C" THEN Leave
END SELECT
GOTO Dim_loop

Edit_text:!
IF Simple_text THEN
	Stat= TextString(Text_ent,Text$)
ELSE
	Stat= DimTextString(Dim_ent,1,Text$)
END IF
IF Stat= 1 THEN Dim_loop
IF LEN(Text$)=0 THEN Dim_loop

Stat= AddBackSlashChars(Text$,Text1$)
IF LEN(Text$)<50 THEN
	Stat= ReplaceString(Text1$,End_line$,New_line$,Text$)
	Stat=SetEditString(Text$)
	Stat=SetInputFormat("a99","",0)
	Stat=GetValue("ENTER TEXT: LEAVE , BACKUP ",Answer$)
	IF ExitScript(Destination$) THEN Leave
	Stat=SetInputFormat("n4","")
	SELECT UPC$(Answer$)
	CASE "BACKUP"
		GOTO Start
	CASE "LEAVE"
		GOTO Leave
	CASE ELSE
		Stat= ReplaceString(Answer$,New_line$,End_line$,Text1$)
		Stat= BackSlashChars(Text1$,Text$)
		IF Simple_text THEN
			ActivateUndo
			Stat= AdvanceUndoNumber("change text")
			Stat= AddDimToUndo(WsUBModifyMode,Text_ent)

			Stat= ChangeTextString(Text_ent,Text$)
		ELSE
			ActivateUndo
			Stat= AdvanceUndoNumber("change text")
			Stat= AddDimToUndo(WsUBModifyMode,Diment)

			Stat= ChAdditionalText(Dim_ent,Text$,"")
		END IF
	END SELECT
ELSE
	Stat= OutputString(File$,Text1$,WsNewFile)
	Stat=EditFile(Editor$,File$,Flip_file)

	Stat=SetInputFormat("a1",",R,P,L,")
	Stat=GetValue("TEXT: Restore, Proceed, Leave ",Answer$)
	IF ExitScript(Destination$) THEN Leave
	Stat=SetInputFormat("n4","")
	SELECT Answer$
	CASE "P"
		Stat= ReadToString(File$,Text1$)
		IF LEN(Text1$)< 1 THEN Start
		Stat= BackSlashChars(Text1$,Text$)
		IF Text$[LEN(Text$)]= CHR$(10) THEN Text$= Text$[1,LEN(Text$)-1]
		IF Simple_text THEN
			ActivateUndo
			Stat= AdvanceUndoNumber("change text")
			Stat= AddDimToUndo(WsUBModifyMode,Text_ent)

			Stat= ChangeTextString(Text_ent,Text$)
		ELSE
			ActivateUndo
			Stat= AdvanceUndoNumber("change text")
			Stat= AddDimToUndo(WsUBModifyMode,Diment)

			Stat= ChAdditionalText(Dim_ent,Text$,"")
		END IF
	CASE "E"
		GOTO Dim_loop
	CASE "C"
		GOTO Leave
	END SELECT
END IF

GOTO Start

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