
! script name: 3dcpaths.d/reversecut
! 3dtopic: reverse cpath cut

!A
!A NAME:
!A
!A 	3D Modify: Reverse Cut
!A
!A DESCRIPTION:
!A
!A 	This script will reverse the cutting direction on a cut in a cutterpath.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CURVES TO BE REVERSED, Undo, Clear, Modify: Pick the cutterpath
!B 		curves to be reversed.
!B
!B 		U - Undo works in a recursive manner.
!B 		C - Clear means that the script will start over without
!B 		    reversing the curves, unless Modify has already been
!B 		    used.
!B 		M - Modify finalizes the reverse process for the selected
!B 		    curves.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: reverse cutterpath cut")

DIM Destination$[256]
DIM Answer$[256]
REAL Cuts(0:400)

DeActivateUndo
Highlight_color=2

Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1

Start:!

Pick_path:!
Ncuts=0

Ploop:!
Stat=SetInputFormat("a1",",M,U,C,")
E1=PickEntity("PICK CURVES TO BE REVERSED, Undo, Clear, Modify ", Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
    CASE "M"
	GOTO Modify_cpaths
    CASE "U"
	Ncuts=Ncuts-1
	IF Ncuts<0 THEN Ncuts=0
	IF ValidGeometry(Cutterpath) THEN
		Pen1=GetColor(Cutterpath)
		Stat=PlotEntity(Cutterpath,pen1)
		Stat=HighlightCpath(Cutterpath,Cuts,Ncuts,Highlight_color)
	END IF
	GOTO Ploop
    CASE "C"
	IF ValidGeometry(Cutterpath) THEN
		Pen1=GetColor(Cutterpath)
		Stat=PlotEntity(Cutterpath,pen1)
	END IF
	GOTO Start
END SELECT
IF NOT ValidGeometry(E1) THEN Ploop

Etype=EntityType(E1)
IF Etype=WsCPathFileEnt THEN
	IF Ncuts=0 THEN Cutterpath=E1
	T=LastPickPara
	Path=INT(T)
	Cuts(Ncuts)=Path
	Ncuts=Ncuts+1
	Stat=HighlightCpath(Cutterpath,Cuts,Ncuts,Highlight_color)
END IF
GOTO Ploop

Modify_cpaths:!

Stat=ReverseCPathCuts(Cutterpath,Cuts,Ncuts)
Stat=PlotEntity(Cutterpath)

GOTO Start

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