
! script name: vdraft.d/textline
! var_topic: construct text

!A
!A NAME:
!A
!A 	Place Text         VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script places text at a point.
!A
!B INSTRUCTIONS:
!B
!B 	PICK LOCATION: Pick the location of the text. This location can
!B	be modified by three offset values found in the free parameters.
!B
!B 	INPUT TEXT: Enter the line of text to be placed at the point.
!B
!C NOTE:
!C
!C 	EXTENDED CHARACTER SET: Characters may be input by their
!C	ascii number.  Type in \031 for example to use the character
!C	in the font assigned to the ascii number 31. The code must be
!C	a three digit number from 001 to 255.  Some of the extended
!C	characters like the geometric tolerancing symbols take up more
!C	than one space so they should be bracketed with extra spaces.
!C
!# see also - htdocs/help.d/dynamicdim.htm

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

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


Start:!
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Dim_type= WsTextLine
New_line$= "\n"
End_line$= CHR$(10)

Dim_loop:! 
Stat= SetInputFormat("a99","")
Stat= GetValue("INPUT TEXT ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Stat= BackSlashChars(Answer$,Text1$)
Stat= ReplaceString(Text1$,New_line$,End_line$,Text$)

Pick_loop:!
Element1=PickEntity("PICK LOCATION")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Element1) THEN Pick_loop
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(Element1,Point1$)

Stat= GenerateVarName("D",Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Text arrow")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
V1= FreeParameter("X incr",0)
V2= FreeParameter("Y incr",0)
V3= FreeParameter("Z incr",0)
V4= StringConstant(Text$)
Ps= PtIncrXyz(Pc,V1,V2,V3)
E1= TextArrow(WsTextLine,Ps,Ps,V4)
Stat= NameEntity(E1,Name$)
Stat=DeleteEntityList(Pc,Ps)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(E1)
Stat= PlotEntity(Point1$)
IF NOT ValidGeometry(E1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("text arrow")
	Stat= AddDimToUndo(WsUBCreateMode,E1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

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
