! script name: robb.d/csecarrow
! topic: construct cross section arrow with text

!A
!A NAME:
!A
!A 	Cross Section Arrow
!A
!A DESCRIPTION:
!A
!A 	This script constructs a cross section arrow with text.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT TEXT: Enter the text to be associated with the arrow.
!B
!B 	ARROW START ABS X,Y: Enter the X,Y coordinates for the point of the
!B 		arrow.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ARROW END ABS X,Y: Enter the X,Y coordinates for the end of the arrow.
!B
!B	LEADER END ABS X,Y: Enter the X,Y coordinates for the connecting
!B	  	leader line.
!B
!C NOTE:
!C	
!C	EXTENDED CHARACTER SET:	Characters may be input by their ascii
!C				number. Type in \031 for example to
!C				use the character in the font assigned to
!C				the ascii number 31. The code must be a
!C				three digit number from 001 to 255. 
!C				Some of the extended characters like the
!C				geometric tolerancing symbols take up
!C				more than one space so they should be
!C				bracketed with extra spaces.
!C
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: c-section arrow ")

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

Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)

Start:!
Dynamic_position=1
Dim_type= WsTextArrow
New_line$= "\n"
End_line$= CHR$(10)
Units= CurrentUnits
IF Units= WsMetric THEN
        Length1= 25
ELSE
        Length1= 1
END IF

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

Text$= " "&Text$&" "

stat= SetInputFormat("n4","")
Pstart=XyzInput("ARROW 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("ARROW END",WsXyOnly)
	IF (ExitScript(Destination$)) THEN Leave
	IF NOT ValidGeometry(Pend) THEN Dim_loop
END IF

E1= TextArrow(Dim_type,Pstart,Pend,Text$)

IF Dynamic_position THEN
        Which_end=WsEnd
        Vnum= LastPickView
        Stat= DynamicDimEdit(Vnum,E1,Which_end,"PICK ARROW END LOCATION")
        IF (ExitScript(Destination$)) THEN Leave
END IF

Line_loop:!

Stat=DeleteEntity(Pend)
Pend= ParameterPt(E1,1.0)

IF NOT Graphical_mode THEN

stat= SetInputFormat("n4b","")
Pe=XyzInput("LEADER ENDING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pe) THEN Line_loop

L1= LineTwoPoints(Pend,Pe)
Stat=DeleteEntity(Pe)

ELSE

PlotOff
Pe= PtIncrXyz(Pend,Length1,0.0,0.0)
L1= LineTwoPoints(Pend,Pe)
Stat= MakeInvisible(L1)
Stat= MakeInvisible(Pe)
PlotOn

        Vnum= LastPickView
stat= SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,L1,Pend,Pe,WsDynamicEnd,"PICK LEADER ENDPOINT")
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(L1)
        GOTO Leave
END IF
PlotOff
Stat=DeleteEntity(Pe)
Pe= ParameterPt(L1,1.0)
Stat=SetLastPoint(Pe)
Stat=DeleteEntity(Pe)
PlotOn
Stat= MakeVisible(L1)
Stat= PlotEntity(L1)
END IF

Stat=DeleteEntity(Pstart)
Stat=DeleteEntity(Pend)

GOTO Dim_loop

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