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

!A
!A NAME:
!A
!A 	Group Similar Holes in a Solid 
!A
!A DESCRIPTION:
!A
!A	This script will group all similar cylindrical holes in a solid body
!A	less than a prescribed radius. Similar holes are those having 
!A	the same components with the same dimensions. For each hole identified 
!A	a parasolids group is created containing the faces in the hole.
!A	Similar holes are colored in the current color.
!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]
DIM Descr$[256]
INTEGER Colors(20)

ActivateUndo

!     classify hole group by number of cylinders
Ncolors=1

Stat= GLPlotOn
Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 10000
ELSE
        Radius= 1000
END IF

Start:!
Stat=SetInputFormat("a1",",D,C,DW,CW,")
Stat=GetValue("SIMILAR:  Diameter, Configuration ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "D"
        Similar=2
CASE "C"
        Similar=1
CASE "DW"
        Similar=12
CASE "CW"
        Similar=11
END SELECT

Pick_hole:!
Stat=SetInputFormat("n4","")
E1=WPKPickEntity("PICK ENTITY IN HOLE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Pick_hole
Pkbody= WPKParentBody(E1)

Stat=SetInputFormat("a99","",WsFalse)
Stat=GetValue("HOLE FEATURE DESCRIPTION",Descr$)
IF (ExitScript(Destination$)) THEN Leave
IF Descr$="CANCEL" THEN Leave

Ncolors=1
Colors(1)= CurrentColor

WPKClearErrorFlag
G1= WPKGroupHoles(Pkbody,Radius,E1,Similar,Descr$,Ncolors,Colors)
Stat= DeleteEntity(G1)

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

GOTO Pick_hole

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