Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Python to define ANSYS Workbench Parameters

Status
Not open for further replies.

andy5powell

Structural
Joined
Feb 11, 2013
Messages
10
Location
GB
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
 
Hi Andy,

Hopefully this is what you're after:
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: [URL unfurl="true"]http://www.ansystips.com/2017/06/act-console.html[/url].


Best Regards,
Jason
 
Hi Jason,

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
 
Hi Andy,

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

 
No problem Jason,

Thanks for your help!

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top