AnyPyTools macro

Hi,

I am having an issue when running a macro from anypytools on python. I am aiming to run the kinematics and inverse dynamics as well as dumping some hip reaction force data. The script runs but only returns one value for the hip reaction force. See code below.

from anypytools.abcutils import AnyPyProcess 
app = AnyPyProcess()

macrolist = [['load "MoCap_LowerBody.main.any" -def MotionAndParameterOptimizationModel="1" -def InverseDynamicModel="0"',
              'operation Main.RunMotionAndParameterOptimizationSequence',
              'run',
              'exit'],
             ['load "MoCap_LowerBody.main.any" -def MotionAndParameterOptimizationModel="0" -def InverseDynamicModel="1"',
              'operation Main.Studies.InverseDynamicStudy.InverseDynamics',
              'run',
              'classoperation Main.Studies.HumanModel.BodyModel.SelectedOutput.Right.Leg.JointReactionForce.Hip_MediolateralForce "Dump"',
              'exit']]
app.start_macro(macrolist);

I believe this could be because the model exits before running the inverse dynamics, therefore returning a value for a stationary body? I have tried to adapt the script but with no success.

Any advice on how to overcome this would be much appreciated.

Kind regards,
Robin

Hi Robin

To get more values, you need to dump the content of the variables below the study output folder. ‘Main.Studies.InverseDynamicStudy.Output’ The Output folder is the structure that collects the data from all time steps.

Thus, the dump class operation would look like this:
‘classoperation Main.Studies.InverseDynamicStudy.Output.BodyModel.SelectedOutput.Right.Leg.JointReactionForce.Hip_MediolateralForce “Dump”’,

Also, keep in mind that you need to run ‘ParameterOptimization’ before the inverse dynamic study. In your case, where the macros are split into two, AnyPyTools may run them in parallel.

Thank you very much for the fast reply. I have made the suggested changes and the script is now running fine.

I have a second question regarding output data. I put the following code into the inverse dynamics of my main model. I aim to save a number of variables directly into text files, however although the model runs fine, no text file is saved as far as I can see. Apologies if this is a relatively simple question.

AnyOutputFile test =
{
FileName = "test.csv";

AnyFloat Hip= Main.Studies.HumanModel.BodyModel.SelectedOutput.Right.Leg.JointReactionForce.Hip_MediolateralForce;
};

Kind regards,
Robin

Hi Robin

The code looks correct to me. Think the issue happens because the AnyOutputFile object is somehow not included in the study that you run.

It should either live directly in the study or the study should have a reference to it.