*PYTHON

New APDL command available from ANSYS 2025R1 – *PYTHON – , see https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v251/en/ans_cmd/Hlp_C_PYTHON_a.html

In the below example we do the following:

  1. Copy/Paste the .rst file somewhere outside the project folder. Here: c:\temp\file.rst
  2. Add a Commands Object under Solution
  3. APDL: Extract node ID and UY (Directional Deformation Y) for each node.
  4. Place node ID and UY in a nnode (number of nodes) x2 array.
  5. Initiate python with the *PYTHON command
  6. Python: Convert APDL parameters (nnode and res (array with node id and uy(node id))) to a python integer and a python list.
  7. PyDPF-Core: Create a scalar field, populate it with the mesh and corresponding values
  8. Plot the solution!

Transparent

!   Commands inserted into this file will be executed immediately after the ANSYS /POST1 command.

!   Active UNIT system in Workbench when this object was created:  Metric (m, kg, N, s, V, A)
!   NOTE:  Any data that requires units (such as mass) is assumed to be in the consistent solver unit system.
!                See Solving Units in the help system for more information.
! ___________________________ ! 
! ___________ APDL __________ !
!!                            !!

/post1
set,last
*get,nnode,node,,count!______ passed to python _____ !
*dim,res,,nnode,2 !______ passed to python _____ ! 
nn = ndnext(0)
*do,i,1,nnode
res(i,1) = nn
res(i,2) = uy(nn)
nn = ndnext(nn)
*enddo
allsel

*python
import ansys.dpf.core as dpf
from ansys.dpf.core import operators as ops
import csv
import numpy
res_py = list()

# ___________________________________________________#
# ___________ APDL parameters ---> Python __________ #
##                                                   ##

nnode_ = int(mapdl.parameters['nnode']) # ______ from APDL _____#
id_val = mapdl.parameters['res']# ______ from APDL _____ #
id_ = id_val[:,0]
val_ = id_val[:,1]

#with open(r'C:\temp\apdl_python.csv','w') as file_:
#    file_.write("Node Number, Value" + "\n")
#    for i in range(nnode_):
#        file_.write(str(int(id_[i]))+ "," + str(val_[i]) + "\n")

#___________________________________#
# ___________ PyDPF-Core __________ #
##                                  ##

rst = r'C:\temp\file.rst'
model = dpf.Model(rst)
mesh_ = model.metadata.meshed_region

# create a field 
result_field= dpf.fields_factory.create_scalar_field(nnode_,dpf.locations.nodal)
for i in range(0,nnode_): 
    result_field.append(float(val_[i]),int(id_[i]))
result_field.meshed_region = mesh_

result_field.plot()
*endpy