!   TITLE:  kp_intersect.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This sub-macro retrieves the keypoint at the intersection of a specified
!   set of lines. This intersection keypoint (IKP) is output in the variable:
!
!                       ikp_ = intersection keypoint number.
!
!
!   COMMAND SYNTAX:
!
!                                  (1)   (2)   (3)   (4) . . . . (15)
!       OPTION 1:   KP_INTERSECT, ln_1, ln_2, ln_3, ln_4,......, ln_15
!
!                                    (1)
!       OPTION 2:   KP_INTERSECT, ln_CG_name
!
!       OPTION 3:   KP_INTERSECT
!
!
!   ARGUMENTS:
!
!       OPTION 1:   (N=1...15) ln_N = line #N.
!
!       OPTION 2:   (1) ln_CG_name = name of component group containing
!                                    selected lines. The remaining arguments
!                                    (2...15) left blank.
!
!       OPTION 3:   (N=1...15) ln_N = all arguments left blank. The current
!                                     selected set of lines are used.
!
!
!   DESCRIPTION:
!
!   The IKP is one end keypoint for the specified set of lines. This information
!   may be used for various solid modeling operations.
!
!   There are 3 options available for specifying the lines in this macro:
!
!       (1) Enter the line numbers directly into the arguments. Up to 15
!           lines may be specified.
!
!       (2) If the lines exist in a component group, the name of the group
!           may be specified in the 1st argument. The remaining arguments
!           may be left blank. This option may be used if more than 15 lines
!           are to be specified.
!
!       (3) If the desired lines are currently selected in the database, then
!           simply executing this macro with no arguments specified will
!           determine the IKP.
!
!
*get,prkey_,active,0,prkey
/nopr
!
!
*do,ijk_,1,15,1
    *if,ijk_,le,9,then
        *get,argtyp_,parm,arg%ijk_%,type
        !
        *if,argtyp_,eq,0,then
            *if,arg%ijk_%,gt,0,then
                *if,ijk_,eq,1,then
                    lsel,s,line,,arg%ijk_%
                *elseif,ijk_,gt,1,then
                    lsel,a,line,,arg%ijk_%
                *endif
            *else
                *exit
            *endif
        *elseif,argtyp_,eq,3,then
            cmsel,s,arg%ijk_%,line
            *exit
        *endif
    *elseif,ijk_,gt,9,then
        *if,ar%ijk_%,gt,0,then
            lsel,a,line,,ar%ijk_%
        *else
            *exit
        *endif
    *endif
*enddo
!
!
entity_array,'l','lngrp_','array',2
lncnt_=ecount
!
!
cm,lingrp_,line
ksll,s
entity_array,'k','kgrp_','array',,,lncnt_+2
nkp_=ecount
!
!
*do,ijk_,1,nkp_,1
    cmsel,s,lingrp_
    ksel,s,kp,,kgrp_(ijk_,1)
    lslk,r,0
    entity_array,'l','lnhold_','array',2
    nlnkp_=ecount
    !
    arry_transfer,'lnhold_','kgrp_',,,,,,,ijk_,3
    kgrp_(ijk_,2)=nlnkp_
    !
    *set,lnhold_(1),
*enddo
!
arry_max_val,'kgrp_',,,2,2
!
ikp_=kgrp_(max_ir,1)
!
init_entity_num
!
lplot
!
*set,ijk_,
*set,argtyp_,
*set,nkp_,
*set,max_val,
*set,max_ir,
*set,max_ic,
*set,max_ip,
*set,lngrp_(1),
*set,kgrp_(1),
cmdele,lingrp_
!
*if,prkey_,eq,1,then
    /go
*endif