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

!A
!A NAME:
!A
!A 	Group By Color
!A
!A DESCRIPTION:
!A
!A 	This script allows parasolid entities to be grouped by color.
!A	The group is a part of the solid model and can be understood by
!A	other systems which read parasolids files.
!A
!B INSTRUCTIONS:
!B
!B	PICK ENTITY FOR COLOR: Pick an entity of the solid model for the
!B 		color to group by. This function groups by the synergy pen
!B 		number. RGB colored entities will be treated as the closest
!B 		synergy pen.
!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 have colors but you cannot create a group of bodies.
!B
!B 	Faces and Edges may now be assigned colors. 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 color ")

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

ActivateUndo

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

Pen1= GetColor(E1)

Pkgroup= WPKGroupByColor(E1,Pen1)
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 color")
Stat= AddItemToUndo(WsUBPKSessionMark)

GOTO Pick_loop

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