! ******************************
! $Revision: 145002 $
! $Date: 2009-11-13 11:20:27 -0500 (Fri, 13 Nov 2009) $
! ******************************
! macro MTparts ()

! *** primary function: Create components of each part in an assembly

! *** Notice - This file contains ANSYS Confidential information ***

!  input arguments: none

!  output arguments:
!   _SUCCESS            (int,sc)      =0 no success, =1 success


/nopr
_SUCCESS=1
fini
/prep7

cm,_facetk,kp
cm,_facetl,line
cm,_faceta,area
cm,_facetv,volu

! --- get areas unattached to volumes
*get,_nnv,volu,,count           ! Find out how many volumes there are
allsel,below,volu
asel,inve                       ! Select all areas not attached to a volume
cm,_iareas,area                 ! Make component out of independent areas
*get,_nnia,area,,count          ! Find out how many independent areas there are
cmsel,s,_facetk
cmsel,s,_facetl
cmsel,s,_faceta
cmsel,s,_facetv

! --- make area component out of each volume's areas
_NPARTS=0
*if,_nnv,ne,0,then              ! If number of volumes is not zero, then...
   _nv=-1
   *do,_i,1,_nnv                ! Loop on volumes
      _nv = vlnext(_nv)
      vsel,s,,,_nv              ! Select the volume and everything below
      aslv
      _NPARTS=_NPARTS+1
      cm,PART%_NPARTS%,area
      cmsel,s,_facetv           ! Reselect the original volume set
   *enddo
*endif

! --- make area component out of the unattached (independent) areas
!
! Loop through all independent areas and make components out of all areas that
! are connected.
*if,_nnia,ne,0,then             ! If there are independent areas, then...
   _na=-1                       ! reset area number pointer 
   *do,_i,1,_nnia               ! Loop on over all independent areas
      cmsel,s,_iareas           ! Select component of independent areas
      _na=arnext(_na)           ! Get next area in in selected set
      *if,_na,eq,0,exit         ! If area number equals zero, exit
      asel,s,area,,_na,,,1      ! Select area number
      *get,_acount1,area,,count ! initialize subcomponent area number
      *do,_j,1,_nnia            ! Loop over independent areas
         asll                   ! Select all areas attached to selected lines
         *get,_acount2,area,,count ! Get number of areas within new selected set
         *if,_acount2,eq,_acount1,exit   ! If number of areas in this new set is
                                         !   equal to counter, then...
         lsla
      *enddo
      _NPARTS=_NPARTS+1
      cm,PART%_NPARTS%,area
      asel,inve
      cmsel,r,_iareas
      cm,_iareas,area           ! Select component of all independent areas
   *enddo
*endif

cmsel,s,_facetk,kp
cmsel,s,_facetl,line
cmsel,s,_faceta,area
cmsel,s,_facetv,volu
cmdele,_facetk
cmdele,_facetl
cmdele,_faceta
cmdele,_facetv
cmsel,all
!!!cmgrp,ALLPARTS,PART1
!!!*if,_NPARTS,gt,1,then
!!!   *do,_i,2,_NPARTS
!!!      cmedit,ALLPARTS,add,PART%_i%
!!!   *enddo
!!!*endif

_acount1=
_acount2=
_na=
_nv=
_nnia=
_nnv=
_nva=
_i=
_j=
