How to export displacement results (deformed shape) in CSV/TXT from nodes in Named Selection

SIMple
Member Posts: 2
**
in Structures
How to export initial position and final displacement results (deformed shape) from my selected nodes in Named Selection and store them in text file?
Similar topics were already discussed:
https://ansyshelp.ansys.com/public/account/secured?returnurl=////////Views/Secured/corp/v242/en/act_script/act_script_examples_python_Export.html
Tagged:
0
Best Answer
-
Besides using the APDL commands, one possible way would be to add Python Code in Solution branch:
def after_solve(this, analysis): # Do not edit this line import mech_dpf import Ans.DataProcessing as dpf import os mech_dpf.setExtAPI(ExtAPI) dataSource = dpf.DataSources(analysis.ResultFileName) ScopingOp = dpf.operators.scoping.on_named_selection() ScopingOp.inputs.named_selection_name.Connect("MyNodeSelection".upper()) ScopingOp.inputs.data_sources.Connect(dataSource) MeshScoping = ScopingOp.outputs.mesh_scoping.GetData() # Get displacements for the scoped nodes displacements = dpf.operators.result.displacement() displacements.inputs.data_sources.Connect(dataSource) displacements.inputs.mesh_scoping.Connect(MeshScoping) disp = displacements.outputs.fields_container.GetData()[0] # Get Mesh information to retrieve node coordinates meshData = ExtAPI.DataModel.Project.Model.Analyses[0].MeshData nodeIds = disp.ScopingIds # Get node list from results # Create a list to store node data node_data = [] # Loop over nodes and collect data for nid in nodeIds: node = meshData.NodeById(nid) # Node data for nid nodeDisp = disp.GetEntityDataById(nid) # displacement from node nid node_data.append((nid, node.X, node.Y, node.Z, nodeDisp[0], nodeDisp[1], nodeDisp[2], node.X+nodeDisp[0], node.Y+nodeDisp[1], node.Z+nodeDisp[2])) # Sort the node data by ascending X coordinate node_data.sort(key=lambda x: x[1]) # Write sorted data to txt file in user_files directory from project outFileName = os.path.join(analysis.WorkingDir, 'exported_disp.txt') with open(outFileName, 'w') as f_out: f_out.write('# Node \t X\tY\tZ\tUX\tUY\tUZ\tdefX\tdefY\tdefZ\n') for data in node_data: f_out.write('\t'.join(map(str, data)) + '\n') pass
0