My goal is to select a node in the geometry window in Mechanical and then retrieve the six stress components for that node with a script.
You can use DPF to retrieve the stress components for a selected node. Here's an example workflow to do this:
Import and initialise the DPF modules:
import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI)
Select the node of interest by graphically picking it in the geometry window before executing the script. The following line will retrieve the node ID for that node:
node_id = ExtAPI.SelectionManager.CurrentSelection.Ids
Use the following script to specify the data source:
analysis = ExtAPI.DataModel.Project.Model.Analyses[0] filepath = analysis.ResultFileName dataSources = dpf.DataSources() dataSources.SetResultFilePath(filepath) model=dpf.Model(dataSources)
Specify the scoping particulars:
my_scoping = dpf.Scoping() my_scoping.Ids = node_id my_scoping.Location = 'Nodal'
Create a field container for stress and use the scoping specified above:
stress_fc = dpf.operators.result.stress() stress_fc.inputs.data_sources.Connect(dataSources) stress_fc.inputs.mesh_scoping.Connect(my_scoping) stress_field = stress_fc.outputs.fields_container.GetData()[0]
stress_field.Data will return a list containing [SX, SY, SZ, SXY, SYZ, SXZ]
stress_field.Data