!   TITLE:  profile_bore.mac (SM_TOOL)
!
!
!
!   This sub-macro is used to create a circular bore with a particular
!   profile which is to be subtracted out, thereby creating a special
!   shaped cavity in the selected volume. This volume may be a combination
!   series of bores and chamfers at varying angle sections or at 90 degree
!   intervals if preferred.
!
!   Parameters needed to be passed to this macro are:
!
!       A selected volume set
!
!       output from (in order):
!
!               ANG_ARRAY.MAC
!               RADIUS.MAC
!               DEPTH.MAC
!
!       opt = input options: 1,2 or 3
!
!       p1 = c.s. origin keypoint
!       p2 = c.s. +x axis keypoint
!       p3 = c.s. +y axis keypoint
!
!       xcutc = x component of cut volume local c.s.
!       ycutc = y component of cut volume local c.s.
!       zcutc = z component of cut volume local c.s.
!       rotxyc = 1st orientation angle (+x to +y) of 'reccutcs' c.s.
!       rotyzc = 2nd orientation angle (+y to +z) of 'reccutcs' c.s.
!       rotzxc = 3rd orientation angle (+z to +x) of 'reccutcs' c.s.
!
!       acs1= pre-existing Active Coordinate System
!
!   The position and orientation of the volume cut c.s. is measured in
!   relation to the active c.s. for option 1. From this c.s., the local
!   coordinate system building this volume is placed. Option 2 allows
!   construction of the cut volume from a c.s. defined by 3 KP's. Lastly,
!   option 3 allows construction from a pre-existing c.s., acs1.  acs1
!   must be a cylindrical c.s.
!
!   The 3 options of input data are summarized as follows:
!
!       1.  Create local c.s. by CLOCAL, input:
!               xcutc, ycutc, zcutc, rotxyc, rotyzc, rotzxc
!
!
!       2.  Create local c.s. by CSKP, input:
!               p1, p2, p3
!
!
!       3.  Use pre-existing c.s., input: acs1
!
!
!
! PROFILE_BORE,opt,xcutc,ycutc,zcutc,rotxyc,rotyzc,rotzxc
!
!
! PROFILE_BORE,opt,p1,p2,p3
!
!
! PROFILE_BORE,opt,acs1
!
!
*get,prkey_,active,0,prkey
/nopr

cm,v2bcut,volu      ! selected volume to be (2b) cut
!
opt=arg1
!
!
*if,opt,eq,1,then
    xcutc=arg2
    ycutc=arg3
    zcutc=arg4
    !
    rotxyc=arg5
    rotyzc=arg6
    rotzxc=arg7
*endif
!
*if,opt,eq,2,then
    p1=arg2
    p2=arg3
    p3=arg4
*endif
!
*if,opt,eq,3,then
    acs1=arg2
*endif
!
!
*if,opt,eq,1,then
    create_cs,0,'circutcs',1,xcutc,ycutc,zcutc,rotxyc,rotyzc,rotzxc
*endif
!
*if,opt,eq,2,then
    create_cs,1,'circutcs',1,p1,p2,p3
*endif
!
*if,opt,eq,3,then
    csys,acs1
*endif
!
!
num_lns=num_pnt
!
k,,0,0,0
!
*do,i,1,(num_pnt-1),1
    !
    k,,rad(i,1),ang(1,1),-z_(i,1)
*enddo
!
k,,0,0,-z_(num_pnt,1)
!
get_max_entity
!
*do,i,1,num_lns,1
    !
    lstr,km-(num_lns-(i-1)),km-(num_lns-i)
*enddo
!
lstr,km,km-(num_lns)
!
ap1=km-(num_lns)
ap2=km
!
get_max_entity
!
lsel,selv,line,,lm-(num_lns),lm
!
al,all
!
init_entity_num
!
asel,u,area,,all
!
asel,s,area,,am
!
*do,i,1,(num_ang),1
    !
    asel,r,loc,y,ang(i,1)
    !
    get_max_entity
    !
    *if,i,ne,num_ang,then
        ang_diff,ang(i,1),ang(i+1,1)
        vrotat,am,,,,,,ap1,ap2,d_angle,1
    *else
        ang_diff,ang(i,1),ang(1,1)
        vrotat,am,,,,,,ap1,ap2,d_angle,1
    *endif
*enddo
!
init_entity_num
!
vsel,s,volu,,vm-(num_ang-1),vm,1
!
vadd,all
!
init_entity_num
!
vsbv,v2bcut,vm,,delete,delete
!
init_entity_num
!
lplot
!
*set,xcutc, ! undefine parameters
*set,ycutc,
*set,zcutc,
*set,opt,
*set,acs1,
*set,rotxyc,
*set,rotyzc,
*set,rotzxc,
*set,ang(1),
*set,d_angle,
*set,z_(1),
*set,rad(1),
*set,xx,
*set,delta,

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