
! script name: 3dcpaths.d/chcpathstrt
! 3dtopic: change cutterpath start points

!A
!A NAME:
!A
!A 	3D Modify: Change Start Point
!A
!A DESCRIPTION:
!A
!A 	Change 3D Cutterpath Start Points.
!A
!B INSTRUCTIONS:
!B
!B 	APPROXIMATE START POINT: Input or pick a point to determine the path
!B 		start points.  Each closed path will start on the point closest
!B 		to this point.  If the path is open, the start point is ignored.
!B
!B 	PICK CURVES TO BE MODIFIED, Undo, Clear, Modify: Pick the cutterpath
!B 		curves to be modified.
!B
!B 		U - Undo works in a recursive manner.
!B 		C - Clear means that the script will start over.
!B 		M - Modify finalizes the process.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: add cutterpath curve start moves")

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:!

Start_point:!
Stat=SetInputFormat("n4","")
Start_pt=XyzInput("APPROXIMATE START POINT",WsXyzInput)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Start_pt) THEN Start_point

Pick_path:!
Ncuts=0

Ploop:!
Stat=SetInputFormat("a1",",M,U,C,")
E1=PickEntity("PICK CURVES TO BE MODIFIED, 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=ChangeCPathStart(Start_pt,Cutterpath,Cuts,Ncuts)
Stat=PlotEntity(Cutterpath)
Stat=DeleteEntity(Start_pt)

GOTO Start

Leave:!
Stat=DeleteEntity(Start_pt)
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
