
! script name: holes.d/toolhole
! topic: associate tool with hole constructed

!A
!A NAME:
!A
!A 	Pick Tools
!A
!A DESCRIPTION:
!A
!A 	This script allows a hole to be constructed and associated with
!A 	a specific tool.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT TOOL ID NAME: The TOOLS selection box with the list of
!B 		available tools will automatically appear for a selection
!B 		to be made.
!B
!B 	INPUT X,Y,Z: Enter the X,Y,Z coordinates of the hole.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: pick tools ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Toolid$[256]

ActivateUndo
Start:!

Stat=ToolSelectBox("TOOLS","selected tool")
IF Stat=1 THEN Leave

Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT TOOL ID NAME",Name$)
IF ExitScript(Destination$) THEN Leave
IF Name$="CANCEL" THEN Leave

Tool=FindUserData(Name$,WsToolData)
IF NOT ValidGeometry(Tool) THEN Start

LowerSelectBox

Stat=GetUserString(Tool,"Tool type:",Toolid$)
Dia=GetUserValue(Tool,"Diameter:")
Pt_angle=GetUserValue(Tool,"Point angle:")

SELECT Toolid$
CASE "DRILL","CENTER DRILL","TWIST DRILL"
	Ask_depth=1
	A11=TAN(Pt_angle/2)
	Depth_addon=0.5*Dia/A11

CASE "COUNTER SINK"
	Ask_depth=0

	Dia1=InputRadius("HOLE DIAMETER",WsDiaInput)
	IF (ExitScript(Destination$)) THEN Leave

	IF (Dia1<Dia) THEN
		Dia=Dia1
	END IF

	A11=TAN(Pt_angle/2)
	Depth=0.5*Dia/A11
	Depth_addon=0

CASE ELSE
	Ask_depth=1
	Depth_addon=0
	Pt_angle=180

END SELECT


IF Ask_depth THEN

	Depth=InputDepth("FINISH DEPTH")
	IF (ExitScript(Destination$)) THEN Leave

END IF
	Depth=Depth+Depth_addon

Point_loop:!

Ploop:Pt=XyzInput("INPUT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

H1=Hole(Pt,Dia,Depth,Pt_angle)
Stat=AssociateTool(H1,Tool)

Stat=SetLastPoint(Pt,WsXyzInput)
Stat=DeleteEntity(Pt)

ActivateUndo
Stat= AdvanceUndoNumber("tool hole")
Stat= AddItemToUndo(WsUBCreateMode,H1)
GOTO Point_loop

Leave:!
LowerSelectBox
Stat=DeleteEntity(Pt)

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