
! script name: voffset.d/facemillrect
! var_topic: face mill the rectangular area determined by two points

!A
!A NAME:
!A
!A 	Mill 2 Pt Area		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A      This script constructs a milling path for face milling a boxed
!A	area determined by two points.  This creates a single contour
!A	with rapid and feed movements.  The two corners would define the
!A	area to be milled.  It overlaps of the edges of the rectangle on
!A	the sides and the ends.  This script can also cut a single line,
!A	provided it is parallel to X or Y, by picking the two end points
!A	as the rectangle corners. The two corners of the rectangle should
!A	represent where the stock starts and the stock ends.  If you wish
!A	to pick the two corners of the finished part, then you must 
!A	increase the values for overrun and overhang by the stock amount.
!A
!A~ image location - images/facemillrect.jpg
!B INSTRUCTIONS:
!B
!B	The questions possibly asked.  Also in () is the Free Parameter
!B	associated with the function.  If a question is not asked the default
!B	is also given.
!B
!B	TOOL: Choose the tool.  It must be previously read into the file.
!B
!B	CUT METHOD: sets both (Axis. 0)Either 1)Y 2)X )  and,
!B		(Cut type. 0)Zigzag 1)ZZr 2)One dir )
!B	There are 9 possible configurations. 
!B
!B		 0- Do a "zig-zag" like cut along the longest axis.
!B		 1- Do a "zig-zag" like cut along the Y-axis.
!B		 2- Do a "zig-zag" like cut along the X-axis.
!B		10- Do a "zig-zag" like cut along the longest axis. Make
!B				the cross moves rapids.
!B		11- Do a "zig-zag" like cut along the Y-axis. Make
!B				the cross moves rapids.
!B		12- Do a "zig-zag" like cut along the X-axis. Make
!B				the cross moves rapids.
!B		20- Cut in one direction along the longest axis.
!B		21- Cut in one direction along the Y-axis.
!B		22- Cut in one direction along the X-axis.
!B
!B 	The numbers are grouped so that the first digit is the type and
!B	the second digit picks the axis. (1= Yaxis   2= Uni-dir. so 21
!B	is Uni-diectional along the Y axis.)
!B
!B	AXIS TO CUT ALONG. X OR Y: (Axis. 0)Either 1)Y 2)X )
!B		Alternative question to pick the method.  Pick X
!B 		or Y as the axis.  The either switch will choose
!B 		the longest axis.
!B
!B	Uni- OR Bi- DIRECTIONAL CUTS: (Cut type. 0)Zigzag
!B 		1)ZZr 2)One dir )
!B		Alternate question in conjunction with previous.
!B 		Pick the type of cut to use.
!B
!B	CUTTER OVERLAP BETWEEN CUTS: (Overlap). The
!B 		mimimum distance that the cutters must overlap
!B 		between passes.
!B
!B	DISTANCE TO RUN PAST EDGE: (Overrun).
!B 		Default= Overlap.  The distance the center of
!B 		the cutter goes past the edge of the rectangle
!B 		at the end of a cut.  This value is added
!B		to the leadin and leadout.
!B
!B	CUTTER OVERHANG ALONG AN EDGE: (Overhang)
!B 		Default= Overlap.  This describes the minimum
!B 		amount that the cutter must "hang over" the edge
!B 		of the rectangle.  This ensures that the cutter
!B 		cuts past the edge and not just "up to it".
!B
!B	LEADIN DISTANCE: (Leadin distance)
!B 		Default= Tool radius.  Distance to start away
!B 		from an edge.  This value is supplemented by the
!B 		Overrun. Additional leadin clearance can be defined below.
!B
!B	LEADOUT DISTANCE: (Leadout distance)
!B 		Default= Tool radius.  Distance to finish off the edge.
!B 		This value is supplemented by the Overrun. Additional
!B 		leadout clearance can be defined below.
!B
!B	ADDITIONAL LEADIN CLEARANCE: (Additional
!B 		leadin clearance) Default= 0.0.  This value gets
!B 		added to the leadin.  This is done so that the
!B 		leadin defaults to the Tool radius.
!B
!B	ADDITIONAL LEADOUT CLEARANCE: (Additional
!B 		leadout clearance) Default= 0.0.  This value gets
!B 		added to the leadout. This is done so that the
!B 		leadout defaults to the Tool radius.
!B
!B	WHERE SHOULD the INTERMEDIATE CUT EDGES STOP:
!B		(Extended to 0)Leadout or 1)Overrun) Default= 1
!B		Defines the how the ends of the cuts will be defined.
!B		0= The cutter will go out to "leadout+clearance+overrun"
!B			past the edge before turning to the next pass.
!B		1= The cutter will go out to "overrun" past the edge
!B			before turning to the next pass.
!B		2= The edges only go as far as they have to go. All values
!B		   for overrun, overlap, and overhang are maintained.
!B		If the method of cut chosen is the zigzag with rapids,
!B		then this value is forced to be 0.
!B
!B	Z CUT METHOD. ( 0 )EQUAL CUTS OR ( 1 )FULL CUT: (Z step
!B 		method) Default= 0.  Defines how the depths are spaced.
!B		0= All cuts are even and no greater than the depth of cut.
!B		1= Each cut is "Z step" apart.  Except the last cut which
!B			is the remainder of the depth less than "Z step"
!B
!B	Z LEVEL OF FIRST CUT: (Z start). Define the Z level
!B 		where the first cut is. This is usually "depth of cut"
!B 		below the top of the part.  This is a (+) value above
!B 		0 and a (-) value below 0.
!B
!B	Z LEVEL OF LAST CUT: (Z end level).  Where the last
!B 		Z cut is to be taken. Usually at 0 or a finish
!B 		allowance above 0.  Same (+) and (-) rules apply
!B 		as above. (+)up and (-)down.  For a single pass,
!B 		define the first and last cut at the same level.
!B 		The "DEPTH OF CUT" will not be asked if the start
!B 		and end levels are the same.
!B
!B	DEPTH OF CUT: (Z step).  The distance between
!B 		each level.  Allows for multiple levels of cut.
!B
!B	Z RETRACT LEVEL. ( 0 )INCR. or ( 1 )CONSTANT:
!B		(Z retract is  0)Incr. or  1)Constant) Default= 1.
!B		This defines how to pull up between cuts.
!B 		The distance is described by "Z retract".
!B		0= An incremental distance in Z from the end point.
!B		1= A constant Z position to always pull up to.
!B	(When a U shape cut is made. A setting of 0 and a "Z retract"= 0
!B		will rapid straight back to the start without pullup).
!B
!B	Z RETRACT LEVEL BETWEEN CUTS: (Z retract) If Z
!B 		retract level is constant this defines the level
!B 		to retract up to. Either this question or the next
!B 		is asked. They both define the "Z retract" Free Parameter.
!B
!B	Z PULLUP DISTANCE BETWEEN CUTS: (Z retract) If Z
!B 		retract level is incremental this defines the distance
!B 		to go up from the last point. Either this question or
!B 		the previous is asked. They both define the "Z retract"
!B 		Free Parameter.
!B
!B	STARTING CORNER: Pick the starting corner.
!B 		This will be the corner where the path starts.
!B
!B	PICK ENDING CORNER: Choose the opposite corner.
!B
!C ADDITIONAL FREE PARAMETERS:
!C
!C 	(Evenly. 0)Loaded or 1)Spaced): Default= 1.  This defines whether
!C 	each cut is evenly spaced out or evenly distributes the
!C 	load so that each cut takes the same amount of material.
!C 	An evenly spaced path will be symmetrical, but the first
!C 	cut is larger than subsequent cuts.
!C 	An evenly spaced path will NOT be symmetrical, but all
!C 	cuts will remove the same amount of material.
!C
!C 	(Leadin feed factor) Default= 1.0.  This gives the ability to feed
!C 	at a reduced rate before the cut.  If a factor other than
!C 	1.0 is used then the first line is broken into two segments
!C 	Otherwise, it is one continuous movement.
!C
!C 	(Leadout feed factor) Default= 1.0.  This gives the ability to feed
!C 	at an increased rate after the cut.  If a factor other than
!C 	1.0 is used then the last line is broken into two segments
!C 	Otherwise, it is one continuous movement. Also, a factor of
!C 	0.0 will make the end move a rapid movement.
!C
!C 	The factors can BOTH increase or decrease the feed rate.
!C
!C NOTES:
!C 
!C 	The script can be changed so that more questions are asked.  There
!C 	is an "IF 0 THEN" around the questions not asked.  The 0 can be
!C 	changed to a 1 so that the question is asked.
!C
!# see also - points.d/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: face mill rectangle area ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Zstart_var$[256],Zstep_var$[256]
DIM Zend_var$[256],Zmethod_var$[256]
DIM Method_var$[256],Overlap_var$[256],Overhang_var$[256],Overrun_var$[256]
DIM Leadin_var$[256],Leadout_var$[256],Zmove_type_var$[256]
DIM Runout_var$[256],Zlevel_var$[256],Zretract_var$[256]
DIM Fclear_var$[256],Bclear_var$[256],F_feed_var$[256],B_feed_var$[256]
DIM Tool_name$[256]
DIM Namelist$[4000]
REAL Params(0:10)

Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

Stat=SetPickMask(WsPickNoSurf)
ActivateUndo

Current_pen=CurrentColor
IF ARGC>1 THEN
	Answer$= ARGV(1)
	GOTO Have_tool
END IF

Start:!
Stat=ToolSelectBox("TOOLS","selected tool",WsAllMills)
IF Stat THEN
  LOAD "vtools.d/readmilltool:voffset.d/facemillrect"
  Stat= MessageFileBox("/usr/weber/database/messages/notoolsloaded","ATTENTION")
  GOTO Leave
END IF
Tool_ques:!
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT TOOL, New_tool ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "CANCEL" THEN
	LowerSelectBox
	GOTO Leave
END IF
IF Answer$="New_tool" THEN
	LowerSelectBox
	LOAD "vtools.d/readmilltool:voffset.d/facemillrect"
END IF

Have_tool:!
Tool_name$= Answer$
Tool=FindUserData(Tool_name$,WsToolData)
IF NOT ValidGeometry(Tool) THEN Tool_ques

SELECT 1
CASE 1
	Namelist$= " 1: Bi-directional Y,"
	Namelist$= Namelist$&" 2: Bi-directional X,"
	Namelist$= Namelist$&"11: Bi-directional Y w/rapids,"
	Namelist$= Namelist$&"12: Bi-directional X w/rapids,"
	Namelist$= Namelist$&"21: Uni-directional Y,"
	Namelist$= Namelist$&"22: Uni-directional X,"
	Stat=GeneralListBox("CUT METHODS","CHOICES",Namelist$)
	Stat= SetInputFormat("a99","")
	Stat=GetValue("CUT METHOD ",Answer$)
	LowerSelectBox
	IF ExitScript(Destination$) THEN Leave
	IF Answer$="CANCEL" THEN Leave
	Method= VAL(Answer$)
	Axis_type= Method MOD 10
	Cut_type= Method DIV 10
CASE 2
	Stat= SetInputFormat("a1",",X,Y,")
	Stat=GetValue("AXIS TO CUT ALONG. X OR Y ",Answer$)
	IF ExitScript(Destination$) THEN Leave
	Method= 1+(Answer$="X")
	Axis_type= 1+(Answer$="X")

	Stat= SetInputFormat("a1",",U,B,")
	Stat=GetValue("Uni- OR Bi- DIRECTIONAL CUTS",Answer$)
	IF ExitScript(Destination$) THEN Leave
	Method= Method+20*(Answer$="U")
	Cut_type= 2*(Answer$="U")
CASE ELSE
	Method= 2
END SELECT

IF 1 THEN
 Stat= SetInputFormat("n4=","")
 Stat= SetEqualsValue(Overlap)
 Overlap=GetValue("CUTTER OVERLAP BETWEEN CUTS")
 IF ExitScript(Destination$) THEN Leave
 No_overlap_var= LastVariableInput(Overlap_var$)
ELSE
 Overlap= .10*ToolDiameter(Tool)
 No_overlap_var= 1
END IF

IF 0 THEN
 Stat= SetInputFormat("n4=","")
 Stat= SetEqualsValue(Overlap)
 Overrun=GetValue("DISTANCE TO RUN PAST EDGE ")
 IF ExitScript(Destination$) THEN Leave
 No_overrun_var= LastVariableInput(Overrun_var$)
ELSE
 Overrun= Overlap
 No_overrun_var= 1
END IF

IF 0 THEN
 Stat= SetInputFormat("n4=","")
 Stat= SetEqualsValue(Overrun)
 Overhang=GetValue("CUTTER OVERHANG ALONG AN EDGE ")
 IF ExitScript(Destination$) THEN Leave
 No_overhang_var= LastVariableInput(Overhang_var$)
ELSE
 Overhang= Overrun
 No_overhang_var= 1
END IF

SELECT 0
CASE 1
 Stat= SetInputFormat("n4=","")
 Stat= SetEqualsValue(ToolDiameter(Tool)/2)
 Leadin=GetValue("LEADIN DISTANCE ")
 IF ExitScript(Destination$) THEN Leave
 No_leadin_var= LastVariableInput(Leadin_var$)
 No_leadout_var= No_leadin_var
 Leadout= Leadin
 Leadout_var$= Leadin_var$
CASE 2
 Stat= SetInputFormat("n4=","")
 Stat= SetEqualsValue(ToolDiameter(Tool)/2)
 Leadin=GetValue("LEADIN DISTANCE ")
 IF ExitScript(Destination$) THEN Leave
 No_leadin_var= LastVariableInput(Leadin_var$)

 Stat= SetInputFormat("n4=","")
 Stat= SetEqualsValue(ToolDiameter(Tool)/2)
 Leadout=GetValue("LEADOUT DISTANCE ")
 IF ExitScript(Destination$) THEN Leave
 No_leadout_var= LastVariableInput(Leadout_var$)
CASE ELSE
 Leadin= ToolDiameter(Tool)/2
 Leadout= Leadin
 No_leadin_var= 1
 No_leadout_var= 1
END SELECT

IF 0 THEN
 Stat= SetInputFormat("n4","")
 Fclear=GetValue("ADDITIONAL LEADIN CLEARANCE ")
 IF ExitScript(Destination$) THEN Leave
 No_fclear_var= LastVariableInput(Fclear_var$)
ELSE
 Fclear= 0.0
 No_fclear_var= 1
END IF

IF 0 THEN
 Stat= SetInputFormat("n4","")
 Bclear=GetValue("ADDITIONAL LEADOUT CLEARANCE ")
 IF ExitScript(Destination$) THEN Leave
 No_bclear_var= LastVariableInput(Bclear_var$)
ELSE
 Bclear= 0.0
 No_bclear_var= 1
END IF

IF 0 THEN
 Namelist$= "0: Leadout+Overrun "
 Namelist$= Namelist$&"1: Overrun "
 Namelist$= Namelist$&"2: Minimize the edges "
 Stat=GeneralListBox("CUT METHODS","CHOICES",Namelist$)
 Stat= SetInputFormat("n0a99","")
 Runout=GetValue("WHERE SHOULD THE INTERMEDIATE CUT EDGES STOP ",Answer$)
 LowerSelectBox
 IF ExitScript(Destination$) THEN Leave
 IF Answer$="CANCEL" THEN Leave
 IF LEN(Answer$) THEN Runout= VAL(Answer$)
 No_runout_var= LastVariableInput(Runout_var$)
ELSE
 Runout= 1
 No_runout_var= 1
END IF

IF 0 THEN
 Stat= SetInputFormat("n0","")
 Zmethod=GetValue("Z CUT METHOD. ( 0 )EQUAL CUTS OR ( 1 )FULL CUT ")
 IF ExitScript(Destination$) THEN Leave
 No_zmethod_var= LastVariableInput(Zmethod_var$)
ELSE
 Zmethod= 0
 No_zmethod_var= 1
END IF

Stat= SetInputFormat("n4=","")
Stat= SetEqualsValue(Zstart)
Stat=SetPickReturn(WsGeometryZ)
Zstart=GetValue("Z LEVEL OF FIRST CUT ")
Stat=SetPickReturn(WsGeometryEnd)
IF ExitScript(Destination$) THEN Leave
No_zstart_var= LastVariableInput(Zstart_var$)

Stat= SetInputFormat("n4=","")
Stat= SetEqualsValue(Zend)
Stat=SetPickReturn(WsGeometryZ)
Zend=GetValue("Z LEVEL OF LAST CUT ")
Stat=SetPickReturn(WsGeometryEnd)
IF ExitScript(Destination$) THEN Leave
No_zend_var= LastVariableInput(Zend_var$)

IF Zstart<>Zend THEN
Get_zstep:Stat= SetInputFormat("n4=","")
	Zstep=NamedVarVal("depth of cut",WsSystemVars,0.0)
        Stat=SetEqualsValue(Zstep)
	Zstep=GetValue("DEPTH OF CUT ")
	IF ExitScript(Destination$) THEN Leave
	No_zstep_var= LastVariableInput(Zstep_var$)
	IF NOT Zstep THEN Get_zstep
	Ncuts= ABS((Zstart-Zend)/Zstep)
	Vdepth=CreateVariable("depth of cut",WsSystemVars,Zstep)
ELSE
	Zstep= 0
	No_zstep_var= 1
	Ncuts= 1
END IF

IF Ncuts>1 OR (Method>=20) THEN
	IF 0 THEN
	 Stat= SetInputFormat("n4=","")
	 Stat= SetEqualsValue(Zmove_type)
	 Zmove_type=GetValue("Z MOVE IN TYPE. ( 0 )RAPID OR ( 1 )FEED ")
	 IF ExitScript(Destination$) THEN Leave
	 No_zmove_var= LastVariableInput(Zmove_type_var$)
	ELSE
	 Zmove_type= 0
	 No_zmove_var= 1
	END IF

	IF 0 THEN
	 Stat= SetInputFormat("n4=","")
	 Stat= SetEqualsValue(Overrun)
	 Zretract=GetValue("Z RETRACT LEVEL. ( 0 )INCR. OR ( 1 )CONSTANT ")
	 IF ExitScript(Destination$) THEN Leave
	 No_zretract_var= LastVariableInput(Zretract_var$)
	ELSE
	 Zretract= 1
	 No_zretract_var= 1
	END IF

	Stat= SetInputFormat("n4=","")
	Stat= SetEqualsValue(Zlevel)
	Stat=SetPickReturn(WsGeometryZ)
	IF Zretract THEN
		Zlevel=GetValue("Z RETRACT LEVEL BETWEEN CUTS ")
	ELSE
		Zlevel=GetValue("Z PULLUP DISTANCE BETWEEN CUTS ")
	END IF
	Stat=SetPickReturn(WsGeometryEnd)
	IF ExitScript(Destination$) THEN Leave
	No_zlevel_var= LastVariableInput(Zlevel_var$)
ELSE
	Zlevel= 1.0*(25.4^(CurrentUnits=WsMetric))
	Zmove_type= 0
	No_zmove_var= 1
	Zretract= 1
	No_zlevel_var= 1
	No_zretract_var= 1
END IF

F_feed= 1.0
No_f_feed_var= 1
B_feed= 1.0
No_b_feed_var= 1

Pick_axis: PlotOn
stat= SetInputFormat("n4b","")
Stat= PointInputMode(1)
Ps=XyzInput("STARTING CORNER",WsXyzInput)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Ps) THEN Circle_loop
E1= LastPickEnt
Para1= LastPickPara
Pick_return1= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Ps)
        Stat= EntityNameCheck(E1,Point1$)
	Ps_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Point1$)
	Ps_created= WsFalse
END IF
Stat=SetLastPoint(Ps)
IF NOT Graphical_mode THEN
End_point:!
        Stat= PointInputMode(1)
        Pe=XyzInput("ENDING",WsXyzInput)
        IF ExitScript(Destination$) THEN Leave
        IF NOT ValidGeometry(Pe) THEN End_point
        E2= LastPickEnt
        Para2= LastPickPara
        Pick_return2= CurrPickReturn
        IF NOT ValidDependency(E2) THEN
                 E2= CopyEntity(Pe)
                 Stat= EntityNameCheck(E2,Point2$)
		 Pe_created= WsTrue
        ELSE
                 Stat= EntityNameCheck(E2,Point2$)
		 Pe_created= WsFalse
        END IF
        Stat=SetLastPoint(Pe)
ELSE
	PlotOff
	Angle= 0.0
	Length1= 2.0+ 2.0*Radius+ 2.0*Chamfer
	Pe= PtIncrXyz(Ps,Length1,Length1,0.0)
	IF Use_chamfer THEN
	   Contour= RectangleTwoPts(Ps,Pe,Chamfer,WsCornerChamfer,Centerstart)
	   Params(0)= WsCornerChamfer
	   Params(1)= Centerstart
	   Params(2)= Chamfer
	   Params(3)= Chamfer
	   Params(4)= Angle
        ELSE
	   Contour= RectangleTwoPts(Ps,Pe,Radius,WsCornerFillet,Centerstart)
	   Params(0)= WsCornerFillet
	   Params(1)= Centerstart
	   Params(2)= Radius
	   Params(3)= Radius
	   Params(4)= Angle
	END IF
	IF NOT ValidGeometry(Contour) THEN
	    IF Ps_created THEN Stat= DeleteEntity(Point1$)
	    Stat= DeleteEntityList(Ps,Pe)
	    PlotOn
	    GOTO Pick_axis
	END IF
	Stat= MakeInvisible(Contour)
	Stat= MakeInvisible(Ps)
	Stat= MakeInvisible(Pe)
	PlotOn

	Vnum= LastPickView
	Num_params=5
	Stat=SetInputFormat("n4b","")
	Stat=DynamicShape(Vnum,Contour,Ps,Pe,WsDynamicRectangle,"PICK ENDING CORNER ",Params,Num_params)
	IF ExitScript(Destination$) THEN
       		 Stat=DeleteGroup(Contour,WsTrue,WsTrue)
		 IF Ps_created THEN Stat=DeleteEntity(Point1$)
		 Stat= DeleteEntityList(Ps,Pe)
       		 IF Destination$= "BACKUP" THEN Pick_axis
       		 GOTO Leave
	END IF
	E2= LastPickEnt
        Para2= LastPickPara
        Pick_return2= CurrPickReturn
        Stat= DeleteGroup(Contour,WsTrue,WsTrue)
	Centerstart= Params(1)
        Radius= Params(2)
        Chamfer= Params(3)
        Angle= Params(4)
        no_radius_var=1
        no_chamfer_var=1
        IF NOT ValidDependency(E2) THEN
                 E2= CopyEntity(Pe)
                 Stat= EntityNameCheck(E2,Point2$)
                 Stat= MakeVisible(E2)
		 Pe_created= WsTrue
        ELSE
                 Stat= EntityNameCheck(E2,Point2$)
		 Pe_created= WsFalse
        END IF
END IF
Stat= DeleteEntityList(Ps,Pe)

Make_record:!
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("MILL: Face Rectangle Area "&Tool_name$)
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,Para2,WsGeomCenter)
END SELECT

Tool=FindUserData(Tool_name$,WsToolData)
V0= FreeParameter("Axis. 0)Either 1)Y 2)X ",Axis_type)
V1= FreeParameter("Cut type. 0)Zigzag 1)ZZr 2)One dir ",Cut_type)
V2= FreeParameter("Evenly. 0)Loaded or 1)Spaced",0)
IF No_overrun_var THEN
	V3= FreeParameter("Overrun",Overrun)
ELSE
	V3= FreeParameter("Overrun",Overrun_var$)
END IF
IF No_overhang_var THEN
	V4= FreeParameter("Overhang",Overhang)
ELSE
	V4= FreeParameter("Overhang",Overhang_var$)
END IF
IF No_overlap_var THEN
	V5= FreeParameter("Overlap",Overlap)
ELSE
	V5= FreeParameter("Overlap",Overlap_var$)
END IF
IF No_leadin_var THEN
	V6= FreeParameter("Leadin distance",Leadin)
ELSE
	V6= FreeParameter("Leadin distance",Leadin_var$)
END IF
IF No_leadout_var THEN
	V7= FreeParameter("Leadout distance",Leadout)
ELSE
	V7= FreeParameter("Leadout distance",Leadout_var$)
END IF
IF No_runout_var THEN
	V8= FreeParameter("Extend to 0)Leadout 1)Overrun 2)Min.",Runout)
ELSE
	V8= FreeParameter("Extend to 0)Leadout 1)Overrun 2)Min.",Runout_var$)
END IF
IF No_zmove_var THEN
	V25=FreeParameter("Z in move ( 0 )Rapid ( 1 )Feed",Zmove_type)
ELSE
	V25=FreeParameter("Z in move ( 0 )Rapid ( 1 )Feed",Zmove_type_var$)
END IF
IF No_zretract_var THEN
	V9= FreeParameter("Z retract is  0)Incr. or  1)Constant",Zretract)
ELSE
	V9= FreeParameter("Z retract is  0)Incr. or  1)Constant",Zretract_var$)
END IF
IF No_zlevel_var THEN
	V10= FreeParameter("Z retract",Zlevel)
ELSE
	V10= FreeParameter("Z retract",Zlevel_var$)
END IF
IF No_fclear_var THEN
	V11= FreeParameter("Additional leadin clearance",Fclear)
ELSE
	V11= FreeParameter("Additional leadin clearance",Fclear_var$)
END IF
IF No_bclear_var THEN
	V12= FreeParameter("Additional leadout clearance",Bclear)
ELSE
	V12= FreeParameter("Additional leadout clearance",Bclear_var$)
END IF
IF No_f_feed_var THEN
	V13= FreeParameter("Leadin feed factor",F_feed)
ELSE
	V13= FreeParameter("Leadin feed factor",F_feed_var$)
END IF
IF No_b_feed_var THEN
	V14= FreeParameter("Leadout feed factor",B_feed)
ELSE
	V14= FreeParameter("Leadout feed factor",B_feed_var$)
END IF

IF No_zmethod_var THEN
	V21= FreeParameter("Z step method",Zmethod)
ELSE
	V21= FreeParameter("Z step method",Zmethod_var$)
END IF
IF No_zstart_var THEN
	V22= FreeParameter("Z start",Zstart)
ELSE
	V22= FreeParameter("Z start",Zstart_var$)
END IF
IF No_zend_var THEN
	V23= FreeParameter("Z end level",Zend)
ELSE
	V23= FreeParameter("Z end level",Zend_var$)
END IF
IF No_zstep_var THEN
	V24= FreeParameter("Z step",Zstep)
ELSE
	V24= FreeParameter("Z step",Zstep_var$)
END IF
V26=FreeParameter("Cycle type",VariableValue(V0)+10*VariableValue(V1))
Zgroup= ZStepsPtGrp(V21,V22,V23,V24)
Path= FaceMillRectangle(V26,Ps,Pe,Zgroup,ToolDiameter(Tool),V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V25)
Stat= AssociateTool(Path,Tool)
Stat= AutoNameGroup(Path,Name$)
Stat= DeleteEntityList(Ps,Pe)
Stat= DeleteGroup(Zgroup,WsTrue)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Stat= PlotEntity(Path)
IF NOT ValidGeometry(Path) THEN
        DelLastVarRecord
ELSE
	Stat= AnimateTool(Tool,Path)
	ActivateUndo
	Stat= AdvanceUndoNumber("mill box area")
	IF Ps_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point1$)
	IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)
	Stat= AddGroupToUndo(WsUBCreateMode,Path,1,WsFalse)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_axis

Leave:!
Stat=SetPickMask(WsPickGeometry)
PlotOn
Stat= PointInputMode(0)
Stat= DeleteEntityList(Ps,Pe)
Stat= SetInputFormat("n4","")
LowerSelectBox

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
	IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END
