Ansys Learning Forum › Forums › Discuss Simulation › General Mechanical › Automated Import of Load history data uisng scripts (Python or Mapdl) › Reply To: Automated Import of Load history data uisng scripts (Python or Mapdl)
January 26, 2024 at 11:23 am
user deleted
Subscriber
For anyone looking through this thread in the future
This is the code adapted to componentwise force import (in this case Y direction)
import csv
filePath = 'filepath\\force.csv'
timesteps = [] #Create empty list to store timestep values
loads = [] #Create empty list to store load values
with open(filePath, 'r') as csvFile:
  csvRead = csv.reader(csvFile, delimiter=',')
  next(csvRead) #Skip first line (assumed headers)
  Â
  for row in csvRead:
    timesteps.append(row[0]) #Populate list with first column's values
    loads.append(row[1]) #Populate list with second column's values
Â
#Configure lists
timeUnit = '[sec]' #Timestep unit
loadUnit = '[N]' #Load unit
timesteps = [str(time) + timeUnit for time in timesteps] #Convert values to strings and append unit
loads = [str(load) + loadUnit for load in loads] #Convert values to strings and append unit
#Create load
analysis_104 = DataModel.GetObjectById(207)
force_207 = DataModel.GetObjectById(207)
selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
selection.Ids = [23]
force_207.Location = selection
force_207.DefineBy = LoadDefineBy.ComponentY
force_207.YComponent.Inputs[0].DiscreteValues = [Quantity(time) for time in timesteps]
force_207.YComponent.Output.DiscreteValues = [Quantity(load) for load in loads]
Â
Don't forget to change the Ids!!
Also, I got the automation working these are resources for both after and before
Script Tip Friday - Examples of Python Results for Mechanical (Part 2) | Ansys Developer Portal
Script Tip Friday - Examples of Python Results for Mechanical (Part 1) | Ansys Developer Portal
Script Tip Friday- "Python Code"​ object in Mechanical | Ansys Developer Portal
Note these codes work when the mechanical GUI is open.
CheersÂ
Also, I got the automation working these are resources for both after and before
Script Tip Friday - Examples of Python Results for Mechanical (Part 2) | Ansys Developer Portal
Script Tip Friday - Examples of Python Results for Mechanical (Part 1) | Ansys Developer Portal
Script Tip Friday- "Python Code"​ object in Mechanical | Ansys Developer Portal
Note these codes work when the mechanical GUI is open.
CheersÂ