
! script name: vlines.d/normalline
! var_topic: construct line normal to an element

!A
!A NAME:
!A
!A 	Normal Line	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line normal to an element, at a point
!A 	on the element.  If the point selected is not on the element, the
!A 	closest point on the element is used.
!A
!A~ image location - images/normalline.jpg
!B INSTRUCTIONS:
!B
!B 	PICK TANGENT ELEMENT: Pick the entity that will be normal to the
!B 		line constructed.
!B
!B 	INPUT ABS X,Y,Z: Enter the X,Y,Z coordinates of the point, through
!B 		which the normal line will be constructed.  If the point is
!B 		not on the entity, then the closest point on the entity will
!B 		be used for the normal line construction.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: normal line ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point$[256]
DIM Element$[256]

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

DEG

ActivateUndo
Line_loop:!
stat= SetInputFormat("n4","")
E1=PickEntity("PICK NORMAL ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Line_loop
Stat= EntityNameCheck(E1,Element$)

Pick_point:!
E1=PickEntity("POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Line_loop
Stat= EntityNameCheck(E1,Point$)
T= LastPickPara
Pick_return= CurrPickReturn

Stat= GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("LINE: normal line at a point")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point$,T,WsGeomCenter)
END SELECT
L1=NormalLine(Element$,Pc,WsTRIMMED)
Stat= NameEntity(L1,Name$)
Stat=DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Point$)
Stat= PlotEntity(Element$)
Stat= PlotEntity(L1)
IF NOT ValidGeometry(L1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("normal line")
	Stat= AddItemToUndo(WsUBCreateMode,L1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Line_loop

Leave:!
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
