!   TITLE:  drill_pattern.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates an evenly spaced drill pattern in a selected set
!   of volumes around a center axis.
!
!
!   COMMAND SYNTAX:
!
!                       (1)   (2)    (3)   (4)   (5)     (6)    (7)
!       DRILL_PATTERN, csnum, rpat, zpos, numh, anginc, stang, patang,
!
!                       (8)   (9)    (10)    (11)    (12)
!                      dhole, tool, depth, r_or_ang, btol
!
!
!   ARGUMENTS:
!
!       (1) csnum = coordinate system number whose Z axis the pattern is con-
!                   structed around (need not be a cylindrical c.s.).
!
!       (2) rpat = radius of hole pattern (i.e., the radial distance at
!                  which the hole local c.s. is placed)
!
!       (3) zpos = z position relative to 'csnum' from which the pattern
!                  is created
!
!       (4) numh = number of holes around the perimeter (if left blank,
!                  then the angular increment must be specified)
!
!       (5) anginc = angular spacing increment for the hole pattern
!                    (if left blank, then the number of holes must
!                    be specified)
!
!       (6) stang = start angle at which the pattern is initiated
!
!       (7) patang = the total pattern angle, measured from 'stang'
!                    (if left blank, defaults to 360)
!
!       (8) dhole = hole diameter
!
!       (9) tool = tool type:
!
!                   'f' = flat cutting tool
!                   'b' = ball cutting tool
!                   'c' = cone-shaped cutting tool
!
!       (10) depth = hole depth as measured from 'zpos' (argument 3)
!
!       (11) r_or_ang = specification of cutting tool fillet radius OR
!                       angle
!
!                   (a) If 'tool' = 'f', then this argument specifies
!                       the fillet radius of the flat cutting tool.
!
!                   (b) If 'tool' = 'c', then this argument specifies
!                       the angle of the conic cutting tool.
!
!                   NOTE: For 'tool' = 'b', this argument is ignored.
!
!       (12) btol = boolean tolerance value:
!
!                   0 (or blank) = 0.0001   (default)
!                   1 = 0.001
!                   2 = 0.01
!
!           Note: This argument need only be specified when the volume addition
!                 or subtraction operations fail at the creation of the tool.
!                 If an operation fails, then simply go to the next higher level
!                 boolean tolerance (first 0, then 1, then 2), and reattempt the
!                 operation.
!
!
!   DESCRIPTION:
!
!   The drill pattern is used for creating drilled holes in a circumferential
!   pattern around the Z axis of a specified C.S. in argument 1. This C.S. does
!   not need to be a cylindrical C.S., but have its Z axis oriented in the
!   desired direction for creating the pattern. The +Z axis must be oriented
!   out of the part, which is the opposite direction to the direction of drill.
!
!   The Z position of the drill pattern may be specified so that the proper
!   hole depth may be drilled.  From this Z position the hole depth is calc-
!   ulated in the -Z direction (see 'mach_op.mac' help).
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
csnum_=arg1
rpat_=arg2
zpos_=arg3
numh_=arg4
anginc_=arg5
stang_=arg6
patang_=arg7
dhole_=arg8
ttyp_=arg9
dpth_=ar10
rorang_=ar11
bt_=ar12
!
cm,vset1_,volu
!
*get,actcs_,active,,csys
!
*if,patang_,eq,0,then
    patang_=4*rtangle
*endif
!
*if,numh_,eq,0,then
    numh_=patang_/anginc_
*endif
!
*if,anginc_,eq,0,then
    *if,patang_,lt,4*rtangle,then
        anginc_=patang_/(numh_-1)
    *else
        anginc_=patang_/numh_
    *endif
    !
*endif
!
*if,patang_,eq,4*rtangle,then
    maxang_=stang_+patang_-anginc_
*else
    maxang_=stang_+patang_
*endif
!
csys,csnum_
!
*get,acs_,active,,csys
*get,acstyp_,cdsy,acs_,attr,kcs
!
*if,acstyp_,ne,1,then
    clocal,csn+20,1,0,0,0,0,0,0
    csnum_=csn+20
*endif
!
clocal,csn+21,0,rpat_,stang_,zpos_,0,0,0
!
mach_op,,ttyp_,dhole_,rorang_,dpth_,csn+21,bt_
!
cmsel,u,vset1_
csys,csnum_
vsel,s,volu,,vm
!
cir_vol_pattern,numh_,anginc_,patang_
!
cmsel,s,vpatrn_
cmsel,a,vset1_
!
vsbv,vset1_,vpatrn_,,delete,delete
init_entity_num
!
csdele,csn+20,csn+21,1
csys,actcs_
!
lplot
!
*set,csnum_,
*set,rpat_,
*set,zpos_,
*set,numh_,
*set,anginc_,
*set,stang_,
*set,patang_,
*set,dhole_,
*set,maxang_,
*set,rorang_,
*set,actcs_,
*set,acs_,
*set,acstyp_,
!
*if,prkey_,eq,1,then
    /go
*endif