
! script name: holes.d/holetoolgrp
! topic: group holes according to associated tool

!A
!A NAME:
!A
!A 	Group by Tool
!A
!A DESCRIPTION:
!A
!A 	This script allows holes to be grouped according to the tool
!A 	associated with the holes.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT TOOL ID NAME: The selection box with the tool names
!B 		available will appear for a selection to be made.
!B
!B 	GROUP NAME: Enter the name to be associated with this
!B 		group of holes and tool.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: group by tool ")

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

ActivateUndo
Ploop:!
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 Ploop
LowerSelectBox

Group= GrpByTool(tool)
IF NOT ValidGeometry(Group) THEN Ploop

Hole_group=PtsInGroup(Group,WsPickHoles)
Stat=DeleteEntity(Group)

IF ValidGeometry(Hole_group) THEN 
	Stat=Highlight(Hole_group,WsPickPen,WsDirArrowOff)
	Stat=SetInputFormat("a99","")
	Stat=GetValue("GROUP NAME",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	Stat=ChangeGrpName(Hole_group,Answer$)

	ActivateUndo
	Stat= AdvanceUndoNumber("group by tool")
	Stat= AddItemToUndo(WsUBCreateMode,Hole_group)



END IF

GOTO Ploop

Leave:!
LowerSelectBox
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
