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

!A
!A NAME:
!A
!A 	3D Modify: Add Start Moves Grp	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will add start moves to a 3D cutterpath group.
!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 GROUP TO BE MODIFIED: Pick the cutterpath group to be
!B 		modified.
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Hole_group$[256]
DIM Contour$[256]
DIM Cpath_group$[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
Stat=SetInputFormat("n4","")
Cpath_grp=PickGroupEnt("PICK CUTTERPATH GROUP TO BE MODIFIED",0)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Cpath_grp) THEN Pick_loop
Stat= EntityNameCheck(Cpath_grp,Cpath_group$)


RecordFunctionOn
Stat= RecordDescr("MODIFY CUTTERPATH GROUP: Add start moves")
Stat= NullReference(Cpath_group$)
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=CPathGrpStrtMoves(Hold_group,Cpath_group$,V1)
Stat=DeleteEntity(Hold_group)
IF Single_point THEN
        Stat=DeleteGroup(Hole_group,WsTrue)
END IF
RecordFunctionOff
CloseVarRecord

Stat=PlotEntity(Cpath_grp)
GOTO Pick_holes

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