[S8507] Script to output a result table of nodes with nodal forces above the threshold value

 

The following is an example of a script that outputs a result table of nodes with nodal forces above the threshold.

# Specify the output file

output_path = r"D:/test.csv"

# Setting the threshold

threshold_value = 0.5

app = designer.GetApplication()

# Get the study being displayed

study = app.GetCurrentStudy()

# Create a probe to obtain the time history of nodal forces values.

objProbe = study.CreateProbe(u"Check")

# Flag indicating whether to perform automatic updates(0:OFF、1:ON)

objProbe.SetAutoRecalculate(0)

# Result Type

objProbe.SetResultType(u"NodalForce", u"")

# Reference Coordinate System

objProbe.SetResultCoordinate(u"Global Rectangular")

# Evaluation Coordinate System

objProbe.SetLocationCoordinate(u"Global Rectangular")

# Component

objProbe.SetComponent(u"Absolute")

# [Type] flag (0:By Coordinate、1:By Element ID)

objProbe.SetProbeType(1)

# Delete all positions.

objProbe.ClearPoints()

# Preparing to select nodes

view = app.View()

# Mesh display

view.ShowMesh()

# Change to node selection mode

view.SelectElementVertex()

# Deselect

view.ClearSelect()

# Get the number of all nodes

num_vertices = study.GetReport().NumVertices()

# List storing nodes that exceed the threshold

exceeding_nodes = []

for node_id in range(1, num_vertices + 1):

   # Set node number for probe

   objProbe.SetId(0, node_id)

   # Updating probe data

   objProbe.Build()

   # Get the point sequence data (DataSet) of the probe acquisition results.

   objData = objProbe.GetDataSet()

   objProbe.SetAutoRecalculate(0)

   flag_exceed = False

   # Time loop

   for val in objData.GetColumn(1):

       if val >= threshold_value:

           flag_exceed = True

           break  # Exit the loop when the threshold is exceeded

   # Add node IDs that exceed the threshold to the selection list.

   if flag_exceed:

       exceeding_nodes.append(node_id)

       # Select a node on the display screen.

       view.SelectByID(node_id)

if exceeding_nodes:

   # Create a result table for the selected nodes

   parameter = study.CreateTableDefinition()

   # Result Type

   parameter.SetResultType(u"NodalForce")

   # Coordinate System

   parameter.SetCoordinate(u"Global Rectangular")

   # Component

   parameter.SetComponent(u"Absolute")

   # Step

   parameter.SetAllSteps()

   # Include maximum/minimum values Information

   parameter.SetIsShownMinMaxInfo(False)

   # Include the Position information

   parameter.SetIsShownPositionInfo(True)

   # Output the file

   study.ExportTable(parameter, output_path, 0)

else:

   print(u"No nodes exceeding the threshold were found.")

How to use script file

Use the JMAG Script Library after reading and agreeing to the following terms of use.