Macro functions

Hi,
I try to use the Anybodycon.exe to automate some sensitivity studies. On think of interest is to change the name of the output file and the nStep parameter. I thought writing a macro like that :

load "Demo.Arm2D.any"
-def N_STEP 10 
-def Name "OuptutfileNameMatlab.txt"
operation Main.Study.InverseDynamics 
run 
exit

But, I must do some mistakes because it doesn’t work.
I also tried to write the same statement directly in the shell and I get an error/warning after the “-def” statement :

"Warnning : Macro arguments has no effect :  -def  N_STEP  10"

My Anybody version is 5.2.

Would you have any idea about my problem and how to solve it ?
Thank you !!
Lauranne

Hi Lauranne,

try

load “Demo.Arm2D.any” -def N_STEP=“10” …

Hi Amir,
Doesn’t work…

I think I tried all possible combinations : -def N_STEP 10 or -def N_STEP=10 or N_STEP=“10” or -def N_STEP “10”
And same four with “/def” and with “define=” (as proposed in the anybodycon.exe --help)

I also tried using macrofile containing that command but also the same error.

Thanks for helping !
Lauranne

Hi Lauranne,

try to write the -def statements in the same line as the load statement


load "Demo.Arm2D.any" -def N_STEP="10"  -def Name="OuptutfileNameMatlab.txt" 
operation Main.Study.InverseDynamics  
run  
exit

If the -def statements are not in the same line as the load command, they are handled as a separate command, which does not exist in this case. This is where the warning comes from.

Best regards
Daniel

Hi Daniel,
Thanks for your help. However it doesn’t solve the problem… Could you have a look of a screen copy from the anybodycon.exe :

Best regards,
Lauranne

Hi Lauranne,

I think the problem is your AnyBody version. On the screenshot it says that you tried with AMS 5.1.0 and I think the feature to have define statements in the load command was implemented in version 5.2.0. If it is possible to update your AnyBody version, this might be the easiest solution.

Otherwise there is an option to have define statements on the command line in AMS 5.1.0. That would require to remove the -def statements from the load line, so to have a macro file (e.g. named macrofile.anymcr)

load "Demo.Arm2D.any" 
operation Main.Study.InverseDynamics  
run  
exit

and move them to the call of AnyBody:


AnyBodyCon.exe /m macrofile.anymcr /def N_STEP=10 /def Name="OuptutfileNameMatlab.txt"

You can find details about the syntax in the help of the AnyBodyCon.
If you want to have a one file solution it a simple way to handle this might be to write this call into a .bat file.

Best regards
Daniel

Hi Daniel,
Well, I’ve the 5.2. version, so I tried it on 2 different computers. I don’t know if it’s a good thing but the error is different :wink: Here is a screen shot with command line:

Could it be due to the fact that I’ve 2 versions of anybody (5.1. & 5.2.) ? I read tutorial to manage several version for the anybodycon.exe but in fact I don’t know how to create shortcuts with a bat file… Could you explain it to me a litte more precisely ? For the moment, I set the environment variables to use the anybodycon 5.2. version by setting the corresponding path.

Thanks for your help !
Lauranne

Hi Lauranne,

at this point I cannot reproduce the error anymore. Just to make sure: Are you sure that the model loads fine in the GUI application of AnyBody?

To the problem with the .bat file: you can simply create a text file, write something like

"<AnyBody installation path>/AnyBodyCon.exe" /m macrofile.anymcr /def N_STEP=10 /def Name="OuptutfileNameMatlab.txt"

where <AnyBody installation path> is typically something like C:\Program Files (x86)\AnyBody Technology\AnyBody.5.2 and rename the ending of the file to .bat to make it executable.

Best regards
Daniel

Hi Daniel,
thanks for your quick reply !

I think we’re talking about 2 different problems in fact :
1. Loading with the 5.2. version :
Yes, loading via the gui anybody 5.2. version works well.
Moreover, loading via the anybodycon 5.1. version also works well.
To be sure, I tested effectively what I wanted, I set the anybodycon path before each loading in the cmd.exe window and check the version. Allways the same error (SCR.SCN9) when launching "load “Demo.Arm2D.any”

2. /def command
With the version 5.1. of the anybodycon, I didn’t get error when writting your code. But it hadn’t any effect : neither the nStep nor the Name correspond to what I wrote in the statement…

To finish, maybe should I be more precise about my objectives. What I’d like si to automate studies loading. I wrote a matlab function using matlabpool to set the number of parallel works and when an analysis finished it launch a new one. So I don’t want have to click on the bat file but really automate that… Maybe would you have any advice about that objectives ?

Regards,
Lauranne

Hi Lauranne,

I tried to reproduce your current problem.

  1. I can see that in version 5.1 there is a problem with the define statement that it has no effect. This is probably a bug, sorry for that, but it is fixed in AMS 5.2

  2. For AMS 5.2: I tried the define statements using a small test example based on Demo.Arm2D.any from the demo examples in the reference manual of AnyBody. I added two define statements at the top of the file (I hope) similar to your define statements:


#ifndef N_STEP
#define N_STEP 10
#endif

#ifndef Name
#define Name "Output.anydata.h5"
#endif

To see the effect of the Name, I simply added a class operation that saves the output and wrote it into an AnyOperationSequence, similar to definitions that can be found in AMMR models


Main = {
  AnyOperationSequence RunApplication = 
  {
    AnyOperation &Inverse = Main.ArmModelStudy.InverseDynamics;
    AnyOperationMacro output = 
    {
      MacroStr = {"classoperation Main.ArmModelStudy.Output " + strquote("Save data") + "--type=Deep --file=" + strquote(Name)};
    };
  };
...
};

To test the effect of the N_STEP define statement, I added used it to define the number of steps in the Study which now looks like this:


AnyBodyStudy ArmModelStudy = {
  AnyFolder& Model = Main.ArmModel;
  Gravity = {0,0,-9.81};
  nStep = N_STEP;
};

With this example I was able to
a) define a statement in an .anymcr file like using the syntax


load "Demo.Arm2D.any" -def N_STEP=10  -def Name=---"\"OuptutfileNameMatlab.anydata.h5\""
operation RunApplication  
run  
exit

which is then called without arguments on the command line. Please note that in this example the Name has to end with .anydata.h5, which is a requirement for the classoperation. I guess what could have been a problem is the quotation of the second define statement. As a reference, the syntax of quotation is mentioned in the release note to AMS 5.2.

b) Otherwise it is possible to define these statements on the commandline by deleting the -def statements from the .anymcr file (if they are still in, the -def statements from the commandline are overwritten)
The call of AnyBodyCon is then


AnyBodyCon.exe /m macrofile.anymcr /def N_STEP=10 /def Name=---"\"OuptutfileNameMatlab.anydata.h5\""

I think in this case it does not make a difference if there are quotes around the 10.

I hope this works also for your problem.

Best regards
Daniel

Hi Daniel,
I definitely think that I’ve problems with my Anybody versions…

Just to confirm : I indeed wrote the “#ifndef,…” at the very beginning of the main file. I wrote it before the “main” declaration ; has it any incidence if placed in or out the main ? In fact I tried both but allways an error. I expected it’s not my main concern :wink:

I followed (or think I did!) all your advices about how tu use/create macro. In fact it was quite similar with what I did. But I can’t launch my study, neither with the /def into the macro fil, nor the /def written in the command line sentence.

For the output file, your advice was to use a .h5 extension file. In my case I create my output file as a .txt, using the anyoutputfile function. Do you think it should be ok ?

Thank you for helping !
Lauranne

Hi Lauranne,

the .h5 extension is only needed for the classoperation I used in my example. For your case the .txt extension should be ok.

I tried to add an AnyOutputFile class to my simple example and I think I see a similar problem. I have some question:

  1. Is it possible for you to update to version 5.2.1 or newer? I thing in this version the problem should be fixed.

  2. This is just a test, not really a solution: Could you change to the directory of the AnyBodyCon.exe and try calling it as …&lt;directery name of AnyBodyCon>\AnyBodyCon.exe /m <macrofile.anymcr>? By accident I saw that this was working for my example, but I don’t know if it was some other effect.

  3. See question no 1.

Best regards
Daniel

Hi Daniel !
GREAT !! :slight_smile:

To sum-up :
Indeed I did install the version 5.2.1 from the first time you asked me. That what it gave me the error <SCR.SCN9>. But I didn’t uninstalled the 5.1. version. When it worked (but not all times !), the model loaded, but as if it could not take the -def parameter into account.
Regarding the problem for the definition of the “Name” parameter, I think my code was wrong : I only wrote the name of the outputfile, not all the specific path.

The problem of the error for the 5.1. is, as you told, a problem with the version itself.

I tried changing the directory of the Anybodycon.exe but new error : “the application failed to start because its side by side configuration is incorrect” (or something like that, I just translated it from french…).

Finally, I uninstalled evereything of all installed versions (5.1. AND 5.2.), even regedit and all caches in local folder. Then, I reinstalled only 5.2… And, as you understood, it works :wink: I absolutely don’t know the cause of my problem, but for the moment, things are good.

Thank you very much for your help !
Lauranne

Hi !
I would have a new question about the macro and the use of -def parameter for the names.

I’d like to do 2 things:
First, launch a macro which is in a “Macro” folder
Second, save the result in a “Results” folder

These 2 folders would be at the same level as the main.any. I tried these solutions (idem for the results path definition) but whithout succes :

-def Name=---"\"Macro\macro.anymcr\""
-def Name=---"\Macro\"macro.anymcr\""
-def Name=---"\Macro"\macro.anymcr\""
-def Name="\Macro"\macro.anymcr\""
-def Name="\Macro\macro.anymcr"

For sure I’ve problem with my quotations but I don’t know where ; I read the release notes of the 5.2. version but was not able to adapt description to my case.

Thank you very much for your help !
Lauranne

Hi Lauranne,

I am not sure i fully understand what you would like to do, but only the last line of your anyscript code would work so :


[SIZE=3]#define[/SIZE] Name="\Macro\macro.anymcr"

Please have a look in the C3DProject model this model also use folders for storing results an retrieving data.

In this model a DataPath is create and then this path is being used different places in the code.


[SIZE=3]#path[/SIZE] DataPath "MyC3DData"

and


[SIZE=3]#include[/SIZE] "<DataPath>/TrialSpecificData.any" 
[SIZE=3]#include[/SIZE] "<DataPath>/ModelSetup.any"

Best regards
Søren

Hi Søren,
Thanks for your descriptions ! I totally agree with your explanations, but only when this path is defined in the gui interface (And I’m able to do it). My problem is that I’d like to define the path via macro functions.

It appears that this way to write the path looks not working when using “-def=” in the macro language.

Am I little clearer ??

Lauranne

Hi Lauranne,

I have a question about the topology of your calls:
When you want to have a .anymcr filename as a #define statement in an .any file (that is what the -def statement is doing), are you calling the .anymcr file from this script? Otherwise, wouldn’t it simply be a call with AnyBodyCon.exe /m Macros/<filenam>.anymcr …?

About the output: I tried to use an output folder in my simple example. With version 5.2.1 I saw an error message, but it worked using the first version of your syntax examples. I guess you assured that the output folder exists. Unfortunately, AnyBody cannot create folders, so they have to exists before using them. What kind of error message do you get for the problem on the output folders?

Best regards
Daniel

Hi Daniel,
Thanks for your so good advices.

Macro works well as you described. I made things very complicated in fact ! :wink:

Regarding the difficulties with the results path definition, in fact, I did not get any errors. It only did not create anything. To answer your question, yes, I made sure having the specified folder. Finally, after new trials, I found a working syntax, which is :

def=---"\\"Results//<NameFileResults.txt>\\""

I think my mistake was that I did not write two “” and 2 “/” before and after the “Results”. Maybe, should I have said that I’m working with matlab to call the anybodycon.exe and maybe is it the reason why I have to double the “” ?

In brief, thank you very much for resolving my problem !
Lauranne

Is it possible to have some variables defined by the command line and other variables defined by the .anymacro and end up will all variables defined by the time it runs the Main?

Hi,

Why not have them as define statements in the main file? I guess you want to fix some of the defines. So you only have the problem of the command line.

If you try to run some parametric studies, where you fix some of them - we would very much recommend to use Matlab/Octave or Python to program the execution. This approach is also less error-prone.

Kind regards,
Pavel

P.S. You might want to search the forum for AnyPyTools/Python/Matlab