
! script name: pkgroups.d/pkgroupbylayer
! solids: group parasolid entities by color

!A
!A NAME:
!A
!A 	Group By Layer
!A
!A DESCRIPTION:
!A
!A 	This script allows parasolid entities to be grouped by layer.
!A 	The group becomes an integral part of the solid model and may
!A 	be understood by other systems which read parasolids files.
!A
!B INSTRUCTIONS:
!B
!B	PICK ENTITY FOR LAYER: Pick an entity of the solid model to
!B 		determine the layer to group by.
!B
!B NOTE:
!B
!B 	Avoid placing an entity into more than one group.
!B
!B 	Imported solids files may already have some groups check for groups
!B 	by getting a listing of the entities. You may wish to remove all
!B 	groups before starting to work with the file.
!B
!B 	Bodies can be on a layer but you cannot create a group of bodies.
!B
!B 	Faces and Edges may now be assigned layers. When a face is created
!B 	it will be assigned the current color and current layer. Edges are
!B 	not automatically assigned any layer or color.
!B
!# see also - htdocs/help.d/pkgroups.htm
!# see also - htdocs/help.d/parasolids.htm

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

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

ActivateUndo

Highlight_pen= 3
Pick_loop:!
E1=WPKPickEntity("PICK ENTITY FOR LAYER")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Pick_loop

Layer= GetLayer(E1)

Pkgroup= WPKGroupByLayer(E1,Layer)
Stat= WPKHighlightEntity(Pkgroup,Highlight_pen)
IF NOT (WPKEntityClass(E1)= WsPKEdgeEnt) THEN
	Groups= WPKDisjointSubGrps(Pkgroup)
	E2= WPKRemoveGroup(Pkgroup)
	Stat= DeleteEntity(Groups)
END IF

ActivateUndo
Stat= AdvanceUndoNumber("group by layer")
Stat= AddItemToUndo(WsUBPKSessionMark)

GOTO Pick_loop

Leave:!
LowerColorBox
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
