
! script name: edit.d/edittoolnum
! topic: edit tool entity number

!A
!A NAME:
!A
!A 	Edit Tool Entity CNC-pocket (turret) number
!A
!A DESCRIPTION:
!A
!A 	This script will ask for a new "CNC tool-pocket number" or 
!A	"CNC tool-turret number" to be defained for a tool entity
!A	in the database.
!A
!A	*NOTE*: This function should only be used by users using the
!A	tool library to define their pocket numbers.  IF you are
!A	NOT using this field in the tool to define your tool numbers
!A	then this function will have no effect on the CNC code output.
!A
!B INSTRUCTIONS:
!B
!B 	CHOOSE TOOL: The selection box with the available tools in the
!B 		JOB database will automatically appear for a selection
!B 		to be made.
!B
!B 	INPUT NEW TOOL NUMBER: Enter the tool number to assign to the
!B		tool.  If a repeat value comes up then that is the 
!B		current tool number assigned to that tool.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: tool file ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM File_name$[256]
DIM Dir$[256],D_label$[256],Choice$[256],Mask$[32]
DIM Namelist$[32000]
DIM Tool_class$[512],Toolstring$[512],Tool_type$[512]

ActivateUndo
Start:!
No_tools=ToolSelectBox("TOOLS","selected tool")
IF No_tools THEN Leave
Stat=SetInputFormat("a99","")
Stat=GetValue("CHOOSE TOOL",Name$)
IF ExitScript(Destination$) OR Name$="CANCEL" THEN Leave
LowerSelectBox

Tool=FindUserData(Name$,WsToolData)
IF NOT ValidGeometry(Tool) THEN Start
Stat=GetUserString(Tool,"Tool type:",Tool_type$)
SELECT Tool_type$
CASE "OD TURN","OD GROOVER","OD THREADER","ID TURN","ID GROOVER","ID THREADER"
	Toolstring$="CNC tool-turret number:"
CASE ELSE
	Toolstring$="CNC tool-pocket number:"
END SELECT

IF CheckUserField(Tool,Toolstring$,0) THEN
	Tool_num=GetUserValue(Tool,Toolstring$)
	Stat=SetEqualsValue(Tool_num)
	Stat=SetInputFormat("n0=","")
ELSE
	Stat=SetInputFormat("n0","")
END IF

Tool_num=GetValue("INPUT NEW TOOL NUMBER ",Answer$)
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("edit tool number")
Stat= AddItemToUndo(WsUBModifyMode,Tool)

Stat=PutUserValue(Tool,Toolstring$,Tool_num)

GOTO Start

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