
! script name: delete.d/delassembly
! topic: Sample - delete by assembly

!A
!A NAME:
!A
!A 	Delete By assembly
!A
!A DESCRIPTION:
!A
!A 	This script allows the deletion of everything in a specified assembly.
!A 	The entities that have been assigned to the assembly selected will be
!A 	highlighted, the default color is red.  This script will not
!A 	permanently delete the entities on a particular assembly until "Delete"
!A 	is selected.
!A
!B INSTRUCTIONS:
!B
!B 	DELETE COMPONENT #, Undo, Restore, Delete: Enter the number 
!B		of the assembly to be deleted or pick an element 
!B 		on the assembly to be deleted.
!B 		NOTE: The Undo, Restore, and Delete options do not appear the
!B 		first time, and will only be present if they are applicable.
!B
!B 		U - Undo works in a recursive manner.  The assembly will be
!B 		    undeleted in the reverse order in which they were selected.
!B 		R - Restore means that the selected assembly will 
!B 		    not be deleted and the script will start over.
!B 		D - Delete finalizes the deletion process for all the assemblys
!B 		    selected and remains in the script.  Restore will not undo
!B 		    the Delete.  NOTE: The "Delete" option must be selected
!B 		    to finalize the delete process.
!B
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: delete by assembly ")

DIM Answer$[256]
DIM Destination$[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"

DeActivateUndo

Start: !
Group=CreateGroup("TEMPGROUP")
Highlight_color=2

Group_loop:!

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

   stat= SetInputFormat("n0","")
   Assembly=InputAssembly("DELETE ASSEMBLY #",Answer$)

ELSE

   stat= SetInputFormat("n0a1",",U,R,D,")
   Assembly=InputAssembly("DELETE ASSEMBLY #, 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 Group_loop
    Stat=Highlight(Temp_group,1,0)
    Stat=RemoveFromGrp(Group,Group_num)
    Delete_count=GroupCount(Group)
    IF Delete_count>0 THEN
       Stat=Highlight(Group,Highlight_color,0)
    END IF
    Stat=DeleteEntity(Temp_group)

  CASE "R"

    GOSUB Free_temp
    GOTO Start

  CASE "D"

    IF ValidGeometry(Group) THEN
       N1=GroupCount(Group)
       IF N1 THEN
          Hold_group=CreateGroup("HOLDING GROUP")
          FOR I=1 TO N1
             G1= GroupElement(Group,I)
             Stat=CombineGroups(Hold_group,G1)
          NEXT I
          Stat=DeleteEntity(Group)
          Stat=UnLink(Hold_group)
          Stat=DeleteGroup(Hold_group,1)
       END IF
    END IF

    Stat=DeleteEntity(Group)

    TransformCleanUp

    GOTO Start

  CASE ELSE

    Group_assembly=GrpByAssembly(Assembly)
    IF (NOT ValidGeometry(Group_assembly)) THEN Group_loop

    IF Ask_undo$="N" THEN

       Stat=UnLink(Group_assembly)
       Stat=DeleteGroup(Group_assembly,1)
       Stat=DeleteEntity(Group_assembly)
       Stat=DeleteEntity(Group)
       TransformCleanUp
       GOTO Start

    ELSE

       N1=ElementGrpNum(Group,Group_assembly)
       IF N1=0 THEN
          Stat=AddToGroup(Group,Group_assembly)
       END IF
       Stat=Highlight(Group,Highlight_color,0)

    END IF

END SELECT


GOTO Group_loop

Free_temp: !
Delete_count=GroupCount(Group)
IF Delete_count THEN
   FOR I=1 TO Delete_count
      G1=GroupElement(Group,I)
      Stat=DeleteEntity(G1)
   NEXT I
   PlotAll
END IF
Stat=DeleteEntity(Group)
RETURN

Leave:!

GOSUB Free_temp

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