
! script name: lathe.d/drill
! topic: center line drilling

!A
!A NAME:
!A
!A 	Drill
!A
!A DESCRIPTION:
!A
!A 	This script creates a drill path.  It can create either a single
!A	element path with a feed or a dual element path with a feed and
!A	a rapid.
!A
!B INSTRUCTIONS:
!B
!B	STARTING TOOL POSITION: Enter the position to start drilling.
!B
!B	ENDING TOOL POSITION: Enter the final position representing
!B	the hole depth.
!B
!C NOTE:
!C	This script can be run with the dual or single option as follows:
!C
!C		\Elathe.d/drill:dual
!C
!C	This option is there so that it can be used with a particular
!C	turbo posts.  Depending upon the turbopost, a different routine
!C	should be used.

Stat=ChangeLabelStr("ScriptNameStatus","Function: drill ")

DIM Destination$[256],Answer$[256]
DIM Cycle_type$[64]
INTEGER Rapid_linetype

IF ARGC>1 THEN
	Cycle_type$= ARGV(1)
ELSE
	Cycle_type$= "dual"
END IF
Cycle_type$=UPC$(Cycle_type$)

DEG
ActivateUndo
Rapid_linetype= 8
Current_pen= CurrentColor
Work= CurrentWorkplane
StdWorkplane

Tool_assoc=NamedVarVal("tool association",WsToolVars,0.)

IF Tool_assoc THEN
	Notools=ToolSelectBox("TOOLS","selected tool",WsNonTurn)
	IF NOT Notools THEN
		Stat=SetInputFormat("a99","")
		Stat=GetValue("DRILL PATH TOOL",Answer$)
		LowerSelectBox
		IF ExitScript(Destination$) THEN Leave
		IF Answer$= "CANCEL" THEN
			Tool_assoc=0
		ELSE
			Tool=FindUserData(Answer$,WsToolData)
		END IF
	ELSE
		Tool_assoc=0
	END IF
END IF

Stat= SetInputFormat("n4=","")
Xstart= GetValue("STARTING TOOL POSITION",Answer$)
IF ExitScript(Destination$) THEN Exit_drill

Endpt:Xend=GetValue("ENDING TOOL POSITION",Answer$)
IF ExitScript(Destination$) THEN Exit_drill

Dist= ABS(Xend-Xstart)
IF (Dist< 0.0001) THEN Endpt

P1= PointXYZ(Xstart,0,0)
P2= PointXYZ(Xend,0,0)

L1= LineTwoPoints(P1,P2,WsTRIMMED)
IF Cycle_type$= "DUAL" THEN
	L2= LineTwoPoints(P2,P1,WsTRIMMED)
	Stat= SetRapidFlag(L2,1)
	Stat= SetLinetype(L2,Rapid_linetype)
	Amode= WsMultipleAuto
ELSE
	L2= L1
	Amode= WsSingleAuto
END IF
Contour= AutoSequence("TempCon",L1,L2,0,Amode,WsForward,2,WsAutoseqPen)

IF ValidGeometry(Contour) THEN
	Stat=ColorContour(Contour)
	Stat=AutoNumberCont(Contour)
	IF Tool_assoc THEN Stat= AssociateTool(Contour,Tool)

	ActivateUndo
        Stat= AdvanceUndoNumber("drill contour")
        Stat= AddGroupToUndo(WsUBCreateMode,Contour,1,WsFalse)

END IF

Exit_drill:!
IF ValidGeometry(P1) THEN Stat= DeleteEntity(P1)
IF ValidGeometry(P2) THEN Stat= DeleteEntity(P2)

Leave:!
Stat=SetCurrentColor(Current_pen)
IF ValidGeometry(Work) THEN Stat=SetWorkplane(Work)
IF NOT LEN(Destination$) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
