
! script name: vpkgroups.d/vpkgroupbylayer
! var_solids: group parasolid entities by color

!A
!A NAME:
!A
!A 	Group By Layer  VARIATIONAL
!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]
DIM Name$[256]
DIM Bodyname$[256]

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Highlight_pen= 3
Pick_loop:!
E1=WPKPickEntity("PICK ENTITY FOR LAYER")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Pick_loop
IF WPKEntityClass(E1)= WsPKEdgeEnt THEN
        Edge_group=1
ELSE
        Edge_group=0
END IF
Bodyname$= WPKBodyName(E1)
Layer= GetLayer(E1)

WPKClearErrorFlag
Stat= GenerateVarName("PkGroup",Name$)
RecordFunctionOn
Stat= RecordDescr("GROUP: group by layer")
V1= FreeParameter("Layer",Layer
IF NOT Edge_group THEN
        Pkgroup= WPKGroupByLayer(Bodyname$,V1,WsPKFaceEnt)
        Groups= WPKDisjointSubGrps(Pkgroup)
	Stat= WPKNameBody(Bodyname$,Bodyname$)
        E2= WPKRemoveGroup(Pkgroup)
        Stat= DeleteEntity(Groups)
ELSE
        Pkgroup= WPKGroupByLayer(Bodyname$,V1,WsPKEdgeEnt)
	Stat= WPKNameBody(Bodyname$,Bodyname$)
END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("group by layer")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

GOTO Pick_loop

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