Using Python to define ANSYS Workbench Parameters
Using Python to define ANSYS Workbench Parameters
(OP)
Hello everybody,
I am creating a python script to run ANSYS Mechanical files for numerous load cases. So far I have managed to set the python script up to create a input journal within ANSYS which creates and changes certain loads and geometries associated with that load case. At present all of my variables are defined by Parameters and read through the python file from ANSYS.
Part of that study looks at varying the preload in a bolt, obtaining an average stress from a path, then applying a force and obtaining the average stress again. The difference between average stresses will be used as part of a study. I know I can create a CSV file to extract the results that I require, however what I am stuck on is how to use python (or ANSYS commands) to vary the initial preload in the study and then apply a load after this. Unfortunately I cannot define bolt preload using the parameters or specify a load to be applied after this.
Can anyone point me in the direction of the coding or method to use to alter the preload on the bolt and then apply a load on the load step after this.
Thanks
I am creating a python script to run ANSYS Mechanical files for numerous load cases. So far I have managed to set the python script up to create a input journal within ANSYS which creates and changes certain loads and geometries associated with that load case. At present all of my variables are defined by Parameters and read through the python file from ANSYS.
Part of that study looks at varying the preload in a bolt, obtaining an average stress from a path, then applying a force and obtaining the average stress again. The difference between average stresses will be used as part of a study. I know I can create a CSV file to extract the results that I require, however what I am stuck on is how to use python (or ANSYS commands) to vary the initial preload in the study and then apply a load after this. Unfortunately I cannot define bolt preload using the parameters or specify a load to be applied after this.
Can anyone point me in the direction of the coding or method to use to alter the preload on the bolt and then apply a load on the load step after this.
Thanks





RE: Using Python to define ANSYS Workbench Parameters
Hopefully this is what you're after:
CODE --> Python
ExtAPI.DataModel.Project.Model.Analyses[0].AnalysisSettings.NumberOfSteps = 2 bolt = ExtAPI.DataModel.Project.Model.Analyses[0].AddBoltPretension() bolt.Location = ExtAPI.DataModel.Project.Model.NamedSelections.Children[2] bolt.SetDefineBy(1,Ansys.ACT.Automation.Mechanical.Enums.BoltLoadDefineBy.Load) bolt.SetDefineBy(2,Ansys.ACT.Automation.Mechanical.Enums.BoltLoadDefineBy.Lock) bolt.Preload.Output.DiscreteValues = [Quantity('10[N]'), Quantity('20[N]')] # second value useless myf = ExtAPI.DataModel.Project.Model.Analyses[0].AddForce() myf.Magnitude.Inputs[0].DiscreteValues= [Quantity('0[sec]'), Quantity('1[sec]'),Quantity('2[sec]')] myf.Magnitude.Output.DiscreteValues=[Quantity('0[N]'), Quantity('0[N]'), Quantity('10[N]')] myf.Location = ExtAPI.DataModel.Project.Model.NamedSelections.Children[0]I'm a beginner at using Python in Mechanical. Here's a blog post on it: http://www.ansystips.com/2017/06/act-console.html.
Best Regards,
Jason
RE: Using Python to define ANSYS Workbench Parameters
Thanks for your reply. Te code looks relatively simple and straight forward, however I am having difficulties with the ExtAPI - is there a specific module I should install in python?
I am pretty new to python so everything is a little.... slow
Andy
RE: Using Python to define ANSYS Workbench Parameters
I know it can be accessed through ACT console and ACT inside Mechanical (previous reply). I'm not aware of how to access it from outside of Ansys. Sorry, I'm no help here.
Best regards,
Jason
RE: Using Python to define ANSYS Workbench Parameters
Thanks for your help!
Andy