
! script name: v3dcpaths.d/cpthstrtmvs
! var_topic: add cutterpath start moves

!A
!A NAME:
!A
!A 	3D Modify: Add Start Moves VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will add start moves to a 3D cutterpath.
!A
!B INSTRUCTIONS:
!B
!B 	PICK GROUP OF STARTHOLES, Proceed: Pick the group of holes or points
!B 		to be used as startholes.
!B
!B 	PICK STOCK BOUNDARY, Proceed: Pick the stock boundary.
!B
!B 	PICK CUTTERPATH TO BE MODIFIED: Pick the cutterpath to be
!B 		modified.
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Hole_group$[256]
DIM Contour$[256]
DIM Cpath_name$[256]
DIM Point$[256]


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


DeActivateUndo

Pick_holes:!
Hole_group$=""
Stat=SetInputFormat("a1",",P,N,")
Startholes=PickGroupEnt("PICK GROUP OF STARTHOLES, Point, None ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN Stock_boundary
IF Answer$="P" THEN 
Start_point: Stat=SetInputFormat("n4","")
	E1=PickEntity("PICK STARTING POINT")
	IF ExitScript(Destination$) THEN Leave
	IF NOT ValidDependency(E1) THEN Start_point
	Stat= EntityNameCheck(E1,Point$)
	Pick_para= LastPickPara
	Pick_return= CurrPickReturn
	Single_point=1
	Contour$=""
	Hole_group$=""
	GOTO Pick_loop
END IF
IF NOT ValidDependency(Startholes) THEN Pick_holes
Stat= EntityNameCheck(Startholes,Hole_group$)
Single_point=0

Stock_boundary:!
Contour$=""
Stat=SetInputFormat("a1",",P,")
Stock_bdy=PickGroupEnt("PICK STOCK BOUNDARY, Proceed ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN Pick_loop
IF NOT ValidDependency(Stock_bdy) THEN Stock_boundary
Stat= EntityNameCheck(Stock_bdy,Contour$)

Pick_loop:!
IF (Single_point=0)AND(NOT LEN(Contour$))AND (NOT LEN(Hole_group$)) THEN Pick_holes
Pick_cpath:!
Stat=SetInputFormat("n4","")
Cpath=PickSpecificEnt("PICK CUTTERPATH",WsCPathFileEnt)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Cpath) THEN Pick_cpath
Stat= EntityNameCheck(Cpath,Cpath_name$)


RecordFunctionOn
Stat= RecordDescr("MODIFY CUTTERPATH: Add start moves")
Stat= NullReference(Cpath_name$)
Hold_group=CreateGroup("")
IF Single_point THEN
	Hole_group=CreateGroup("")
	SELECT Pick_return
	CASE WsGeometryEnd
       		 Ps= ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
	CASE WsGeometryMid
       		 Ps= ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
	CASE WsGeomCenter
       		 Ps= ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
	END SELECT
	Stat= AddToGroup(Hole_group,Ps)
	Stat=CombineGroups(Hold_group,Hole_group)
	V1= FreeParameter("Check z",0)
ELSE
	IF LEN(Hole_group$) THEN
		Stat=CombineGroups(Hold_group,Hole_group$)
	END IF
	IF LEN(Contour$) THEN
		Stat=AddToGroup(Hold_group,Contour$)
	END IF
	V1= FreeParameter("Check z",1)
END IF
Stat=CPathStartMoves(Hold_group,Cpath_name$,V1)
Stat=DeleteEntity(Hold_group)
IF Single_point THEN
	Stat=DeleteGroup(Hole_group,WsTrue)
END IF
RecordFunctionOff
CloseVarRecord

Stat=PlotEntity(Cpath)
GOTO Pick_holes

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