!   TITLE:  flng_ptrn_2.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 pattern.
!   (2nd flange pattern)
!
!
!   COMMAND SYNTAX:
!
!                     (1)    (2)   (3)   (4)   (5)      (6)    (7)    (8)
!       FLNG_PTRN_2, csnum, rpat, zpos, numh, stangH, secang, dhole, radbf,
!
!                    radff, radin, radbh, stangC, thick
!                     (9)    (10)   (11)   (12)    (13)
!
!
!   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) radff = radius of the outer perimeter flange fillet webbing between
!                   each of the bolt holes.
!
!       (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) stangC = start angle at which the inside radius (argument 10) of
!                     the flange is initiated.
!
!       (13) 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_2,1,1.425,0,8,90,90,0.100,0.250,1.00,1.2,0.150,30,2
!
!
*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
rff__=arg9
rin__=ar10
rbh__=ar11
stangi__=ar12
thk__=ar13
!
csys,fcsnum_
clocal,csn+1000,1,0,0,0,0,0,0
fcsnum_=csn+1000
!
*if,secang_,eq,0,then
    secang_=90
*endif
!
phi__=360/(2*nh__)
theta___=asin(rpt__*sin((phi__)*rconv)/(rbf__+rff__))*dconv
alpha___=180-phi__-theta___
!
rfc_=sqrt((rpt__**2)+((rbf__+rff__)**2)-2*rpt__*(rbf__+rff__)*cos(alpha___*rconv))
rcirc___=sqrt((rpt__**2)+(rbf__**2)-2*rpt__*rbf__*cos(alpha___*rconv))
!
stangff_=stangh_+phi__
!
create_circ_area,rcirc___,zp__,,nh__,stangh_
hole_pattern,fcsnum_,rpt__,zp__,nh__,,stangh_,360,2*rbf__,2,90,1
!
isolate_areas
configuration,-1,1
aadd,all
init_entity_num
!
isolate_areas
configuration,-1,1
cm,flngset_,area
!
hole_pattern,fcsnum_,rfc_,zp__,nh__,,stangff_,360,2*rff__,2,90,1
!
isolate_areas
configuration,-1,1
cmsel,u,flngset_
cm,afilset_,area
!
isolate_areas
configuration,-1,1
asba,flngset_,afilset_,,delete,delete
init_entity_num
!
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__
    !
    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__
    !
    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
!
configuration,-2,1
!
aplot
!
csdele,fcsnum_
cmdele,flngset_
cmdele,bhset_
cmdele,holeset_
cmdele,afilset_
*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__,
*set,theta___,
*set,alpha___,
*set,rfc_,
*set,rcirc___,
!
*if,prkey_,eq,1,then
    /go
*endif