
! script name: vpoints.d/contourmaxmin
! var_topic: approximate max min points on a contour.

!A
!A NAME:
!A
!A 	Approximate max min points on a contour. VARIATIONAL
!A
!A~ image location - images/maxminpoint.jpg
!A DESCRIPTION:
!A
!A      This script creates two points which are the max min limits
!A      of the contour. This is an exact value for lines,circles,ellipses
!A	it is an approximate value for cubic splines, bspline or nurb curves,
!A	as well as helii. The max min points are calculated relative to 
!A	the current workplane. The angle parameter can be changed to
!A	provide the max/min in an arbitrary direction.
!A
!A
!B INSTRUCTIONS:
!B
!B 	PICK  CONTOUR: Pick an element on the contour.
!B
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: contour max min ")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour$[256]
DIM Name1$[256]
DIM Name2$[256]

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

ActivateUndo
Pick_contour:!
Stat= SetInputFormat("n4","")
Contour=PickGroupEnt("PICK CONTOUR ")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidDependency(Contour)) THEN Pick_contour
Stat= EntityNameCheck(Contour,Contour$)

Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)

Stat= GenerateVarName(WsPointEnt,Name1$)
Stat= GenerateVarName(WsPointEnt,Name2$)
RecordFunctionOn
Stat= RecordDescr("POINTS: contour max min")
Stat= SetRecDelLastExec
V1= FreeParameter("Angle",Angle)
PlotOff
L1= ContourMaxMin(Contour$,V1)
PlotOn
P1= ParameterPt(L1,0.0)
P2= ParameterPt(L1,1.0)
Stat= NameEntity(P1,Name1$)
Stat= NameEntity(P2,Name2$)
Stat= DeleteEntity(L1,WsTrue)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Contour$)
Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
IF NOT ValidGeometry(P1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("max/min pts")
	Stat= AddItemToUndo(WsUBCreateMode,P1)
	Stat= AddItemToUndo(WsUBCreateMode,P2)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_contour


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

