AnyPyTools - How to comment out #include

Hello everyone,

I run some parametric studies with AnyPyTools and would like to know if there is an option to comment out a #include-command or undo a #define-command in my AnyBody Model using AnyPyTools ?

I included an exoskeleton to the human model by #include and want to run the one part of the parametric study with the exoskeleton and the other part without.
I was hoping there is a more convenient way to do that other than having two different main files.

Best regards,
Tobias

Hi Tobias,

I suggest you wrap your #include statements inside an #if - #else - #endif statement. So, firstly you make a define statement for the exoskeleton condition (with or without), and in your model, have all the changes wrapped inside the if-else statements.

Then, you can you use AnyPyTools to generate macros while setting define through AnyPyTools.

One issue that you will face in this way is when you run the main file directly in AnyBody, you will use the define statement, but when you run it through AnyPyTools, the same define will be defined twice and create an error. You can avoid that by setting a default define inside an #ifndef - #endif statement in your main file. Here is an example:

#ifndef EXO
#define EXO "WOExo"
#endif

#if EXO == "WExo"
#include "Exo.any"
#endif

I hope this helps.

Best regards,
Dave

Hi Dave,

thank you a lot.
Can you please tell me how I set the define statement through AnyPyTools?

I think it should be something like: mc.SetValue(.EXO, "WExo") but AnyBody doesn´t show me where "EXO" is located.

Best regards,
Tobias

Hi Tobias,

Yes, there is an example showing how to do that in the link I posted above. So, following the example I wrote above, i.e., #define EXO "WExo", you can write the command through AnyPyTools like this:

from anypytools.macro_commands import (MacroCommand, Load, SetValue, SetValue_random,  
Dump, SaveDesign, LoadDesign, SaveValues, LoadValues, UpdateValues, OperationRun)

macrolist = [
    Load('Main.any', defs={'EXO':'"WExo"'}),
    OperationRun('Main.MyStudy.InverseDynamics'),
]

from anypytools import AnyPyProcess
app = AnyPyProcess()
app.start_macro(macrolist);

I hope this helps!

Best regards,
Dave

Hi Dave,
thank you again. It works great.
I did not get it at first when I checked out the tutorial.

Best regards,
Tobias

Hi Tobias

An other good tip is to structure your models in a smart way. I.e.include everything outside the studies, and then make references to the body parts you need in the different studies. A study only runs simulations on the parts of the model it has references to.

Here is a small example with pseudo code:

Main  = {

   AnyFolder HumanModel = {};

   AnyFolder ExoSkeleton1 = {};

   AnyFolder ExoSkeleton2 = {};

   // This study will only run simulations with exo1
   AnyParamStudy ParamStudy1= {
      AnyFolder& BodyModel = .HumanModel.BodyModel;
      AnyFolder& Exo1= .ExoSkeleton1;
    };

   // This study will only run simulations with exo2
   AnyParamStudy ParamStudy2= {
      AnyFolder& BodyModel = .HumanModel.BodyModel;
      AnyFolder& Exo1= .ExoSkeleton2;
    };
};

Thank you very much for the input.
I will include it in my code.

Best regards,
Tobias

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