!   TITLE:  init_entity_num.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This sub-macro is used to update solid and FE model entity numbers,
!   and initialize all newly created entity numbers from these maximums.
!
!
!   COMMAND SYNTAX:
!
!                          (1)
!       INIT_ENTITY_NUM, all_sel
!
!
!   ARGUMENTS:
!
!       (1) all_sel = parameter defining the option to select current
!                     solid model entities or entire assembly of models
!                     entities:
!
!               0 (or blank) = select only current solid model entities.
!
!               1 = select all solid model entities in the assembly.
!
!
!   DESCRIPTION:
!
!   This sub-macro accomodates all solid/FE model parametric operations. It
!   eliminates the use of any numbering "holes" in the sequence that may have
!   been created by boolean operations, thereby allowing total parameterization
!   to be manageable.
!
!   It retrieves the maximum numbers of all solid/FE model entities in the
!   database, and initializes any newly created (or deleted) entity numbers,
!   as a result of any subsequent modeling operations, from the retrieved
!   maximum values.
!
!   Ater retrieving the maximums and initializing the new entity numbers,
!   it will either select only the current solid model entities (the current
!   part under construction in an assembly), or select all entities of all
!   models in the database (assembly). The option between these 2 functions
!   is controlled by the argument, 'all_sel'.
!
!   This sub-macro should ONLY be used when the number maximums and initial-
!   izations are desired from the entire database set. For retrieving the
!   maximum entity numbers from within a selected set of entities, the
!   'GET_MAX_ENTITY' macro should be used.
! 

*get,prkey_,active,0,prkey
/nopr
!
/prep7
!
km_prev=km              ! store previous entity maximums
lm_prev=lm
am_prev=am
vm_prev=vm
em_prev=em
nm_prev=nm
!
allsel,all
!
*get,km,kp,,num,max     ! store current maximum entity numbers
numstr,kp,km            ! initialize entity numbers from current max values
!
*get,lm,line,,num,max
numstr,line,lm
!
*get,am,area,,num,max
numstr,area,am
!
*get,vm,volu,,num,max
numstr,volu,vm
!
*get,em,elem,,num,max
numstr,elem,em
!
*get,nm,node,,num,max
numstr,node,nm
!
*if,arg1,eq,0,then
    *if,kp_pssof,gt,0,then
        ksel,u,kp,,_kset_
    *endif
    !
    *if,ln_pssof,gt,0,then
        lsel,u,line,,_lset_
    *endif
    !
    *if,ar_pssof,gt,0,then
        asel,u,area,,_aset_
    *endif
    !
    *if,vl_pssof,gt,0,then
        vsel,u,volu,,_vset_
    *endif
    !
    *if,el_pssof,gt,0,then
        esel,u,elem,,_eset_
    *endif
    !
    *if,nd_pssof,gt,0,then
        nsel,u,node,,_ndset_
    *endif
*elseif,arg1,eq,1,then
    allsel,all
*endif
!
*if,prkey_,eq,1,then
    /go
*endif