
! script name: v3dcpaths.d/cpthzramp
! var_topic: zramp leadin  into a cutterpath

!A
!A NAME:
!A
!A 	3D Modify: Insert Z Ramp Leadin  Cut   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script inserts a z ramp move into a 3D cutterpath.
!A	The ramp move starts at a distance along the contour
!A	determined by the ramp depth and the ramp angle. The ramp move is
!A	constructed in such a way as it follows the shape of the cutterpath
!A	in XY and it ramps down in z to the start of the cutterpath.
!A	The ramp move will always be milling reverse to the direction of
!A	the cutterpath. If the cutterpath is not long enough it will
!A	reach depth by milling back and forth along the path until it
!A	reached depth.
!A
!B INSTRUCTIONS:
!B
!B	RAMP DEPTH: Input the z length of the ramp move.
!B
!B	RAMP ANGLE: Input the angle which the cutter is feeding down along
!B			the ramp.
!B
!B 	PICK CUTTERPATH: Pick the cutterpath. 
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Angle_var$[256]
DIM Depth_var$[256]
DIM Cpath_name$[256]


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

DeActivateUndo
Stat=SetInputFormat("n4","")
Depth=GetValue("RAMP DEPTH")
IF (ExitScript(Destination$)) THEN Leave
No_depth_var= LastVariableInput(Depth_var$)

Stat=SetInputFormat("n4","")
Ramp_angle=GetValue("RAMP ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)


Pick_loop:!
Stat=SetInputFormat("n4","")
Cpath=PickEntity("PICK CUTTERPATH")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Cpath) THEN Pick_loop
Stat= EntityNameCheck(Cpath,Cpath_name$)
Etype=EntityType(Cpath)
IF Etype<>WsCPathFileEnt THEN Pick_loop


RecordFunctionOn
Stat= RecordDescr("MODIFY CUTTERPATH: Insert z ramp  leadin ")
IF No_depth_var THEN
        V1= FreeParameter("Z Ramp Depth",Depth)
ELSE
        V1= FreeParameter("Z Ramp Depth",Depth_var$)
END IF
IF No_angle_var THEN
        V2= FreeParameter("Ramp angle",Ramp_angle)
ELSE
        V2= FreeParameter("Ramp angle",Angle_var$)
END IF
V3= FreeParameter("Feed factor",0.6)
V4= FreeParameter("Method",2)
Stat= AddCpathZRamp(Cpath_name$,V1,V2,V3,V4)
RecordFunctionOff
CloseVarRecord

Stat=PlotEntity(Cpath)
GOTO Pick_loop

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