!   TITLE:  flng_ptrn_1.mac (PART_LIB)
!
!
!       Update macro with latest tools, made provision for default values
!       and for creating a flange volume by extrusion.
!
!   OBJECTIVE:
!
!   This sub-macro creates an evenly spaced cicrcular flange.
!   (1st flange pattern)
!
!
!   COMMAND SYNTAX:
!
!                     (1)    (2)   (3)   (4)   (5)      (6)    (7)    (8)
!       FLNG_PTRN_1, csnum, rpat, zpos, numh, stangH, secang, dhole, radbf,
!
!                    radout, radin, radbh, rfil, stangC, thick
!                      (9)    (10)   (11)  (12)   (13)    (14)
!
!
!   ARGUMENTS:
!
!       (1) csnum = coordinate system to construct the flange relative to.
!                   [may be any CS type]
!
!       (2) rpat = radius of hole (centers) pattern.
!
!       (3) zpos = position along the Z-axis of CSNUM (argument 1) at
!                  which the initial flange face is created.
!
!       (4) numh = number of bolt/screw holes around the perimeter.
!
!       (5) stangH = start angle at which the hole pattern is initiated.
!
!       (6) secang = the angle subtended by the circular center hole that
!                    creates the flange inner-perimeter. The inner perimeter
!                    will be divided into an integral number of line
!                    sections for aligning the flange to desired positions.
!                    This argument must be an integral divisor of 360 degrees.
!                    (e.g., 10,20,30,40,45,60,90,120,...etc.)
!                    [If 0 (or blank), defaults to 90]
!
!       (7) dhole = flange bolt/screw hole diameters.
!                   [If 0 (or blank), flange is created with no 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 flange. [If 0 (or blank), flange is
!                                               created with no center hole]
!
!       (11) radbh = radius of bolt head. [If 0 (or blank), flange is created
!                                           with no bolt head areas]
!
!       (12) rfil = flange fillet radii
!
!       (13) stangC = start angle at which the inside radius (argument 10) of
!                     the flange is initiated.
!
!       (14) thick = flange thickness.
!                    [If 0 (or blank), flange area only is created]
!
!
!   DESCRIPTION:
!
!   This pattern contains the evenly spaced holes around the perimeter. The
!   pattern is designated FLANGE PATTERN #2, which is a flange with rounded
!   fillets (webbing) fitting tangent to the bolt flange circular profiles.
!
!   The flange is created parallel to, or coincident with, the XY plane of
!   the coordinate system specified in argument 1. Therefore, the Z axis is
!   is the axis normal to the flange surface. This coordinate system may be
!   any type (i.e., cartesian, cyclindrical, etc.).
!
!   To view a flange created from this macro, run the following example line
!   of code (must execute 'mod_assemb_prep' prior to running):
!
!       FLNG_PTRN_1,1,3,0,6,90,,0.200,0.350,3.00,1.2,0.250,0.400,45,1
!
!
*get,prkey_,active,0,prkey
/nopr
!
configuration,0,1
!
fcsnum_=arg1
rpt__=arg2
zp__=arg3
nh__=arg4
stangh_=arg5
secang_=arg6
dh__=arg7
rbf__=arg8
rout__=arg9
rin__=ar10
rbh__=ar11
rfil__=ar12
stangi__=ar13
thk__=ar14
!
csys,fcsnum_
clocal,csn+360000,1,0,0,0,0,0,0
fcsnum_=csn+360000
!
*if,secang_,eq,0,then
    secang_=90
*endif
!
phi__=360/(2*nh__)
!
create_circ_area,rout__,zp__,,nh__,stangh_
hole_pattern,fcsnum_,rpt__,zp__,nh__,,stangh_,360,2*rbf__,2,0
!
isolate_areas
configuration,-1,1
aadd,all
init_entity_num
!
isolate_areas
configuration,-1,1
cm,flnglin_,line
adele,all
init_entity_num
!
cmsel,s,flnglin_
ksll,s
!
csys,fcsnum_
ksel,r,loc,x,rout__
!
ln_fillet,,rfil__
!
create_area-lines
!
csys,fcsnum_
!
*if,rin__,gt,0,then
    create_circ_area,rin__,zp__,secang_,,stangi__
    !
    asba,am-1,am,,delete,delete
    init_entity_num
*endif
!
isolate_areas
configuration,-1,1
cm,flngset_,area
!
*if,rbh__,gt,0,then
    hole_pattern,fcsnum_,rpt__,zp__,nh__,,stangh_,360,2*rbh__,,,1
    !
    isolate_areas
    configuration,-1,1
    cmsel,u,flngset_
    cm,bhset_,area
    !
    isolate_areas
    configuration,-1,1
    !
    asba,flngset_,bhset_,,delete,keep
    init_entity_num
    !
    isolate_areas
    configuration,-1,1
    cm,flngset_,area
*endif
!
*if,dh__,gt,0,then
    hole_pattern,fcsnum_,rpt__,zp__,nh__,,stangh_,360,dh__,,,1
    !
    isolate_areas
    configuration,-1,1
    cmsel,u,flngset_
    cm,holeset_,area
    !
    isolate_areas
    configuration,-1,1
    !
    asba,flngset_,holeset_,,delete,delete
    init_entity_num
    !
    isolate_areas
    configuration,-1,1
    cm,flngset_,area
*endif
!
*if,thk__,ne,0,then
    cmsel,s,flngset_
    extrude_aset,thk__
*endif
!
configuration,1,1
init_entity_num
!
aplot
!
csdele,fcsnum_
cmdele,flngset_
cmdele,bhset_
cmdele,holeset_
*set,fcsnum_,
*set,nh__,
*set,rpt__,
*set,zp__,
*set,secang_,
*set,stangh_,
*set,stangff_,
*set,dh__,
*set,rbf__,
*set,rff__,
*set,rin__,
*set,rbh__,
*set,stangi__,
*set,thk__,
*set,phi__,
!
*if,prkey_,eq,1,then
    /go
*endif