
! script name: draft.d/runningdatum
! topic: construct linear running datum dimension

!A
!A NAME:
!A
!A 	Linear Running Datum Dim
!A
!A DESCRIPTION:
!A
!A 	This script constructs a linear running datum dimension.
!A
!B INSTRUCTIONS:
!B
!B 	DIM START ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the start point of the dimension.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	DIM END ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the end point of the dimension.
!B
!B 	DIM LOCATION: PICK FREE POINT: Pick the
!B 		location for the placement of the dimension.
!B
!# see also - htdocs/help.d/dynamicdim.htm
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: linear running datum dim ")

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

ActivateUndo
Start:!
Dynamic_position=1
Dim_type= WsRunningDim
Dim_type$= "DATUM"

text_follows= GetDefault(WsTextFollows)
stat= SetDefaults(WsTextFollows,1)

Angle= InputAngle("DIMENSION ANGLE")
IF (ExitScript(Destination$)) THEN Leave

Ps=XyzInput("DATUM ",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Dim_loop

Startup: First= 1

Dim_loop:!

Stat=SetLastPoint(Ps)
Pe=XyzInput(Dim_type$&"DIM END",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pe) THEN Dim_loop

Dist= DistTwoPts(Ps,Pe)
IF Dist< 0.0001 THEN
	GOTO Dim_loop
END IF


IF First THEN
IF Dynamic_position THEN
        P1= SubtractVectors(Ps,Pe)
        Ploc= AddVectors(Ps,P1)
        Stat=DeleteEntity(P1)
ELSE
        Input_method= CurrInputMethod
        stat= SetXyzInput(WsFreePoint)
        Stat=SetLastPoint(Ps)
        Ploc=XyzInput("DIM LOCATION",WsXyOnly)
        stat= SetXyzInput(Input_method)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Ploc) THEN Dim_loop
END IF
PlotOff
	E1=LinearDim(Dim_type,Ps,Pe,Ploc,Angle,"","")
PlotOn
	Stat=SetLastPoint(Pe)
	Stat=DeleteEntity(Pe)
	Stat=DeleteEntity(Ploc)
	IF NOT ValidGeometry(E1) THEN
                Stat=DeleteEntity(Ps)
                GOTO Startup
        END IF
        IF Dynamic_position THEN
                Which_end=2
                Vnum= LastPickView
                Stat= DynamicDimEdit(Vnum,E1,Which_end,"PICK DIM LOCATION",WsFalse)
		IF (ExitScript(Destination$)) THEN
               		 Stat= DeleteEntity(E1)
               		 GOTO Leave
        	END IF
        END IF
	Ploc= ComDimEndPoint(E1,Which_end)
	First= 0
ELSE
	E1=LinearDim(Dim_type,Ps,Pe,Ploc,Angle,"","")
	Stat=SetLastPoint(Pe)
	Stat=DeleteEntity(Pe)
	IF NOT ValidGeometry(E1) THEN
                Stat=DeleteEntity(Ps)
		Stat=DeleteEntity(Ploc)
                GOTO Startup
        END IF
END IF
ActivateUndo
Stat= AdvanceUndoNumber("running dim")
Stat= AddDimToUndo(WsUBCreateMode,E1)
GOTO Dim_loop

Leave:!
IF text_follows THEN
        stat= SetDefaults(WsTextFollows,1)
ELSE
        stat= SetDefaults(WsTextFollows,0)
END IF
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Ploc)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
