!   TITLE:  flng_ptrn_1.mac (PART_LIB)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates an evenly spaced circular flange bolt pattern
!   about the Z axis of a selected coordinate system.
!
!
!   COMMAND SYNTAX:
!
!
!                     (1)   (2)     (3)   (4)     (5)    (6)     (7)    (8)
!       FLNG_PTRN_1, csnum, rpat,  zpos,  numh,  stang, secang, dhole, radbf,
!
!                    radout, radin, radbh, rfil
!                     (9)     (10)   (11)  (12)
!
!
!   ARGUMENTS:
!
!       (1) csnum = coordinate system number that the pattern is con-
!                   structed around (must 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' at which the pattern
!                  is created
!
!       (4) numh = number of bolt holes around the perimeter
!
!       (5) stang = start angle at which the pattern is initiated
!
!       (6) 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.
!
!       (7) * dhole = bolt hole diameter.
!
!                 * If no holes are desired in the flange, then simply placing
!                   a zero for this argument, or leaving this argument blank,
!                   will create the flange without the bolt holes.
!
!       (8) 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.
!
!       (9) radout = outer radius of circular flange.
!
!       (10) radin = inside radius of circular flange
!
!       (11) radbh = radius of bolt head
!
!       (12) rfil = flange fillet radii
!
!
!   DESCRIPTION:
!
!   This flange pattern has protruding circular bosses enclosing the bolt holes,
!   with the flange as a simple circular perimeter between the bosses. The flange
!   may contain the evenly spaced holes around the perimeter, or be created with
!   no holes. This configuration is named FLANGE PATTERN #1.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
cnum__=arg1
rpt__=arg2
zp__=arg3
nh__=arg4
sta__=arg5
secang__=arg6
dh__=arg7
radbf__=arg8
radout__=arg9
radin__=ar10
radbh__=ar11
rfil__=ar12
!
ang_=360/nh__
!
hole_pattern-,cnum__,rpt__,zp__,nh__,,sta__,360,2*radbf__
!
adele,am-(nh__-1),am,1,1
!
init_entity_num
!
*do,ii_,1,nh__,1
    csys,csn-(nh__-ii_)
    k,,rpt__-radout__,180,0
*enddo
!
csys,cnum__
create_lines,1
!
*do,ii_,1,nh__,1
    csys,csn-(nh__-ii_)
    !
    k,,radbf__,190,0
    k,,radbf__,0,0
    k,,radbf__,170,0
    !
    create_lines,1,1
*enddo
!
isolate_lines
!
lovlap,all
!
init_entity_num
!
*do,ii_,1,nh__,1
    csys,csn-(nh__-ii_)
    !
    isolate_lines
    ksll,s
    ksel,r,loc,x,0,abs(rpt__-radout__)
    !
    *if,(rpt__-radout__),gt,0,then
        ksel,r,loc,y,180
    *elseif,(rpt__-radout__),lt,0,then
        ksel,r,loc,y,0
    *endif
    !
    lslk,r,0
    ldele,all,,,1
*enddo
!
init_entity_num
!
csys,cnum__
isolate_lines
ksll,s
ksel,u,loc,x,radout__,radout__+radbf__+(rpt__-radout__)
lslk,r,0
ldele,all,,,1
!
init_entity_num
!
isolate_lines
cm,lset1,line
!
*do,ii_,1,nh__,1
    csys,cnum__
    !
    lsel,s,line,,lset1
    lsel,r,loc,y,((ii_-1)*ang_)+sta__,((ii_-1)*ang_)+sta__+ang_/2
    !
    get_max_entity
    get_min_entity
    !
    lfillt,lm,l_min,rfil__
    !
    lsel,s,line,,lset1
    lsel,r,loc,y,((ii_-1)*ang_)+sta__+ang_/2,((ii_-1)*ang_)+sta__+ang_
    !
    get_max_entity
    get_min_entity
    !
    lfillt,lm,l_min,rfil__
    !
    init_entity_num
    !
*enddo
!
isolate_lines
!
al,all
!
init_entity_num
!
create_circle,radin__,zp__,secang__,,sta__
create_area-lines
!
asba,am-1,am,,delete,delete
!
init_entity_num
!
lplot
!
*if,radbh__,gt,0,then
    hole_pattern-,cnum__,rpt__,zp__,nh__,,sta__,360,2*radbh__
    !
    asel,s,area,,am-(nh__-1),am
    cm,aset1,area
    !
    init_entity_num
    !
    asba,am-nh__,aset1,,delete,keep
    !
    init_entity_num
    !
    isolate_areas
    !
    csys,cnum__
    !
    asel,r,loc,x,rpt__
    cm,aset1,area
    !
    init_entity_num
    !
    lplot
*endif
!
*if,dh__,gt,0,then
    hole_pattern-,cnum__,rpt__,zp__,nh__,,sta__,360,dh__
    !
    asel,s,area,,am-(nh__-1),am
    cm,aset2,area
    !
    init_entity_num
    !
    *if,radbh__,gt,0,then
        asba,aset1,aset2,,delete,delete
    *else
        asba,am-nh__,aset2,,delete,delete
    *endif
    !
    init_entity_num
    !
    lplot
*endif
!
*do,ii_,1,cstran,1
    csdele,patcs%ii_%
    *set,patcs%ii_%
*enddo
!
*set,ang_,
*set,cnum__,
*set,cstran,
*set,nh__,
*set,rpt__,
*set,zp__,
*set,sta__,
*set,secang__,
*set,dh__,
*set,ii_,
*set,radbf__,
*set,radin__,
*set,radbh__,
*set,rfil__,
*set,radout__,
cmdele,lset1
!
*if,prkey_,eq,1,then
    /go
*endif