!   TITLE:  ara_create_part.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro is used to partition a selected set of areas by creating
!   a partition line by position and orientation from a known C.S.
!
!
!   COMMAND SYNTAX:
!
!                            (1)   (2)      (3)     (4)     (5)     (6)
!           ARA_CREATE_PART, acs, ang_ln, dist_ln, x_dist, y_dist, zpos,
!
!                            sclf
!                            (7)
!
!
!   ARGUMENTS:
!
!       (1) acs = the active C.S. located on the areas plane. The XY plane
!                 must be aligned coplanar with the selected areas
!
!       (2) ang_ln = the angle of the cutting line as measured from the
!                    C.S. +x axis.
!
!       (3) dist_ln = the normal distance of the line from the C.S. origin
!                     as measured in the XY plane of the active C.S.
!                     X_DIST and Y_DIST are ignored.
!
!       (4) x_dist = the distance along the x (+ or -) axis the line
!                    intersects as measured in the XY plane of the active
!                    C.S. Y_DIST and DIST_PLN are ignored.
!
!       (5) y_dist = the distance along the y (+ or -) axis the line
!                    intersects as measured in the XY plane of the active
!                    C.S. X_DIST and DIST_PLN are ignored.
!
!       (6) zpos = the z distance of the plane in which the areas, and
!                  therefore the cutting line, reside.
!
!       (7) sclf = line length sclaing factor. This parameter allows for
!                  controling the cutting line length.
!
!
!   DESCRIPTION:
!
!   The cutting line is created at a user specified angle, ANG_PLN, with
!   respect to the +x axis, and is an angle (in degrees) range of:
!
!                           0 < ang_pln < 180
!
!   The distance of the line (DIST_LN) is the magnitude of a vector from the
!   origin oriented normal to the line. Therefore, it is the perpendicular
!   distance of the line from the origin. The line is constructed such that
!   it lies in the XY plane of the active C.S., which is coplanar with the
!   selected area(s).
!
!   The line position may also be specified by the intercept with the X or
!   Y axis.  See the argument descriptions to verify proper useage.
!
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
actcs_=arg1
ang_=arg2
dist_=arg3
xdist_=arg4
ydist_=arg5
zpos_=arg6
sclf_=arg7
!
!
*if,sclf_,eq,0,then
    sclf_=10
*endif
!
csys,actcs_
!
*get,acs_,active,,csys                  ! axis coordinate system (CS)
*get,acstyp_,cdsy,acs_,attr,kcs         ! axis CS type
!
*if,acstyp_,ne,0,then                   ! If axis CS is not cartesian, then
    clocal,csn+10,0,0,0,0,0,0,0         ! create cartesian CS at same location.
    acs_=csn+10
*endif
!
cm,aset,area
!
max_enty_dim,'l'
!
lpln_=sclf_*max_leng
!
*if,dist_,eq,0,then
    *if,xdist_,ne,0,then
        flag_=1
        clocal,csn+11,1,xdist_,0,0,0,0,0
    *else
        *if,ydist_,ne,0,then
            flag_=1
            clocal,csn+12,1,0,ydist_,0,0,0,0
        *endif
    *endif
*endif
!
*if,dist_,lt,0,then
    *if,ang_,lt,90,then
        x_=abs(dist_)*cos((ang_-90)*rconv)
        y_=abs(dist_)*sin((ang_-90)*rconv)
    *else
        x_=-abs(dist_)*cos((ang_-90)*rconv)
        y_=-abs(dist_)*sin((ang_-90)*rconv)
    *endif
*elseif,dist_,gt,0,then
    *if,ang_,lt,90,then
        x_=abs(dist_)*cos((ang_+90)*rconv)
        y_=abs(dist_)*sin((ang_+90)*rconv)
    *else
        x_=-abs(dist_)*cos((ang_+90)*rconv)
        y_=-abs(dist_)*sin((ang_+90)*rconv)
    *endif
*else
    *if,flag_,ne,1,then
        xdist_=0
        ydist_=0
        x_=0
        y_=0
    *endif
*endif
!
*if,flag_,ne,1,then
    clocal,csn+13,1,x_,y_,0,0,0,0
*endif
!
k,,lpln_,ang_,zpos_
k,,-lpln_,ang_,zpos_
!
create_lines,,1
!
_lcut=lm
!
cmsel,s,aset
!
*get,_alow,area,,num,min
*get,_ahigh,area,,num,max
!
*do,_iii,_alow,_ahigh,1
    *if,_alow,eq,_ahigh,then
        _kdv='delete'
    *else
        *if,_iii,ne,_ahigh,then
            _kdv='keep'             ! keep/delete decision variable
        *else
            _kdv='delete'
        *endif
    *endif
    !
    *if,asel(_iii),eq,1,then
        asbl,_iii,_lcut,,delete,_kdv
    *endif
*enddo
!
*get,_ptyp,parm,_lcut,type
!
*if,_ptyp,eq,3,then
    ldele,_lcut,,,1
*endif
!
*if,_ptyp,ne,3,then
    *if,lsel(_lcut),ne,0,then
        ldele,_lcut,,,1
    *endif
*endif
!
csdele,csn+10,csn+13,1
init_entity_num
!
csys,actcs_
!
lplot
!
*set,actcs_,
*set,_kdv,
*set,_alow,
*set,_ahigh,
*set,_lcut,
*set,_iii,
*set,_ptyp,
*set,x_,
*set,y_,
*set,ang_,
*set,dist_,
*set,xdist_,
*set,ydist_,
*set,lpln_,
*set,acstyp_,
*set,acs_,
*set,flag_,
*set,zpos_,
cmdele,aset,
!
*if,prkey_,eq,1,then
    /go
*endif