
! script name: delete.d/deleteboundary
! topic: delete boundary

!A
!A NAME:
!A
!A 	Delete Boundary
!A
!A DESCRIPTION:
!A
!A 	This script allows a boundary to be deleted.  The boundary selected will
!A 	be highlighted, the default color is red.  If an element is selected
!A 	rather than a boundary, the element is highlighted in the pick color.
!A 	This script will not permanently delete a boundary until "Delete" is
!A 	selected or the script is exited, by selection of another script.
!A
!B INSTRUCTIONS:
!B
!B 	DELETE WHICH BOUNDARY, Undo, Restore, Delete: Pick an element on the
!B 		boundary to be deleted.  NOTE: The Undo, Restore, and Procced
!B 		options do not appear the first time, and will only be present
!B 		if they are applicable.
!B
!B 		U - Undo works in a recursive manner.  The boundarys will be
!B 		    undeleted in the reverse order in which they were selected.
!B 		R - Restore means that the highlighted boundarys will not be
!B 		    deleted and the script will start over.  If Delete has been
!B 		    used, those elements are still gone.
!B 		D - Delete finalizes the deletion process for all the boundarys
!B 		    presently highlighted and remains in the script.  Restore
!B 		    will not undo the Delete.
!B
!C NOTE
!C
!C      This script deletes the boundary entity. It also unlinks
!C      the exterior contour. It does not unlink the interior islands.
!C

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

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

DeActivateUndo

Start: !
Group=CreateGroup("TEMPGROUP")

Highlight_color=2
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Ploop:!
Delete_count=GroupCount(Group)
Answer$=""
Choice$=""
IF Delete_count=0 THEN

  G1=PickGroupEnt("DELETE WHICH BOUNDARY")

ELSE

  Stat=SetInputFormat("a1",",U,R,D,")
  G1=PickGroupEnt("DELETE WHICH BOUNDARY, Undo, Restore, Delete",0,Answer$)

END IF
IF (ExitScript(Destination$)) THEN Leave
Choice$=Answer$

SELECT Choice$
   CASE "U"
      Group_num=GroupCount(Group)
      Temp_group=GroupElement(Group,Group_num)
      IF NOT ValidGeometry(Temp_group) THEN Ploop
      Stat= SetSelectedFlag(Temp_group,WsFalse)
      Stat= PlotEntity(Temp_group)
      Stat=RemoveFromGrp(Group,Group_num)
   CASE "R"
      Stat= SetSelectedFlag(Group,WsFalse)
      Stat= PlotEntity(Group)
      stat= DeleteEntity(Group)
      GOTO Start
   CASE "D"
      Stat= SetSelectedFlag(Group,WsFalse)
      Stat= PlotEntity(Group)
      Stat= DeleteGroup(Group,WsTrue)
      GOTO Start
   CASE ELSE
      Boundary1= FindBoundary(G1)
      IF NOT ValidGeometry(Boundary1) THEN Ploop
	 IF IsEntVariational(Boundary1) THEN Ploop
	 IF IsEntReferenced(Boundary1) THEN Ploop
         N1=ElementGrpNum(Group,Boundary1)
         IF N1=0 THEN
      	    Stat= SetSelectedFlag(Boundary1,WsTrue)
            Stat=AddToGroup(Group,Boundary1)
         END IF
         Stat=PlotEntity(Boundary1)
END SELECT

GOTO Ploop

Leave:!
UnSelectAll
stat= DeleteEntity(Group)

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