
! script name: vdraft.d/verticaldim
! var_topic: construct linear vertical dimension

!A
!A NAME:
!A
!A 	Linear Vertical Dim
!A
!A DESCRIPTION:
!A
!A 	This script constructs a linear vertical dimension.  The linear
!A 	vertical dimension is the difference between two Y coordinates.
!A
!A~ image location - images/vertdim.gif
!A
!B INSTRUCTIONS:
!B 
!B 	STARTING POINT: Pick the start point of the dimension.
!B
!B 	ENDING POINT: Pick the end point of the dimension.
!B
!B 	DIM LOCATION: PICK FREE POINT: Pick the location
!B 		for the linear vertical dimension to be placed.
!B
!# see also - htdocs/help.d/dynamicdim.htm

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

DIM Answer$[256]
DIM Destination$[256]
DIM Dim_type$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Point3$[256]
DIM Name$[256]
DIM Textflags$[20]
DEG

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

ActivateUndo
Dynamic_position=1
Dim_type= WsVerticalDim
Dim_type$= "VERTICAL "

Dim_loop:!
E1=PickEntity("STARTING POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Dim_loop
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(E1,Point1$)
Ps= ParameterReturnPt(E1,T1,Pick_return1)

Stat=SetLastPoint(Ps)
E2=PickEntity("ENDING POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E2) THEN Dim_loop
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(E2,Point2$)
Pe= ParameterReturnPt(E2,T2,Pick_return2)
Stat=SetLastPoint(Pe)

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=DeleteEntity(Ps)
	Stat=DeleteEntity(Pe)
	GOTO Dim_loop
END IF

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
	Last_pick_ent= LastPickEnt
        Pick_para3= LastPickPara
        Pick_return3= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Point_reference=0
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Point3$)
                 Point_reference=1
        END IF
END IF

IF Dynamic_position THEN
	PlotOff
	E1=LinearDim(Dim_type,Ps,Pe,Ploc,0,"","")
	PlotOn
	Stat=SetLastPoint(Pe)
	Stat=MakeInvisible(Ps)
	Stat=MakeInvisible(Pe)
	Stat=DeleteEntity(Ploc)
	IF NOT ValidGeometry(E1) THEN Dim_loop
        Which_end=2
        Vnum= LastPickView
        Stat= DynamicDimEdit(Vnum,E1,Which_end,"PICK DIM LOCATION",WsFalse)
        IF (ExitScript(Destination$)) THEN 
		Stat= DeleteEntity(E1)
		Stat=DeleteEntity(Ps)
		Stat=DeleteEntity(Pe)
		GOTO Leave
	END IF
	Last_pick_ent= LastPickEnt
        Pick_para3= LastPickPara
        Pick_return3= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Point_reference=0
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Point3$)
        	 Point_reference=1
        END IF
	PlotOff
	Ploc= ParameterPt(E1,0.5)
 	Stat= DimTextFlagStr(E1,Textflags$)
        Stat= DeleteEntity(E1)
        PlotOn
ELSE
        Textflags$=""
END IF


P1= SubtractVectors(Ploc,Ps)
Stat= XYZPointValues(P1,X1,Y1,Z1)
Stat=DeleteEntityList(P1,Ploc,Ps,Pe)

Stat= GenerateVarName("D",Name$)
RecordFunctionOn
IF Dim_type= WsHorizDim THEN
	Stat= RecordDescr("DIM: Horizontal dimension")
ELSE
	Stat= RecordDescr("DIM: Vertical dimension")
END IF
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,T2,WsGeomCenter)
END SELECT
IF Point_reference THEN
        SELECT Pick_return3
        CASE WsGeometryEnd
                 Ploc= ParameterReturnPt(Point3$,Pick_para3,WsGeometryEnd)
        CASE WsGeometryMid
                 Ploc= ParameterReturnPt(Point3$,Pick_para3,WsGeometryMid)
        CASE WsGeomCenter
                 Ploc= ParameterReturnPt(Point3$,Pick_para3,WsGeomCenter)
        END SELECT
ELSE
        V1= FreeParameter("Xloc",X1)
        V2= FreeParameter("Yloc",Y1)
        Ploc= PtIncrXyz(Ps,V1,V2,Z1)
END IF
V4= StringConstant(Textflags$)
IF Dim_type= WsHorizDim THEN
	E1=LinearDim(WsHorizDim,Ps,Pe,Ploc,0,"","",V4)
ELSE
	E1=LinearDim(WsVerticalDim,Ps,Pe,Ploc,0,"","",V4)
END IF
Stat= NameEntity(E1,Name$)
Stat=DeleteEntityList(Ps,Pe,Ploc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(E1)
Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Stat= PlotEntity(Point3$)
IF NOT ValidGeometry(E1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("vertical dim")
	Stat= AddDimToUndo(WsUBCreateMode,E1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Dim_loop

Leave:!
Stat=DeleteEntityList(Ps,Pe,Ploc)
RecordFunctionOff
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
        IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END


