
! script name: vnvars.d/vdistptpt
! var_topic: make variable for dist between two points

!A
!A NAME:
!A
!A 	Distance Two Points ( make variable )
!A
!A DESCRIPTION:
!A
!A 	This script makes a variable dependent on the distance between 
!A 	two points.
!A
!B INSTRUCTIONS:
!B
!B 	VARIABLE NAME: Enter the variable name.
!B
!B 	INVALID VARIABLE NAME: Name input was invalid choose new variable.
!B
!B 	STARTING POINT: Pick the starting location point.
!B
!B 	ENDING POINT: Pick the ending location point.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: make dist two points variable")

DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Destination$[256]
DIM Point1$[256]
DIM Point2$[256]
DEG

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

DeActivateUndo
Name_loop:!
stat= SetInputFormat("a99","")
Stat=GetValue("VARIABLE NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Name$= Answer$
IF NOT ValidVariableName(Name$)	THEN
	stat= SetInputFormat("a99","")
	Stat=GetValue("INVALID VARIABLE NAME, Proceed",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	GOTO Name_loop
END IF



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

Pick_end:Stat=SetLastPoint(Ps)
E2=PickEntity("ENDING POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E2) THEN Pick_end
IF NOT ValidDependency(E2) THEN Pick_end
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= ReadEntityName(E2,Point2$)
IF NOT LEN(Point2$) THEN
        Stat= AutoNameEntity(E2)
        Stat= ReadEntityName(E2,Point2$)
END IF
Pe= ParameterReturnPt(E2,T2,Pick_return2)
Stat=SetLastPoint(Pe)

Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)


RecordFunctionOn
Stat= RecordDescr("VARIABLE: Distance two points")
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
L1=LineTwoPoints(Ps,Pe)
V1=NumericVariable(Name$,WsVariationVars,EntityLength(L1))
stat= SetVariableDescr(V1,"Distance:")
Stat= DeleteEntity(L1)
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)
RecordFunctionOff
CloseVarRecord

GOTO Name_loop



Leave:!
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
