!   TITLE:  flng_ptrn_2.mac (PART_LIB)
!
!
!
!   This sub-macro creates an evenly spaced flange pattern around a center
!   line.  This pattern contains the evenly spaced holes around the peri-
!   meter.  This pattern is flange pattern #2, which is a flange with a
!   rounded fillet fitting tangent to the bolt flange profiles.The input
!   variables are as follows:
!
!       csnum = coordinate system number that the pattern is con-
!               structed around (must be a cylindrical c.s.)
!
!       rpat = radius of hole pattern (i.e., the radial distance at
!              which the hole local c.s. is placed)
!
!       zpos = z position relative to 'csnum' at which the pattern
!              is created
!
!       numh = number of holes around the perimeter (if left blank,
!              then the angular increment must be specified)
!
!       stang = start angle at which the pattern is initiated
!
!       secang = the angle subtended by a user defined section of the
!                flange inner radius. The flange inner radius profile
!                will be divided up into an integral number of these
!                angular sections for the purpose of aligning the flange
!                profile to a rotated set of volumes. Therefore, 'secang'
!                must be an integral divisor of 360; e.g., 10,20,30,40,45,
!                60,90,120,...etc.
!
!       dhole = hole diameter
!
!       radbf = radius of the bolt flange, which is the circular profile
!               surrounding each of the bolt holes around the outer per-
!               imeter of the flange.
!
!       radff = radius of the outer perimeter flange fillet between the
!               each of the bolt holes.
!
!       radin = inside radius of flange
!
!       radbh = radius of bolt head
!
!
!
!               (1)  (2)   (3)  (4)  (5)   (6)    (7)  (8)    (9)   (10)
! FLNG_PTRN_2, cnum, rpt,  zp,  nh,  sta, secang, dh, radbf, radff, radin,
!
!              radbh
!              (11)
!
!
*get,prkey_,active,0,prkey
/nopr

cnum=arg1
rpt=arg2
zp=arg3
nh=arg4
sta=arg5
secang=arg6
dh=arg7
radbf=arg8
radff=arg9
radin=ar10
radbh=ar11
!
ang=360/nh
stangh=sta
stangff=sta+ang/2
!
y=(asin((rpt/(radbf+radff))*sin((ang/2)*rconv)))*dconv
!
x=180-(ang/2)-y
!
rfc=sqrt(rpt**2+(radbf+radff)**2-2*rpt*(radbf+radff)*cos(x*rconv))
!
hole_pattern,cnum,rpt,zp,nh,,stangh,360,2*radbf
hole_pattern,cnum,rfc,zp,nh,,stangff,360,2*radff
!
init_entity_num
!
adele,am-(2*nh-1),am,1,1
!
init_entity_num
!
*do,ii,(cstran-(cstran-1)),nh,1
    !
    *if,ii,eq,(cstran-(cstran-1)),then
        jj=cstran
        kk=ii+nh
    *else
        jj=ii+(nh-1)
        kk=ii+nh
    *endif
    !
    csys,patcs%jj%
        !
        *if,ii,eq,(cstran-(cstran-1)),then
            k,,radff,2*rtangle,0
            *get,k1,kp,,num,max
        *endif
        !
        k,,radff,(2*rtangle)-y,0
        !
        init_entity_num
        !
        l,km-1,km
        !
        init_entity_num
        !
    csys,patcs%ii%
        !
        k,,radbf,0,0
        !
        init_entity_num
        !
        l,km-1,km
        !
        init_entity_num
        !
    csys,patcs%kk%
        !
        k,,radff,(2*rtangle)+y,0
        !
        *if,ii,ne,nh,then
            k,,radff,2*rtangle,0
        *endif
        !
        init_entity_num
        !
    csys,patcs%ii%
        !
        *if,ii,ne,nh,then
            l,km-2,km-1
        *else
            l,km-1,km
        *endif
        !
    csys,patcs%kk%
        !
        *if,ii,ne,nh,then
            l,km-1,km
        *else
            l,km,k1
        *endif
        !
        init_entity_num
*enddo
!
lsel,selv,line,,lm-(4*nh-1),lm,1
!
al,all
!
init_entity_num
!
csys,cnum
!
*do,ii,sta,sta+4*rtangle-secang,secang
    k,,radin,ii,zp
*enddo
!
init_entity_num
!
sec=4*rtangle/secang
!
*do,ii,1,sec,1
    *if,ii,lt,sec,then
        l,km-(sec-ii),km-((sec-ii)-1)
    *else
        l,km-(sec-ii),km-(ii-1)
    *endif
*enddo
!
init_entity_num
!
lsel,selv,line,,lm-(sec-1),lm,1
!
al,all
!
init_entity_num
!
asba,am-1,am,,delete,delete
!
init_entity_num
!
hole_pattern,cnum,rpt,zp,nh,,stangh,360,2*radbh
!
init_entity_num
!
asel,selv,area,,am-(nh-1),am
cm,aset1,area
!
init_entity_num
!
asba,am-nh,aset1,,delete,keep
!
init_entity_num
!
hole_pattern,cnum,rpt,zp,nh,,stangh,360,dh
!
init_entity_num
!
asel,selv,area,,am-(nh-1),am
cm,aset2,area
!
init_entity_num
!
asba,aset1,aset2,,delete,delete
!
init_entity_num
!
*set,cnum,
*set,nh,
*set,rpt,
*set,zp,
*set,sta,
*set,secang,
*set,stangh,
*set,patang,
*set,dh,
*set,maxang,
*set,m,
*set,ii,
*set,jj,
*set,kk,
*set,zzz,
*set,radbf,
*set,radff,
*set,radin,
*set,radbh,


*if,prkey_,eq,1,then
    /go
*endif