
! script name: v3dcpaths.d/cpthzmovesgrp
! var_topic: add z approach and retract to a group of 3d cutterpaths.

!A
!A NAME:
!A
!A 	3D Modify: Z Approach and Retract   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script inserts the Z approach and retract moves into a
!A	3D cutterpath.
!A
!B INSTRUCTIONS:
!B
!B	RETRACT LEVEL: Input the z retract level.
!B
!B	Z FEED IN DISTANCE: The amount of feed in the z direction.  
!B	
!B	Z FEED OUT DISTANCE: The amount of feed out in the z direction.  
!B
!B 	PICK CUTTERPATH GROUP: Pick the group of cutterpaths. 
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Instock_var$[256]
DIM Outstock_var$[256]
DIM Rlevel_var$[256]
DIM Group$[256]


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

DeActivateUndo
Stat=SetInputFormat("n4","")
Rlevel=GetValue("RETRACT LEVEL")
IF (ExitScript(Destination$)) THEN Leave
No_rlevel_var= LastVariableInput(Rlevel_var$)

Stat=SetInputFormat("n4","")
Instock=GetValue("Z FEED IN DISTANCE")
IF (ExitScript(Destination$)) THEN Leave
No_instock_var= LastVariableInput(Instock_var$)

Stat=SetInputFormat("n4","")
Outstock=GetValue("Z FEED OUT DISTANCE")
IF (ExitScript(Destination$)) THEN Leave
No_outstock_var= LastVariableInput(Outstock_var$)

Pick_loop:!
Stat=SetInputFormat("n4","")
Group=PickGroupEnt("PICK GROUP OF CUTTERPATHS",0)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Group) THEN Pick_loop
Stat= EntityNameCheck(Group,Group$)


RecordFunctionOn
Stat= RecordDescr("MODIFY CUTTERPATH: Insert z moves ")
IF No_rlevel_var THEN
        V1= FreeParameter("Z Retract Level",Rlevel)
ELSE
        V1= FreeParameter("Z Retract Level",Rlevel_var$)
END IF
IF No_instock_var THEN
        V2= FreeParameter("Z Feed in dist",Instock)
ELSE
        V2= FreeParameter("Z Feed in dist",Instock_var$)
END IF
IF No_outstock_var THEN
        V3= FreeParameter("Z Feed out dist",Outstock)
ELSE
        V3= FreeParameter("Z Feed out dist",Outstock_var$)
END IF
V4= FreeParameter("Feed factor",0.6)
V5= FreeParameter("Method",1)
Stat= AddCpathZRetracts(Group$,V1,V2,V3,V4,V5)
RecordFunctionOff
CloseVarRecord

Stat=PlotEntity(Group)
GOTO Pick_loop

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