!   TITLE:  ln_profile_cut.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This command macro creates an line profile shape to cut selected volumes.
!
!
!   COMMAND SYNTAX:
!
!                          (1)    (2)
!        LN_PROFILE_CUT, dirovr, distf
!
!
!   ARGUMENTS:
!
!       (1) dirovr = the extrusion direction over-ride parameter:
!
!                   0 (or blank) = calculate direction based on volume
!                                  centroid.
!
!                   1 = opposite direction from calculated centroid.
!
!       (2) distf = distance factor. Must be an integer number > 0.
!
!
!   DESCRIPTION:
!
!   The selected lines are extruded to form a hollow closed surface. The surface
!   is extruded through a selected volume, or set of volumes, cutting the volumes
!   into two separate regions: volume segments interior to(or on one side of) the
!   surface profile, and volume segments exterior to(or on the other side of) the
!   surface profile.
!
!   The extrusion direction is calculated by the algorithm using the location
!   of the centroid of the selected volumes. If the automated direction choice
!   is not the desired direction, then simply placing a 1 in the first argument
!   will reverse the direction of extrude.  If the default extrusion distance is
!   not a sufficient distance, then the extrude distance may be increased by a
!   factor specified in argument 2. Otherwise, arguments 1 and 2 are unnecessary,
!   and are routinely left blank.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
dirovr_=arg1
distf_=arg2
!
*if,distf_,eq,0,then
    distf_=1
*else
    distf_=abs(nint(distf_))
*endif
!
*if,dirovr_,eq,0,then
    df_=distf_*10
*elseif,dirovr_,eq,1,then
    df_=-distf_*10
*endif
!
*get,acs1_,active,,csys
!
csys,0
!
cm,proflns_,line
cm,vset1_,volu
!
vsum
*get,vcx_,volu,,cent,x
*get,vcy_,volu,,cent,y
*get,vcz_,volu,,cent,z
k,,vcx_,vcy_,vcz_
!
init_entity_num
kvcent_=km
!
init_entity_num
!
cmsel,s,vset1_
!
cmsel,s,proflns_
*get,plcnt_,line,,count
ksll,s
!
get_max_entity
kstrt_=km
get_min_entity
*get,kcnt_,kp,k_min,nxth
!
cskp,csn+5,0,kcnt_,k_min,kstrt_
!
k,,kx(km),ky(km),df_*kz(kvcent_)
get_max_entity
!
lstr,kstrt_,km
get_max_entity
pthln_=lm
!
adrag,proflns_,,,,,,pthln_
ldele,pthln_,,,1
init_entity_num
!
asel,s,area,,am-(plcnt_-1),am
!
cm,newars_,area
!
init_entity_num
!
vsba,vset1_,newars_,,delete,delete
!
init_entity_num
!
kdele,kvcent_
init_entity_num
!
csdele,csn+5
csys,acs1_
!
lplot
!
!
*set,dirovr_,
*set,distf_,
*set,kstrt_,
*set,df_,
*set,acs1_,
*set,kvcent_,
*set,vcx_,
*set,vcy_,
*set,vcz_,
*set,plcnt_,
*set,pthln_,
cmdele,proflns_,
cmdele,vset1_
cmdele,newars_

*if,prkey_,eq,1,then
    /go
*endif