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

! *** primary function: reset ENVDP and dim the results tab if remeshed

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

!  input arguments: none

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

/nopr
_SUCCESS=1

! --- debug
*if,_DEBUG,gt,0,then
!{
   /gopr
   *vwrite
   (' === MTchgmsh')
   *if,_DEBUG,lt,3,then
   !{
      /nopr
   !}
   *endif
!}
*endif

! delete any load transfer elements
cm,melem,elem
esel,s,real,,104
*get,_count,elem,,count
*if,_count,gt,0,then
   edele,all
*endif 
esel,s,real,,154
*get,_count,elem,,count
*if,_count,gt,0,then
   edele,all
*endif
! delete any contact elements
esel,s,ename,,174
*get,_count,elem,,count
*if,_count,gt,0,then
   esel,a,ename,,170
   edele,all
*endif 
cmsel,s,melem
cmdele,melem

! determine the active results file extension
*get,_strkey,active,,keyw,,PR_STRUC
*if,_strkey,eq,1,then
   _ext='rst'
   _ext2='rth'
*else
   _ext='rth'
   _ext2='rst'
*endif

! update the ENV statuses back to "ready to solve" from "solved" and
! delete the associated results files
*dim,_namep,char,4
*do,_env,1,_NUMENV
   _namep(1)=_ENVNAM(_env,1)
   _namep(2)=_ENVNAM(_env,2)
   _namep(3)=_ENVNAM(_env,3)
   _namep(4)=_ENVNAM(_env,4)
   mtrmspc
   _n1=_namep(1)
   _n2=_namep(2)
   _n3=_namep(3)
   _n4=_namep(4)
   *if,_ENVDP(_env),ge,3,then
      _ENVDP(_env)=1
      /inquire,_exist,'EXIST','%_n1%%_n2%%_n3%%_n4%',%_ext%
      *if,_exist,gt,0,then
         /del,'%_n1%%_n2%%_n3%%_n4%',%_ext%
      *endif
   *endif
   *if,_ENVDP2(_env),ge,3,then
      _ENVDP2(_env)=1
      /inquire,_exist,'EXIST','%_n1%%_n2%%_n3%%_n4%',%_ext2%
      *if,_exist,gt,0,then
         /del,'%_n1%%_n2%%_n3%%_n4%',%_ext2%
      *endif
   *endif
*enddo

! dim the results tab
_calleui=1
*get,_env,active,,keyword,,MECHTOOL      ! get MECHTOOL key
*if,_env,eq,0,then
   _calleui=0                          ! MECHTOOL not active, no eui calls
*endif
*get,_env,active,,int                    ! get interactive key
*if,_env,eq,0,then
   _calleui=0                          ! not interactive, no eui calls
*endif
*if,_calleui,eq,1,then
   ~eui,'euidl::mechtool::updateTabs resultstab 0'
*endif
*if,_DEBUG,gt,0,then
   /gopr
   /com, === leave MTchgmsh
*endif

! delete local variables
*del,_env
*del,_calleui
*del,_strkey
*del,_ext
*del,_ext2
*del,_namep
*del,_n1
*del,_n2
*del,_n3
*del,_n4
