
! script name: vnvars.d/vcoordinate
! var_topic: make coordinate variable

!A
!A NAME:
!A
!A 	Coordinate (make variable)
!A
!A DESCRIPTION:
!A
!A 	This script makes a variable dependent on an X,Y, or Z coordinate.
!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 	WHICH COORDINATE   X, Y, Z: Enter the coordinate which is to be used
!B 		 for the variable.
!B
!B 	PICK POINT: Pick the point that defines the coordinate.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: make coordinate variable")

DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Point$[256]
DIM Coord$[256]
DIM Destination$[256]
DEG

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

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

Which_coordinate:!
stat= SetInputFormat("a1",",X,Y,Z,")
Stat=GetValue("WHICH COORDINATE   X, Y, Z ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Coord$= Answer$


Pick_loop:stat= SetInputFormat("n4","")
E1=PickEntity("PICK POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Line_loop
Stat= EntityNameCheck(E1,Point$)
Para_value= LastPickPara
Pick_return= CurrPickReturn

SELECT Coord$
CASE "X"
	RecordFunctionOn
	Stat= RecordDescr("VARIABLE: X coordinate")
	SELECT Pick_return
	CASE WsGeometryEnd
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeometryEnd)
	CASE WsGeometryMid
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeometryMid)
	CASE WsGeomCenter
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeomCenter)
	END SELECT
	V1=NumericVariable(Name$,WsVariationVars,XPointValue(Ps))
	stat= SetVariableDescr(V1,"X coordinate:")
	Stat= DeleteEntity(Ps)
        Stat= DeleteEntity(Pe)
	RecordFunctionOff
	CloseVarRecord
CASE "Y"
	RecordFunctionOn
	Stat= RecordDescr("VARIABLE: Y coordinate")
	SELECT Pick_return
	CASE WsGeometryEnd
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeometryEnd)
	CASE WsGeometryMid
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeometryMid)
	CASE WsGeomCenter
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeomCenter)
	END SELECT
	V1=NumericVariable(Name$,WsVariationVars,YPointValue(Ps))
	stat= SetVariableDescr(V1,"Y coordinate:")
	Stat= DeleteEntity(Ps)
        Stat= DeleteEntity(Pe)
	RecordFunctionOff
	CloseVarRecord
CASE "Z"
	RecordFunctionOn
	Stat= RecordDescr("VARIABLE: Z coordinate")
	SELECT Pick_return
	CASE WsGeometryEnd
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeometryEnd)
	CASE WsGeometryMid
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeometryMid)
	CASE WsGeomCenter
       		 Ps= ParameterReturnPt(Point$,Para_value,WsGeomCenter)
	END SELECT
	V1=NumericVariable(Name$,WsVariationVars,ZPointValue(Ps))
	stat= SetVariableDescr(V1,"Z coordinate:")
	Stat= DeleteEntity(Ps)
        Stat= DeleteEntity(Pe)
	RecordFunctionOff
	CloseVarRecord
END SELECT

GOTO Name_loop



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