
! script name: vcontours.d/orientcontour
! var_topic: orient a closed contour clockwise or counterclockwise.

!A
!A NAME:
!A
!A 	Orient Contour	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script automatically orients a closed contour in a clockwise
!A	or counterclockwise orientation. Should be applied in the
!A	workplane of the contour.
!A
!B INSTRUCTIONS:
!B
!B	ORIENTATION (1) CW or (2) CCW.
!B
!B 	PICK CONTOUR : Pick the contour.
!B
!C NOTE:
!C
!C	This script can be useful when building variational strategies
!C	to work on arbitrary closed contours. By making an orient record
!C	part of the strategy the strategy can then always work consistently
!C	no matter what the original direction of the contour. For example,
!C	the direction of the contour affects which side a cutter path
!c	is placed on.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: orient contour ")

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

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



ActivateUndo
Ploop:!
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$)
IF NOT IsEntVariational(Contour) THEN
   Stat=SetInputFormat("a1",",Y,N,")
   Stat= GetValue("NON-VDM ENTITY. LOAD NON-VDM? Yes or No ",Answer$)
   IF Answer$="N" THEN Pick_contour
   Destination$= "contours.d/orientcontour"
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF

Stat=SetInputFormat("a1",",1,2,")
Stat=GetValue("ORIENTATION ( 1 ) CW or ( 2 ) CCW ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "1"
	Direction= WsCW
CASE "2"
	Direction= WsCCW
END SELECT

ActivateUndo
Stat= AdvanceUndoNumber("orient contour")
Stat= AddGroupToUndo(WsUBModifyMode,Contour$,1,WsTrue)


RecordFunctionOn
IF Direction= WsCW THEN
	Stat= RecordDescr("CONTOUR: orient clockwise")
ELSE
	Stat= RecordDescr("CONTOUR: orient counterclockwise")
END IF
IF Direction= WsCW THEN
	Stat=OrientContour(Contour$,WsCW)
ELSE
	Stat=OrientContour(Contour$,WsCCW)
END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat=Highlight(Contour,WsPickPen,WsDirArrowOn)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Ploop

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