! ************************* REV52 *********************************** !
!                          SWITCH2D.MAC                               ! 
!        Macro to Switch a Pro/ENGINEER 3D shell model on the xy      !
!                      plane to a 2D analysis                         !
!                      PHB September 20, 1993                         !
! Last Modified:                                                      !
!                 
! 12/30/93  - CJK. Also modify Z coordinate to be zero, for submodeling.    
! 12/30/93  - CJK. If axisymm, and thetamin=thetamax, set theta to zero.
!  1/23/93  - CJK. Added checks for non-zero node rotations in YZ and ZX.
!  2/01/94  - CJK. Added error flag. Do all error checks, then exit if error.
!  6/27/94  - CJK. Added checks for node rotations that are factor of 180.
!                  These are legal node rotations for a 2d analysis.
!  2/5/95   - RWG. Added logic to  handle tri/quad shell meshes from pro/e 14
!  9/20/95  - RWG. removed rev4 command
!
!                                                                     !
! This macro is to be issued at the end of a Pro/ENGINEER /prep7 batch!
! input file.                                                         !
!                                                                     !
! Usage:  SWITCH2D,,,ARG3                                             !
!                                                                     !
!  where      ARG3 = 1     sets keyopt(3)=1       AXISYMMETRIC
!             ARG3 = 2     sets keyopt(3)=2                           !
!             ARG3 = 3     etc.                                       !
!             ARG3 = 4                                                !
!                                                                     !
! ******************************************************************* !
!                                                              
!/nopr                          ! Suppress command echo 
e2dpars=82                     !keyopt 3=3 for 2D, 3=1 for axisymmetric
e3dpars=93
e2dlins=42                     !keyopt 3=3 for 2D, 3=1 for axisymmetric
e3dlins=63
! e2dpart= 77
! e3dpart= 00                  !ANSYS doesn't have one
e2dlint= 55                    !keyopt 3=1 for axisymmetric
e3dlint= 57

nummrg,type
*get,elmnum,elem,0,nxth
*get,etnum,elem,elmnum,attr,type
type,etnum

_small_z=1e-02   ! small numbers to use when comparing global Z 
_small_t=.5      ! and angular coordinates. This should be a percentage
                 ! of the overall model dimensional size, instead of
                 ! hard-coded number.
!
_err=0   ! error flag, if 1 terminate run.

csys,0       ! added fix
*get,zmax,node,,mxloc,z
*get,zmin,node,,mnloc,z

*get,xmax,node,,mxloc,x
*get,xmin,node,,mnloc,x
*get,ymax,node,,mxloc,y
*get,ymin,node,,mnloc,y

*get,etnum,active,,type
*get,elmnum,etyp,etnum,attr,enam

!
! +++++++++++ AXISYM +++++++++++++++++
!
*if,arg3,eq,1,then
  !
  RDEL,ALL
  !
  ! special check for axisymmetric structure
  ! assumes user at least has Y axis along axis of structure,
  ! and proper radial location. Just doesn't quite have
  ! the cut setup in the XY plane.
  !

  LOCAL,21,1,0,0,0,0,-90,0
  *get,tmax,node,,mxloc,y
  *get,tmin,node,,mnloc,y

    *if,abs(tmin-tmax),le,_small_t,then
      LOCAL,20,0,0,0,0,0,0,(tmin+tmax)/2
      TRANS,0,0,ALL
      csys,0     
      ! csdel,20,21
      ! do not delete local csys since they
      ! can be useful in post-processing.
      !
      *get,zmax,node,,mxloc,z
      *get,zmin,node,,mnloc,z
    *endif
 csys,0
*endif

/nopr
*if,elmnum,eq,e3dpars,then
  ettrue=1
  *elseif,elmnum,eq,e3dlins
  ettrue=1
  *elseif,elmnum,eq,e3dlint
  ettrue=1
  *else
  ettrue=0
*endif

! Check to see if zmin=zmax
! Comparing to small number.
*if,abs(zmin-zmax),gt,_small_z,then
  /go
  /com
  *msg,WARN
*** ERROR *** %/ Cannot switch analysis from 3D to 2D.  All nodes must have the&
same Z value. Specify the proper CSYS in the 'Run Study -> Options' menu. %/
  /nopr
  _err=1
!
! Check to determine what plane the mesh is in.
!
 *if,abs(xmin-xm