Build load table with ACT/Mechanical Scripting

Options
M
M Member, Employee Posts: 230
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited January 23 in Structures

There are limited methods to build/retrieve table data in Mechanical that will work in both Windows and Linux.
Below is an example of building a force load boundary condition that is operating system independent.

The example is generalized for a force boundary condition to demo how to fill in the X,Y,Z table components. Other bcs that are not 3d should be simpler but follow the same method.

tmax = 4
t = [1,2,3,4]
xloads = [1,2,3,4]
yloads = [5,6,7,8]
zloads = [1234,5678,91011,12]
loadUnit = '[N]' #Load unit
load_named_selection = "loadFace"

# convert time to quantity
timeUnit = '[sec]' #Timestep unit
timesteps = [str(time) + timeUnit for time in t]

# convert load to quantity
xloads = [str(load) + loadUnit for load in xloads]
yloads = [str(load) + loadUnit for load in yloads]
zloads = [str(load) + loadUnit for load in zloads]

# Set Analysis 
analysis = ExtAPI.DataModel.Project.Model.Analyses[0] # refer to analysis
analysis.AnalysisSettings.NumberOfSteps = tmax

# Create boundary condition
my_bc = analysis.AddForce() # add boundary condition
my_bc.DefineBy = LoadDefineBy.Components

my_bc.Location = ExtAPI.DataModel.GetObjectsByName(load_named_selection)[0] 
my_bc.XComponent.Inputs[0].DiscreteValues =  [Quantity(time) for time in timesteps] 
my_bc.XComponent.Output.DiscreteValues=[Quantity(load) for load in xloads]

my_bc.YComponent.Inputs[0].DiscreteValues =  [Quantity(time) for time in timesteps] 
my_bc.YComponent.Output.DiscreteValues=[Quantity(load) for load in yloads]

my_bc.ZComponent.Inputs[0].DiscreteValues =  [Quantity(time) for time in timesteps] 
my_bc.ZComponent.Output.DiscreteValues=[Quantity(load) for load in zloads]`