Assign FirstFrame and LastFrame values from external txt file

Hi,
I'm using Plug-in-gait_Simple. I want to read FirstFrame and LastFrame values from a txt file in the Input folder. I have written the code below in the TrialSpecificData_GRFPrediction.any file:

  AnyInputFile FirstLastFrame = 
  {
    FileName = "Input/Frames.txt";
    TOnOff = Off;
    ReloadOnOff = Off;
  };
  FirstFrame = round(FirstLastFrame.Data[0]);
  LastFrame = round(FirstLastFrame.Data[1]);

I have checked that it can read the two numbers in the Frames.txt file but can't assign them to FirstFrame and LastFrame because there is no data at moment "Const". The following error is given:

ERROR(SCR.EXP10) : KinematicStudyForParameterIdentificationSettings.any(46) : 'nStep' : Expression evaluation failed at moment 'Const' :
ModelSetup.any(7) : nStep : argument will not be ready for evaluation until moment 'DesignVar'

How can I assign TrialFileName, FirstFrame, and LastFrame values from external files in any way?

Best regards,
Mohammadreza

Hi @mrb9

What you are trying is unfortunately not possible. The AnyInputFile is evaluated at a later evaluation moment. It only works with the AnyInputC3D and AnyInputBVH since they are differently implemented and evaluated at a much sooner evaluation moment.

What you could do is to use a .any include file.
it could look something like:

TrialFileName = "GaitNormal_1";
FirstFrame = 100;
LastFrame = 300;

this you can same as Frames.any and place besides your TrialSpecificData.any
Inside the TrialSpecificData.any you can comment out / remove the lines that set the three variables in question and insert a line with: `#include "Frames.any"

This way the variables are loaded in appropriately.

Bonus info.

If you need to generate the Frame.any file, you could do so from python. A simple snippet could look something like:

# open text file with info
with open("Frames.txt", "r") as fh:
    trials = fh.readlines()

for trial in trials:
    # assume the input to be rows of comma separated values
    name, first, last = trial.split(",")

    with open(f"Frames_{name}.any", "w") as file_handle:
        file_handle.write(f'TrialFileName = "{name}";\n')
        file_handle.write(f'FirstFrame = {first};\n')
        file_handle.write(f'LastFrame = {last};\n')

Best regards,
Bjørn
AnyBody Technology

2 Likes

Hi Bjørn,

Thank you so much for your response.
Before I tried to read data from a text file, I had used the implementation of the "Frames.any" file that you mentioned. But I didn't want to devote much time to write information on a more complex file. Thanks for letting me know that it is impossible to work with text files here.
But with the Python code that you described, it is now so easy for me to do what I had in mind. So thanks for answering my next question before I ask it. :innocent:

Best regards,
Mohammadreza

This topic was automatically closed 125 days after the last reply. New replies are no longer allowed.