
! script name: wsccommon.d/deletegroup
! topic: delete elements in box

!A
!A NAME:
!A
!A 	Delete Group
!A
!A DESCRIPTION:
!A
!A 	This script allows a box to be made around the elements to be
!A 	deleted.  The elements selected will be highlighted the default
!A 	is red. This script will not permanently delete the elements
!A 	within the box until "Delete" is selected.  If part of an
!A 	element is inside the view box, the entire element is deleted.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that elements will
!B 		be deleted from.
!B
!B 	PICK FIRST CORNER OF PICK ZONE: Pick a corner of the box.
!B
!B 	PICK SECOND CORNER OF PICK ZONE: Pick the other corner of
!B 		the view box.
!B
!B 	Restore or Delete: Enter "R" to restore the elements within
!B 		the selected box.  Enter "D" to finalize the deletion
!B 		process.  Delete must be selected to finalize the
!B 		process, exiting the script works like Restore.
!B

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

DIM Answer$[256]
DIM Destination$[256]

!C 	If Ask_undo$="Y" the "Restore or Delete" options will be present.
!C 	If Ask_undo$="N" the script will automatically delete the elements
!C 	when they are picked.  NO CHANCE to change the selection.

Ask_undo$="Y"

ActivateUndo
FadeUndoButtons
Group_loop:!
Group=CreateGroup("TEMPGROUP")

Highlight_color= 2
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Vnum= LastPickView
Stat=PickBox(Group,Vnum,WsPickPen)
IF (ExitScript(Destination$)) THEN Leave

Stat= PlotEntity(Group)
Stat= RemoveVarEntities(Group)
Stat= RemoveRefEntities(Group)
Stat= SetSelectedFlag(Group,WsTrue)
Stat= PlotEntity(Group)
IF GroupCount(Group)= 0 THEN 
   Stat=DeleteEntity(Group)
   GOTO Group_loop
END IF
IF Ask_undo$="Y" THEN

   Stat=SetInputFormat("a1=",",R,D,")
   Stat=SetEqualsValue(0,"D")
   Stat=GetValue("Restore or Delete",Answer$)
   IF (ExitScript(Destination$)) THEN Leave

ELSE

   Answer$="D"

END IF

IF Answer$="D" THEN

   ActivateUndo
   Stat= AdvanceUndoNumber("delete")
   Stat= AddGroupToUndo(WsUBDeleteMode,Group,0,WsFalse)

   Stat=UnLink(Group)
   Stat=DeleteGroup(Group)

ELSE
   Stat= SetSelectedFlag(Group,WsFalse)
   PlotAll
   Stat=DeleteEntity(Group)

END IF

GOTO Group_loop

Leave:!
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat=DeleteEntity(Group)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

