!   TITLE:  a_rect_pattern.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates a rectangular spaced pattern of an area.
!
!
!   COMMAND SYNTAX:
!
!                       (1)   (2)      (3)    (4)    (5)    (6)
!       A_RECT_PATTERN, acs, area_#, x_space, N_x, y_space, N_y
!
!
!   ARGUMENTS:
!
!       (1) acs = the active coordinate system (CS) to build the pattern in.
!                 May be any CS type (i.e., crtesian, cylindrical, etc.)
!
!       (2) area_# = the area number to create the pattern from.
!
!       (3) x_space = the distance between the areas along the X-axis
!                     direction (centroid-to-centroid).
!
!       (4) N_x = the number of areas in the X direction.
!
!       (5) y_space = the distance between the areas along the Y-axis
!                     direction (centroid-to-centroid).
!
!       (6) N_y = the number of areas in the Y direction.
!
!
!   DESCRIPTION:
!
!   The rectangular pattern is a planar pattern of areas that are arranged in
!   aligned rows and columns. The number or rows and colums of the pattern are
!   determined by arguments 6 and 4, respectively. A row is a series of aligned
!   areas having the same Y coordinate value, whereas a column is a series of
!   aligned areas having the same X coordinate value.
!
!   The spacing between each area, as measured from centroid to centroid, or
!   between corresponding identical points or edges on each area. The spacing in
!   the X and Y directions is determined by arguments 3 and 4, respectively.
!
!   The new areas formed from the original area of argument 2, will be patterned
!   along the coordinate X and Y directions of the CS specified in argument 1.
!   The CS may be any type (i.e., cartesian, cylindrical, etc.). The rectangular
!   pattern will be formed relative to the X and Y axis directions of that CS,
!   with the X and Y coordinate values as cartesian coordinates.
!
!   The newly created areas are automatically stored in a component group
!   designated:
!                               NEW_AS
!
!   These areas may then be manipulated with boolean operations as desired.
!
!   To view a rectangle created from this macro, run the following example
!   lines of code (must execute 'mod_assemb_prep' prior to running):
!
!   EXAMPLE: (place this code in a test macro and execute):
!
!                   mod_assemb_prep
!                   create_rect_pos,0,'lx',1,'ly',1,0.5,1,0,0.1
!                   a_rect_pattern,0,1,1.5,4,2,5
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
acs___=arg1
anum__=arg2
xspace_=arg3
xnum_=arg4
yspace_=arg5
ynum_=arg6
!
csys,acs___
clocal,csn+1000,0,0,0,0,0,0,0
!
ypos_=-yspace_
!
*do,row_,1,ynum_,1
    ypos_=ypos_+yspace_
    !
    csys,csn+1000
    !
    *if,row_,eq,1,then
        colinit_=2
        clocal,csn+1001,0,0,ypos_,0,0,0,0
    *elseif,row_,gt,1,then
        colinit_=1
        clocal,csn+1001,0,-xspace_,ypos_,0,0,0,0
    *endif
    !
    *do,col_,colinit_,xnum_,1
        clocal,csn+1001,0,xspace_,0,0,0,0,0
        !
        csys,csn+1000
        atran,csn+1001,anum__
        csys,csn+1001
    *enddo
*enddo
!
init_entity_num
!
csdele,csn+1000,csn+1001
!
asel,s,area,,am-((xnum_*ynum_)-1),am
cm,new_as,area
!
init_entity_num
aplot
!
*set,acs___,
*set,anum__,
*set,xspace_,
*set,xnum_,
*set,yspace_,
*set,ynum_,
*set,ypos_,
*set,row_,
*set,col_,
*set,colinit_,
!
*if,prkey_,eq,1,then
    /go
*endif