
! script name: vlines.d/perpendicular
! var_topic: construct perpendicular line through point

!A
!A NAME:
!A
!A 	Perpendicular Line	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line through a point perpendicular to a line.
!A
!A~ image location - images/perpendicular.jpg
!B INSTRUCTIONS:
!B
!B 	PICK PERPENDICULAR LINE: Pick the line that will be used to construct
!B 		a line perpendicular to it.
!B
!B 	INPUT ABS X,Y: Enter the X,Y coordinates of the point through which
!B 		the perpendicular line will be constructed.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

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

DIM Destination$[256]
DIM Answer$[256]
DIM Lname$[256]
DIM Center$[256]
DIM Name$[256]

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


ActivateUndo
Line_loop:!
stat= SetInputFormat("n4","")
E1=PickSpecificEnt("PICK PERPENDICULAR LINE",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Line_loop
Stat= EntityNameCheck(E1,Lname$)

Pick_point:Stat=SetInputFormat("n4","")
P1=PickEntity("POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(P1) THEN Pick_point
Stat= EntityNameCheck(P1,Center$)
T= LastPickPara
Pick_return= CurrPickReturn

Stat= GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("LINE: Perpendicular")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
L1=Perpendicular(Lname$,Pc,WsUNTRIMMED)
Stat= NameEntity(L1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Center$)
Stat= PlotEntity(Lname$)
Stat= PlotEntity(L1)

ActivateUndo
Stat= AdvanceUndoNumber("perpendicular line")
Stat= AddItemToUndo(WsUBCreateMode,L1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Line_loop

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

