
! script name: pkgroups.d/pkgroupholes
! solids: group holes in a solid model

!A
!A NAME:
!A
!A 	Group Holes in a Solid 
!A
!A DESCRIPTION:
!A
!A	This script will group all cylindrical holes in a solid body
!A	less than a prescribed radius. For each hole a parasolid
!A	group is created containing the faces in the hole. The holes
!A	are color coded by the number of components in the hole.
!A
!B INSTRUCTIONS:
!B
!B	MAXIMUM RADIUS: All holes less than this radius will be grouped.
!B
!B	PICK BODY: Pick the body.
!B
!C NOTES:
!C
!C      This script may be applied to any solid body.
!C
!C      To be found a hole must be recognizable as a cylindrical
!C      hole by the parasolids kernel. Non-cylindrical holes
!C      are not recognized and are not found.
!C
!C	Not every hole may be found. Exceptions are as follows:
!C
!C		The hole is not recognized as a cylindrical hole.
!C		This may happen if the hole is imported from another
!C		system which does not use cylinders and cones. 
!C		This may happen if the geometry contained in the hole
!C		is too complicated. An example might be where two or more
!C		intersect.
!C
!# see also - htdocs/help.d/pkgroups.htm
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: group holes ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
INTEGER Colors(20)

ActivateUndo

!     color hole group by number of components
Ncolors=20
FOR I= 1 TO 20
Colors(I)= 1+I
NEXT I

Stat= GLPlotOn
Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 25
        Length1= 125
ELSE
        Radius= 1
        Length1= 5
END IF

Stat= GLPlotOn
Ask_max_radius:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("MAXIMUM RADIUS")
IF ExitScript(Destination$) THEN Leave

Pick_body:!
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
        E1=WPKPickEntity("PICK BODY")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Pick_body
        Pkbody= WPKParentBody(E1)
END IF



WPKClearErrorFlag
G1= WPKGroupHoles(Pkbody,Radius,0,0,"",Ncolors,Colors)
Stat= DeleteEntity(G1)

ActivateUndo
Stat= AdvanceUndoNumber("group holes in solid")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck


GOTO Ask_max_radius

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