How to execute a Mechanical script by inserting it as a command snippet

SK
SK Member Posts: 9
Name Dropper First Comment
**

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

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 216
    50 Answers 100 Comments 25 Likes Name Dropper
    ✭✭✭✭
    edited October 8 Answer ✓

    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
    
  • SK
    SK Member Posts: 9
    Name Dropper First Comment
    **
    Answer ✓

    @Erik Kostson
    Perfect, it's working.
    Thanks a lot and appreciate your quick and accurate solution.

Answers