
! script name: layers.d/layerenttype
! topic: layer group of elements in box by entity type

!A
!A NAME:
!A
!A 	Layer in Box By Entity Type.
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of elements within a box to be layered.
!A
!B INSTRUCTIONS:
!B
!B 	LAYER NUMBER,   current layer= # : Enter the layer number that will
!B 		be assigned to the elements selected.
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that the elements are in.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: layer by entity type ")

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

ActivateUndo
Layer=CurrentLayer

Ask_layer=1
IF ARGC> 1 THEN Ask_layer=0

IF Ask_layer THEN
        Stat=SetInputFormat("n0=","")
        Stat= SetEqualsValue(Layer)
        Layer=InputLayer("LAYER NUMBER ")
        IF (ExitScript(Destination$)) THEN Leave
        Stat= SetCurrentLayer(Layer)
END IF

E1=PickEntity("PICK ELEMENT TO DETERMINE ENTITY TYPE")
IF (ExitScript(Destination$)) THEN Leave
Etype= EntityType(E1)

Group_loop:!
Group=CreateGroup("TEMPGROUP")

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

Group1= GrpByEntType(Group,Etype)
Stat= PlotEntity(Group1,WsPickPen)

ActivateUndo
Stat= AdvanceUndoNumber("layer entity type")
Stat= AddGroupToUndo(WsUBModifyMode,Group1,0,WsFalse)

Stat=SetLayer(Group1)
Stat=DeleteEntity(Group)
Stat=DeleteEntity(Group1)

GOTO Group_loop

Leave:!
Stat=DeleteEntity(Group)
Stat=DeleteEntity(Group1)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END


