!   TITLE:  nd_dist_calcs.mac (CALCULATION)
!
!
!   TOOLBAR MACRO
!
!   OBJECTIVE:
!
!   This GUI command macro calculates the linear distances between 2 nodes.
!
!
!   ARGUMENTS:
!
!           1st prompt:     acs = active coordinate system to measure axial
!                                 distance in.
!
!                           Node numbers to measure distance between:
!
!                                   ND1 and ND2
!
!           NOTE: If the input boxes for node numbers in the dialogue box are
!                 left to their default values of 0, then graphical picking is
!                 enabled. In this case, the user must select exactly 2 nodes
!                 only.
!
!   DESCRIPTION:
!
!   This macro calculates the linear (cartesian) distances between 2 nodes.
!   These distances are measured in all 3 axial directions: Dx, Dy and Dz, and the
!   absolute linear distance between them, Dabs. The distances are calculated rel-
!   ative to a desired user-specified coordinate system.
!
!   If the specified coordinate system is not cartesian, then the distance calcu-
!   lations are measured along the oriented axial directions of that coordinate
!   system as if it were cartesian. Therefore, a cartesian coordinate system need
!   not be created or specified as long as the axial directions of the specified
!   coordinate system are oriented as desired.
!
!   If the desired coordinate system is the current active coordinate system, then
!   simply pressing the ENTER key will suffice, since the default coordinate
!   system value activated by the user prompt is the current active coordinate
!   system. If the specified coordinate system is different from the current active
!   coordinate system, the calculations will be performed and the current active
!   coordinate system will be restored.
!
!   All output is to a screen dialog box.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
entity_group
!
*get,acs1_,active,,csys
!
grphpic_=0
!
multipro,'start',4
    *cset,1,3,csnum_,'COORDINATE SYSTEM #',acs1_
    *cset,4,6,prec_,'Decimal Precision of Output',4
    *cset,7,9,nd_1st,'Enter 1st Node',0
    *cset,10,12,nd_2nd,'Enter 2nd Node',0
    *cset,61,62,'Calculates the X,Y,Z and abs','olute (linear) distance'
    *cset,63,64,'between 2 nodes. Enter',' the node numbers.'
multipro,'end'
!
*if,nd_1st,eq,0,then
    *if,nd_2nd,eq,0,then
        /ui,nsel
        get_min_entity
        get_max_entity
        !
        *get,ncount_,node,,count
        !
        nd_1st=n_min
        nd_2nd=nm
        !
        grphpic_=1
    *endif
*endif
!
*if,grphpic_,eq,0,then
    nd1_=nsel(nd_1st)
    nd2_=nsel(nd_2nd)
    !
    *if,nd1_,eq,1,then
        *if,nd2_,eq,1,then
            ncount_=2
        *else
            ncount_=1
        *endif
    *else
        *if,nd2_,eq,1,then
            ncount_=1
        *else
            ncount_=0
        *endif
    *endif
*endif
!
*if,ncount_,eq,2,then
    csys,csnum_
    !
    *get,csnumtyp,cdsy,csnum_,attr,kcs
    !
    *if,csnumtyp,ne,0,then
        clocal,csn+1,0,0,0,0,0,0,0
        csnum_=csn+1
    *endif
    !
    *if,nd_1st,ne,0,then
        *if,nd_2nd,ne,0,then
            *if,prec_,le,0,then
                prec_=4
            *endif
            !
            tol_=10**(-prec_-1)
            !
            dx__=abs(nx(nd_1st)-nx(nd_2nd))
            !
            *if,abs(dx__),lt,tol_,then
                dx__=0
            *else
                *if,abs(dx__),ge,(10*tol_),then
                    round_num,dx__,prec_
                *else
                    round_num,dx__,prec_+1
                *endif
                !
                dx__=num_
            *endif
            !
            dy__=abs(ny(nd_1st)-ny(nd_2nd))
            !
            *if,abs(dy__),lt,tol_,then
                dy__=0
            *else
                *if,abs(dy__),ge,(10*tol_),then
                    round_num,dy__,prec_
                *else
                    round_num,dy__,prec_+1
                *endif
                !
                dy__=num_
            *endif
            !
            dz__=abs(nz(nd_1st)-nz(nd_2nd))
            !
            *if,abs(dz__),lt,tol_,then
                dz__=0
            *else
                *if,abs(dz__),ge,(10*tol_),then
                    round_num,dz__,prec_
                *else
                    round_num,dz__,prec_+1
                *endif
                !
                dz__=num_
            *endif
            !
            dabs__=distnd(nd_1st,nd_2nd)
            !
            *if,abs(dabs__),lt,tol_,then
                dabs__=0
            *else
                *if,abs(dabs__),ge,(10*tol_),then
                    round_num,dabs__,prec_
                *else
                    round_num,dabs__,prec_+1
                *endif
                !
                dabs__=num_
            *endif
            !
*msg,ui,%nd_1st%,%nd_2nd%,%dx__%,%dy__%,%dz__%,%dabs__%
Distance Between Node #'s ( %i , %i ) : %/&
%/&
Dx = %g %/&
Dy = %g %/&
Dz = %g %/&
%/&
Dabs = %g
            !
            *if,csnumtyp,ne,0,then
                csdele,csnum_
            *endif
            !
            csys,acs1_
            !
            *set,acs1_,
            *set,csnum_,
            *set,csnumtyp,
            *set,dx__,
            *set,dy__,
            *set,dz__,
            *set,dabs__,
            *set,tol_,
        *endif
    *endif
*elseif,ncount_,gt,2,then
*msg,warn
Too Many Nodes Picked. Must Select 2 Nodes Only.
*elseif,ncount_,lt,2,then
*msg,warn
Not Enough Nodes Picked. Must Select 2 Nodes Only.
*endif
!
entity_group,1
!
*set,grphpic_,
*set,nd1_,
*set,nd2_,
*set,nd_1st,
*set,nd_2nd,
*set,prec_,
*set,ncount_,
!
*if,prkey_,eq,1,then
    /go
*endif