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

!A
!A NAME:
!A
!A 	Operation Text Leader
!A
!A DESCRIPTION:
!A
!A 	This script constructs a leader to a hole with an operation.
!A
!B INSTRUCTIONS:
!B
!B 	PICK HOLE: Pick the hole that the leader will be constructed from.
!B
!# see also - htdocs/help.d/dynamicdim.htm
!# see also - points.d/xyzinput.hlp

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

DIM Answer$[256]
DIM Destination$[256]
DIM Dim_type$[256]
DIM Operation$[256]
DEG

ActivateUndo
Start:!
Dynamic_position=1
Dim_type= WsTextLeader


Dim_loop:! 

H1=PickSpecificEnt("PICK HOLE",WsPickHoles)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(H1) THEN Line_loop

Operation_prop= GetAssocEnt(H1,WsOperation)
IF NOT ValidGeometry(Operation_prop) THEN Line_loop
Stat= GetUserDataName(Operation_prop,Operation$)

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


Pstart= ParameterPt(H1,0.0)

PlotOff
E1= TextArrow(Dim_type,Pstart,Pend,Operation$)
IF Box_on THEN
	Stat=EditDraftSetting(E1,WsTextBoxOn,1,Calculate)
END IF
IF Underline_on THEN
	Stat=EditDraftSetting(E1,WsTextUnderline,1,Calculate)
END IF
PlotOn
Stat=SetLastPoint(Pend)
Stat=DeleteEntity(Pend)
Stat=DeleteEntity(Pstart)

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

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

GOTO Dim_loop

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