
! script name: draft.d/multhoriz
! topic: construct horizontal dimension

!A
!A NAME:
!A
!A 	Standard: Horizontal: Multiple
!A
!A DESCRIPTION:
!A
!A 	This script constructs multiple horizontal dimensions.
!A
!B INSTRUCTIONS:
!B
!B 	DIM START ABS X,Y,Z: Enter the X,Y,Z coordinate of the
!B 		start point of the dimension.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	DIM END ABS X,Y,Z: Enter the X,Y,Z coordinate of the
!B 		end point of the dimension.
!B
!B 	DIM LOCATION: PICK FREE POINT: Pick the location for
!B 		the dimension to be placed.
!B
!# see also - htdocs/help.d/dynamicdim.htm
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: multiple horizontal dim ")

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

ActivateUndo
Start:!
Dynamic_position=1
Dim_type= WsHorizDim
Dim_type$= "HORIZONTAL "

Startup: First= 1

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

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 "
	CASE WsHorizDim
		Dim_type= WsVerticalDim
		Dim_type$= "VERTICAL "
	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(Ps)
	Stat=DeleteEntity(Ploc)
	IF NOT ValidGeometry(E1) THEN 
		Stat=DeleteEntity(Pe)
		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)
	Xloc= XPointValue(Ploc)
	Yloc= YPointValue(Ploc)
	Stat=DeleteEntity(Ploc)
	First=0
	Ps= Pe
ELSE
	SELECT Dim_type
	CASE WsHorizDim
		Xs= XPointValue(Ps)
		Xe= XPointValue(Pe)
		X= (Xs+Xe)*0.5
		Ploc= PointXyz(X,Yloc,0)
	CASE WsVerticalDim
		Ys= YPointValue(Ps)
		Ye= YPointValue(Pe)
		Y= (Ys+Ye)*0.5
		Ploc= PointXyz(Xloc,Y,0)
	END SELECT

	E1=LinearDim(Dim_type,Ps,Pe,Ploc,0,"","")
	Stat=SetLastPoint(Pe)
	Stat=DeleteEntity(Ps)
	Stat=DeleteEntity(Ploc)
	IF NOT ValidGeometry(E1) THEN 
		Stat=DeleteEntity(Pe)
		GOTO Startup
	END IF
	Ps= Pe
END IF
ActivateUndo
Stat= AdvanceUndoNumber("horizontal 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
