Can I define a set of step end times via scripting?

Tasos
Tasos Member, Employee Posts: 8
Name Dropper 5 Likes First Comment Photogenic
✭✭✭

I am trying to develop a script to access analysis settings and set a large series of step end times from a list of end time values in seconds.

Tagged:

Best Answer

  • Tasos
    Tasos Member, Employee Posts: 8
    Name Dropper 5 Likes First Comment Photogenic
    ✭✭✭
    Answer ✓

    When trying to set step end times in Mechanical UI using scripting, you might encounter issues depending on the values populating the End Time data table.
    For example, when setting the number of steps, Mechanical will automatically populate the table with values for every newly defined step, incrementing by 1s for each subsequent step. As a result, depending on the desired step end times and their position in the table, Mechanical may reject some values.

    The following script uses a list of ascending step end times as input, resets the number of steps to one and iteratively increases the number by one, setting the end time to the corresponding value in the list.

    with Transaction(True):
        # Accessing analysis settings
        analysis_settings = ExtAPI.DataModel.Project.Model.Analyses[0].AnalysisSettings
    
        step_endtimes = [0.2, 0.4, 0.8, 0.9] # example list
    
        ts = 1 # iteration index
        for end_time in step_endtimes:
            analysis_settings.NumberOfSteps = ts
            analysis_settings.SetStepEndTime(ts,Quantity(end_time, 'sec'))
            ts = ts + 1
    
    
    

Answers

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 341
    25 Answers 100 Comments 25 Likes First Anniversary
    ✭✭✭✭

    There is sometimes an issue trying to set a step end time that is larger than the next step. For example if step 2 end time is 2s you cannot set step 1 end time to 3s.
    To avoid this you can set all the steps to something very small to start like 0.001, 0.002 etc...
    Then you can set the steps in reverse order by starting at the last step and working backwards.

  • Tasos
    Tasos Member, Employee Posts: 8
    Name Dropper 5 Likes First Comment Photogenic
    ✭✭✭

    Hi @Mike.Thompson, that was indeed my initial approach.
    Even when filling the table bottom to top, I encountered scenarios that values were rejected (e.g. when the end time for step n was lower than the value already in step n-1), which makes "flushing" the table, as you suggested, necessary.
    Since this resulted in longer code and would require more explanation I chose to post the above approach.
    Thanks for the comment, it makes the topic more complete.