
! script name: delete.d/deletedims
! topic: delete dimensions

!A
!A NAME:
!A
!A 	Delete Dimensions
!A
!A DESCRIPTION:
!A
!A 	This script allows dimensions to be deleted.  The dimension will
!A 	be highlighted, the default color is red.  If an element is selected
!A 	rather than a dimension, the element is highlighted in the pick color.
!A 	This script will not permanently delete a dimension until "Delete" is
!A 	selected or the script is exited, by selection of another script.
!A
!B INSTRUCTIONS:
!B
!B 	DELETE WHICH DIMENSION, Undo, Restore, Delete: Pick an element on the
!B 		dimension 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 dimensions will be
!B 		    undeleted in the reverse order in which they were selected.
!B 		R - Restore means that the highlighted dimensions 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 dimensions
!B 		    presently highlighted and remains in the script.  Restore
!B 		    will not undo the Delete.
!B

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

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

!C 	If Ask_undo$="Y" the "Undo, Restore, 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
Start: !
Group=CreateGroup("TEMPGROUP")

Highlight_color= 2
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

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

  ActivateUndo
  G1=PickEntity("DELETE WHICH DIMENSION")

ELSE

  FadeUndoButtons
  Stat=SetInputFormat("a1",",U,R,D,")
  G1=PickEntity("DELETE WHICH DIMENSION, Undo, Restore, Delete",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"
      IF ValidGeometry(Group) THEN
      Stat= SetSelectedFlag(Group,WsFalse)
      Stat=PlotEntity(Group)
      stat= DeleteEntity(Group)
      END IF
      GOTO Start

   CASE "D"

      IF ValidGeometry(Group) THEN
	 Stat= SetSelectedFlag(Group,WsFalse)
	 ActivateUndo
         Stat= AdvanceUndoNumber("delete dim")
         Stat= AddGroupToUndo(WsUBDeleteMode,Group,0,0)
         Stat= DeleteGroup(Group,WsTrue)
      END IF
      stat= DeleteEntity(Group)

      GOTO Start

   CASE ELSE

      IF NOT ValidGeometry(G1) THEN Ploop
      G2= ParentDimEnt(G1)
      IF NOT ValidGeometry(G2) THEN Ploop
      Stat=PlotEntity(G2)
      IF IsEntVariational(G2) THEN Ploop
      IF IsEntReferenced(G2) THEN Ploop

      IF Ask_undo$="N" THEN
	 Stat= SetSelectedFlag(G2,WsFalse)
	 ActivateUndo
         Stat= AdvanceUndoNumber("delete dim")
         Stat= AddDimToUndo(WsUBDeleteMode,G2,0,0)

         Stat=DeleteEntity(G2)
         Stat=DeleteEntity(Group)
         GOTO Start
      ELSE
         N1=ElementGrpNum(Group,G2)
         IF N1=0 THEN
	    Stat= SetSelectedFlag(G2,WsTrue)
            Stat=PlotEntity(G2)
            Stat=AddToGroup(Group,G2)
         END IF
      END IF

END SELECT

GOTO Ploop

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