
! script name: vcontours.d/addhelicalzramp
! var_topic: add a helical z ramp to a contour.

!A
!A NAME:
!A
!A 	 Add Helical Z Ramp To A Contour		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script adds a helical ramp to a contour. 
!A      The original contour is deleted.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick an element on the contour.
!B
!B 	DEPTH: Give amount of the ramp in z.
!B
!B 	RAMP ANGLE: Give the angle of the helical ramp.
!B
!C NOTES:
!C		Method= 1 Uses depth of cut to calculate ramp angle.
!C		Method= 2 Uses ramp angle to calculate depth of cut.
!C
!C		This function does not do any check for cutter interference.
!C		It is assumed that it is to be used in the center of an area
!C		to be pocketed.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: add helical z ramp ")

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Angle_var$[256]
DIM Ramp_var$[256]
DIM Depth_var$[256]
DIM Depthcut_var$[256]
DIM Dia_var$[256]
DIM Name$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

Method=2
Ramp_angle= 5

ActivateUndo
Pick_contour: !
Contour=PickGroupEnt("PICK CONTOUR ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat=EntityNameCheck(Contour,Contour$)
IF NOT IsEntVariational(Contour) THEN
   Stat=SetInputFormat("a99","")
   Stat= GetValue("NON-VDM ENTITY. CANNOT USE ON NON VDM ENTITY ",Answer$)
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF

Helix_dia:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Diar/2)
Helix_dia=InputRadius("DIAMETER OF HELIX",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
No_dia_var= LastVariableInput(Dia_var$)
Diar= Helix_dia


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

Depth_cut: IF Method=1 THEN
	Depth_cut=NamedVarVal("depth of cut",WsSystemVars,0.0)
	Stat=SetEqualsValue(Depth_cut)
	Stat=SetInputFormat("n4=","")
	Depth_cut=GetValue("DEPTH OF CUT",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	Depth_cut=ABS(Depth_cut)
	Vdepth=CreateVariable("depth of cut",WsSystemVars,Depth_cut)
	No_depthcut_var= LastVariableInput(Depthcut_var$)
	Stat=SetCurrentColor(Pen_color)
ELSE
 	Depth_cut= Depth
 	No_depthcut_var=1
END IF
Ramp_angle: IF Method=2 THEN
	Stat=SetInputFormat("n4=","")
	Stat=SetEqualsValue(Ramp_angle)
	Ramp_angle=GetValue("RAMP ANGLE")
	IF (ExitScript(Destination$)) THEN Leave
	No_ramp_var= LastVariableInput(Ramp_var$)
ELSE
	Ramp_angle= 5
	No_ramp_var=1
END IF

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Start_angle)
Start_angle=GetValue("START ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)


Stat=GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Add Helical Z Ramp")
IF No_dia_var THEN
        V1= FreeParameter("Helix diameter",Helix_dia)
ELSE
        V1= FreeParameter("Helix diameter",Dia_var$)
END IF
IF No_depth_var THEN
	V2= FreeParameter("Z Ramp Depth",Depth)
ELSE
	V2= FreeParameter("Z Ramp Depth",Depth_var$)
END IF
IF No_depthcut_var THEN
        V3= FreeParameter("Depth of cut",Depth_cut)
ELSE
        V3= FreeParameter("Depth of cut",Depthcut_var$)
END IF
IF No_ramp_var THEN
        V4= FreeParameter("Ramp angle",Ramp_angle)
ELSE
        V4= FreeParameter("Ramp angle",Ramp_var$)
END IF
IF No_angle_var THEN
	V5= FreeParameter("Start angle",Start_angle)
ELSE
	V5= FreeParameter("Start angle",Angle_var$)
END IF
V6= FreeParameter("Feed factor",0.6)
V7= FreeParameter("Direction",WsCCW)
V8= FreeParameter("Method",Method)
C1=AddHelicalZRamp(Contour$,V1,V2,V4,V3,V5,V6,V7,V8)
RecordFunctionOff
IF ValidGeometry(C1) THEN
	RecordFunctionOn
	Stat=AutoNameGroup(C1,Name$)
	Tool= GetAssocTool(Contour$)

	ActivateUndo
	Stat= AdvanceUndoNumber("add helical z ramp")
	Stat= AddGroupToUndo(WsUBDeleteMode,Contour$,1,WsTrue)

	Stat=DeleteGroup(Contour$,WsTrue)
	Stat=AssociateTool(C1,Tool)
	RecordFunctionOff
	Stat= PlotEntity(C1)
END IF
RecordFunctionOn
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord


Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsTrue)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Pick_contour

Leave:!
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

