


{"id":346757,"date":"2024-01-26T11:23:59","date_gmt":"2024-01-26T11:23:59","guid":{"rendered":"\/forum\/forums\/reply\/346757\/"},"modified":"2024-01-26T11:23:59","modified_gmt":"2024-01-26T11:23:59","slug":"346757","status":"publish","type":"reply","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/reply\/346757\/","title":{"rendered":"Reply To: Automated Import of Load history data uisng scripts (Python or Mapdl)"},"content":{"rendered":"<p>&lt;p&gt;For anyone looking through this thread in the future&lt;br&gt;&lt;br&gt;&lt;\/p&gt;&lt;p&gt;This is the code adapted to componentwise force import (in this case Y direction)&lt;\/p&gt;&lt;div&gt;import csv&lt;\/div&gt;&lt;div&gt;filePath = &#8216;filepath\\\\force.csv'&lt;\/div&gt;&lt;div&gt;timesteps = [] #Create empty list to store timestep values&lt;\/div&gt;&lt;div&gt;loads = [] #Create empty list to store load values&lt;\/div&gt;&lt;div&gt;with open(filePath, &#8216;r&#8217;) as csvFile:&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; csvRead = csv.reader(csvFile, delimiter=&#8217;,&#8217;)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; next(csvRead) #Skip first line (assumed headers)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp;&nbsp;&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; for row in csvRead:&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; timesteps.append(row[0]) #Populate list with first column&#8217;s values&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; loads.append(row[1]) #Populate list with second column&#8217;s values&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;#Configure lists&lt;\/div&gt;&lt;div&gt;timeUnit = &#8216;[sec]&#8217; #Timestep unit&lt;\/div&gt;&lt;div&gt;loadUnit = &#8216;[N]&#8217; #Load unit&lt;\/div&gt;&lt;div&gt;timesteps = [str(time) + timeUnit for time in timesteps] #Convert values to strings and append unit&lt;\/div&gt;&lt;div&gt;loads = [str(load) + loadUnit for load in loads] #Convert values to strings and append unit&lt;\/div&gt;&lt;div&gt;#Create load&lt;\/div&gt;&lt;div&gt;analysis_104 = DataModel.GetObjectById(207)&lt;\/div&gt;&lt;div&gt;force_207 = DataModel.GetObjectById(207)&lt;\/div&gt;&lt;div&gt;selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)&lt;\/div&gt;&lt;div&gt;selection.Ids = [23]&lt;\/div&gt;&lt;div&gt;force_207.Location = selection&lt;\/div&gt;&lt;div&gt;force_207.DefineBy = LoadDefineBy.ComponentY&lt;\/div&gt;&lt;div&gt;force_207.YComponent.Inputs[0].DiscreteValues = [Quantity(time) for time in timesteps]&lt;\/div&gt;&lt;div&gt;force_207.YComponent.Output.DiscreteValues = [Quantity(load) for load in loads]&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;Don&#8217;t forget to change the Ids!!&lt;br&gt;&lt;br&gt;&lt;br&gt;Also, I got the automation working these are resources for both after and before&lt;br&gt;&lt;br&gt;<a href=\"https:\/\/developer.ansys.com\/blog\/script-tip-friday-examples-python-results-mechanical-part-2\">Script Tip Friday &#8211; Examples of Python Results for Mechanical (Part 2) | Ansys Developer Portal<\/a>&lt;br&gt;&lt;br&gt;<a href=\"https:\/\/developer.ansys.com\/blog\/script-tip-friday-examples-python-results-mechanical-part-1\">Script Tip Friday &#8211; Examples of Python Results for Mechanical (Part 1) | Ansys Developer Portal<\/a>&lt;br&gt;&lt;br&gt;<a href=\"https:\/\/developer.ansys.com\/blog\/script-tip-friday-python-code-object-mechanical\">Script Tip Friday- &#8220;Python Code&#8221;\u200b object in Mechanical | Ansys Developer Portal<\/a>&lt;br&gt;&lt;br&gt;Note these codes work when the mechanical GUI is open.&lt;br&gt;&lt;br&gt;Cheers&nbsp;&lt;\/div&gt;<\/p>\n","protected":false},"template":"","class_list":["post-346757","reply","type-reply","status-publish","hentry"],"aioseo_notices":[],"acf":[],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies\/346757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/reply"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies\/346757\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=346757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}