
! script name: delete.d/deletetool
! topic: delete tool from current list

!A
!A NAME:
!A
!A 	Delete Tool
!A
!A DESCRIPTION:
!A
!A 	This script will delete a tool from the current tool list.
!A
!B INSTRUCTIONS:
!B
!B 	TOOL ID NAME TO BE DELETED: The selection
!B 		box with the TOOLS available will automatically
!B 		appear for a selection to be made.  Geometry
!B 		associated with the tool to be deleted will
!B 		have the tool references deleted also.
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256],Name2$[256]
DIM Toolid$[256]
DIM Tool_grp$[256]

DeActivateUndo
Start:!

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

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

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

	Stat=GetUserString(Tool,"Tool image:",Tool_grp$)
	Grp=FindNamedGrp(Tool_grp$)

	Stat=UnAssocTool(Tool)
	IF ValidGeometry(Grp) THEN Stat=DeleteGroup(Grp)

	Task_ent= FindUserData(Task_ent,"AMO OPERATIONS",WsTaskPacket)
	IF ValidGeometry(Task_ent) THEN
Redo_tool:	Number= GetUserValue(Task_ent,"Number tools:")
		FOR J= 1 TO Number
		   Name2$= UserDataStr(Task_ent,"Tool "&VAL$(J)&":")
		   IF Name2$= Name$ THEN
			FOR I= J+1 TO Number
			  Name2$=UserDataStr(Task_ent,"Tool "&VAL$(I)&":")
			  Stat= PutUserString(Task_ent,"Tool "&VAL$(I-1)&":",Name2$)
			NEXT I	
			Stat= DeleteUserField(Task_ent,"Tool "&VAL$(Number)&":")
			Number= Number-1
			Stat= PutUserValue(Task_ent,"Number tools:",Number)
			GOTO Redo_tool
		   END IF
		NEXT J
	ELSE
		Oper_grp= FindNamedGrp("AMO OPERATIONS")
		IF ValidGeometry(Oper_grp) THEN
			Number= ElementGrpNum(Oper_grp,Tool)
			Stat= RemoveFromGrp(Oper_grp,Number)
		END IF
	END IF

	Stat=DeleteEntity(Tool)
END IF

GOTO Start

Leave:!
LowerSelectBox
stat= SetInputFormat("n4","")

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