How to execute a Mechanical script by inserting it as a command snippet
Hello All,
We have a script which records the modal natural frequencies and update the harmonic user defined frequencies. Now the problem is this script is mechanical script and we need to run it automatically by inserting it as a command snippet, so when we run a DOE each time this scripts runs automatically. How can I use this mechanical script as a command snippet, note that we are running a full method harmonic, we are not connecting the modal solution to the harmonic analysis but model will be shared.
Best Answers
-
Hi
As promised below is another idea/way that might be also easier.
So as you say, model is shared but full method is used (see below).
A python code (after post) object (uses Mechanical ACT script commands as shown below) will transfer the user defined frequencies from modal to harmonic (full)).
For this to be updated (design point study) we need to go to WB Tools -> Options - > Mechanical and tick the box to Reconnect Python Code Objects....
Python code:
def after_post(this, solution):# Do not edit this line """ Called after post processing. Keyword Arguments : this -- the datamodel object instance of the python code object you are currently editing in the tree solution -- Solution """ freq=[] manalysis = ExtAPI.DataModel.Project.Model.Analyses[0] reader = manalysis.GetResultsData() freq=reader.ListTimeFreq harmonic_analysis = ExtAPI.DataModel.Project.Model.Analyses[1] harmo_settings = harmonic_analysis.AnalysisSettings harmo_settings.UserDefinedFrequencies = True # activate User Defined Frequencies harmo_settings.UserDefinedFrequencySteps = [Quantity(str(freq[0]) +'[Hz]'), Quantity(str(freq[2]) +'[Hz]'), Quantity(str(freq[4]) +'[Hz]')] # define frequencies as a list of quantities reader.Dispose() pass
0 -
@Erik Kostson
Perfect, it's working.
Thanks a lot and appreciate your quick and accurate solution.1
Answers
-
Hi
Perhaps save these frequencies to a file and then use mechanical scripting or python code object to read it and add the frequencies as a command or straight into analysis settings?
These should all help:
https://discuss.ansys.com/discussion/1698/harmonic-analysis-define-user-defined-frequencies
https://discuss.ansys.com/discussion/407/how-can-i-read-a-file-using-python
I will post also here in the next hrs, another possible way.
All the best
Erik
0 -
Hi @Erik Kostson
Thanks for your quick reply.
Could you please help with a command snippet, which reads freq values and set them as user defined freq in harmonic analysis ?0