
! script name: draft.d/textleader
! topic: construct text leader

!A
!A NAME:
!A
!A 	Text Leader
!A
!A DESCRIPTION:
!A
!A 	This script constructs a leader, a line with end points defined
!A 	by the user, with text placed after the last point defined.
!A
!B INSTRUCTIONS:
!B
!B 	LEADER START ABS X,Y: Enter the X,Y coordinates to be used for the
!B 		start of the leader. An arrow will be placed at this point.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	LEADER END ABS X,Y: Enter the X,Y coordinates to be used for the
!B 		end point of the leader.
!B
!B 	INPUT TEXT, None: Enter the line of text to be placed at the end point
!B 		of the leader.  Enter "N" for None, if no text is to be placed
!B 		at this time.
!B
!C NOTE:
!C
!C 	EXTENDED CHARACTER SET: Characters may be input by their ascii number.
!C 		Type in \031 for example to use the character in the font
!C 		assigned to the ascii number 31. The code must be a three digit
!C 		number from 001 to 255.  Some of the extended characters like
!C 		the geometric tolerancing symbols take up more than one space
!C 		so they should be bracketed with extra spaces.
!C
!# see also - htdocs/help.d/dynamicdim.htm
!# see also - points.d/xyzinput.hlp

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

DIM Answer$[256]
DIM Destination$[256]
DIM Dim_type$[256]
DIM Text$[256]
DIM Text1$[256]
DEG

ActivateUndo
Start:!
Dynamic_position=1
Dim_type= WsTextLeader
New_line$= "\n"
End_line$= CHR$(10)


Dim_loop:! 
stat= SetInputFormat("a99","")
stat= GetValue("INPUT TEXT, None ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "N", "n", "None","NONE"
	Text$=""
CASE ELSE
	Stat= BackSlashChars(Answer$,Text1$)
	Stat= ReplaceString(Text1$,New_line$,End_line$,Text$)
END SELECT


stat= SetInputFormat("n4","")
Pstart=XyzInput("LEADER START",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pstart) THEN Dim_loop

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


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

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

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

GOTO Dim_loop

Leave:!
stat= SetInputFormat("n4","")
Stat=DeleteEntity(Pstart)
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
