
! script name: draft.d/verticaldatum
! topic: construct vertical datum dimension

!A
!A NAME:
!A
!A 	Vertical Datum Dim
!A
!A DESCRIPTION:
!A
!A 	This script constructs a vertical datum dimension.  The starting
!A 	point is the reference point (or datum point) for all dimensions.
!A 	The vertical datum dimension is the difference between the two Y
!A 	coordinates.
!A
!B INSTRUCTIONS:
!B
!B 	DIM START ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		of the datum (start) point dimension.  This question
!B 		is only asked when the script is entered, it assumes
!B 		that all subsequent dimensions are referenced from it.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	DIM END ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		of the end point of the dimension.
!B
!B 	DIM LOCATION: PICK FREE POINT: Pick the location
!B 		for the vertical datum dimension to be printed.
!B 		The dimensions will all be located parallel to the Y axis.
!B 		This question is only asked once, all subsequent locations
!B 		are referenced from this one.
!B
!# see also - htdocs/help.d/dynamicdim.htm
!# see also - points.d/xyzinput.hlp

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

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

ActivateUndo
Start:!
Dynamic_position=1
Dim_type= WsVerticalDim
Dim_type$= "VERTICAL "

Angle= 90

Startup:First= 1
Ps=XyzInput(Dim_type$&"DIM START",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Dim_loop

SELECT Dim_type
CASE WsVerticalDim
	Space= 8*GetDefault(WsTextWidth)
CASE WsHorizDim
	Space= 2*GetDefault(WsTextHeight)
END SELECT
Stagger= 0

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
	SELECT Dim_type
	CASE WsVerticalDim
		Dim_type= WsHorizDim
		Dim_type$= "HORIZONTAL "
		Angle= 0
	CASE WsHorizDim
		Dim_type= WsVerticalDim
		Dim_type$= "VERTICAL "
		Angle= 90
	END SELECT
	Stat=SetLastPoint(Pe)
	Stat=DeleteEntity(Ps)
	GOTO Startup
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,0,"","")
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
	Xloc= XPointValue(Ploc)
	Yloc= YPointValue(Ploc)
	Stagger= Stagger+ Space
	Stat=DeleteEntity(Ploc)
ELSE
	PlotOff
	Pcen= PointXyz(Xloc,Yloc,0)
        Dim_line= PointAngle(Pcen,Angle)
        Base_line= PointAngle(Ps,Angle)
        P3= Intersect(Dim_line,Ps)
	D1= DistTwoPts(Ps,P3)
	S1=PtLeftRight(Base_line,P3)
	Dist=S1*(D1+ Stagger)

	L2=PtDistAngle(Ps,Dist,Angle)

        P1= Intersect(L2,Ps)
        P2= Intersect(L2,Pe)
        L1= LineTwoPoints(P1,P2)
        Ploc= Midpoint(L1)

        Stat=DeleteEntity(P1)
        Stat=DeleteEntity(P2)
        Stat=DeleteEntity(P3)
        Stat=DeleteEntity(Pcen)
        Stat=DeleteEntity(Dim_line)
        Stat=DeleteEntity(Base_line)
        Stat=DeleteEntity(L1)
        Stat=DeleteEntity(L2)
	PlotOn

	E1=LinearDim(Dim_type,Ps,Pe,Ploc,0,"","")

	Stat=SetLastPoint(Pe)
	Stat=DeleteEntity(Pe)
	Stat=DeleteEntity(Ploc)
	IF NOT ValidGeometry(E1) THEN
                Stat=DeleteEntity(Ps)
                GOTO Startup
        END IF
	Stagger= Stagger+ Space
END IF

ActivateUndo
Stat= AdvanceUndoNumber("vertical dim")
Stat= AddDimToUndo(WsUBCreateMode,E1)
GOTO Dim_loop

Leave:!

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
