
! script name: pkgroups.d/pkgroupbyattrib
! solids: group by attribute

!A
!A NAME:
!A
!A	Group By Attribute
!A
!A DESCRIPTION:
!A
!A	This script will create a parasolids group of solid entities sharing
!A	a common attribute.
!A
!B INSTRUCTIONS:
!B	
!B	PICK ENTITY FOR ATTRIBUTES: Pick an entity of the solid model to
!B				determine the attribute 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 have attributes but you cannot create a group of bodies.
!B
!B
!# see also - htdocs/help.d/parasolids.htm

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

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Datastr$[2000]

ActivateUndo

Highlight_pen= 3

Start:!
Pick_loop:!
Stat=SetInputFormat("n4","")
E1=WPKPickEntity("PICK ENTITY FOR ATTRIBUTES")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Pick_loop

Stat= WPKListEntAttdefs(E1,"ATTDEFS","SELECT")
IF Stat THEN Pick_loop
Stat=SetInputFormat("a99","")
Stat=GetValue("ATTRIBUTE NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Name$= Answer$


ON ERROR GOTO Start
Att_num= VAL(Name$)

Datastr$= WPKEntAttribStr(E1,Name$,Att_num)
Pkbody= WPKParentBody(E1)

WPKClearErrorFlag
Pkgroup= WPKGroupByAttrib(Pkbody,Name$,Datastr$)
Pen_color= CurrentColor
Stat= WPKColorEntity(Pkgroup,Pen_color)
Stat= WPKHighlightEntity(Pkgroup,Highlight_pen)
IF NOT (WPKEntityClass(E1)= WsPKEdgeEnt) THEN
	Groups= WPKDisjointSubGrps(Pkgroup)
	E2= WPKRemoveGroup(Pkgroup)
END IF
Stat= DeleteEntity(Groups)

ActivateUndo
Stat= AdvanceUndoNumber("group by attribute")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Pick_loop

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