AnyBody and Python??

Hi Felix,

Yes, it is possible to set the value, but the problem will appear if you use it for specifying filenames. Filenames are needed by the system very early to be loaded and, thus, something may not work. And that is basically the meaning of the warning that you see.

I would probably try to avoid setting filename-related strings from the macro commands and set if through a reload of the model and #defines.

But please try on a smaller example, maybe your case will just work.

Regards,
Pavel

Hi there Pavel,

during the last weeks I could almost finish my python script. There is one last obstacle I’ve to take: I’m trying to pass different landmark coodinates to my own VTK_LANDMARK_RIGIDBODY transformation (the ones of my own stl geometry).

When preparing the values with the python script I’ve to convert them to a string. I tried to place a string-value of python with my AnyMacro script to a Float[1] and Float[3] value of AnyBody an it worked fine. The landmark points are a AnyFloat[6][3] matrix. I already wrapped the coords in a DesingVar = (…) statement in order to get access to them, checked a couple of times my syntax and had a lot of little examples. Actually it should not make difference between Float[3] and Float[6][3] because AnyBody is interpreting the syntax of the string? Do you have any idea what is going wrong?

King regards,
felix

Felix,

I do not fully understand what you are doing - some details are missing without seeing the actual code. But i think the problem might be that the python functions require exact output dimensions and they cannot be dynamic (related to memory allocation in AnyBody). So you should be handling parameters of a specific size. Is the size always fixed?

The solution might look like, where you change the output dimension manually:


  AnyInt Size = 16;
  AnyFunEx FunCEx = 
  {
    AnyMatrix Return = {iarr(1,.Size)*0,iarr(1,.Size)*0,iarr(1,.Size)*0}';
    AnyFunExMonoPy ReadFile =
    {
      ModuleFile = "ReadFileIn.py";
      ArgList = 
      {
        AnyStringVar stringIn = "";
      };
    };
  };

I hope this helps, otherwise try to show us the code.

Regards,
Pavel

Hi Pavel,

I’ve something like this in AnyBody:

  AnyFloat LandmarksAB = ...
  AnyFloat LandmarksCT = DesignVar({
    {0.3289, 0.4259,-0.175},     
    {0.2899, 0.4205, 0.0139},    
    {0.3220, 0.4332,-0.3786},
    {0.3063, 0.4872,-0.3703},
    {0.2893, 0.4268,-0.373},
    {0.2619, 0.4759,-0.3729}});

  AnyFunTransform3DLin2 S_FORWARD_RIGIDBODY = {
    Points0 = .LandmarksAB;  
    Points1 = .LandmarksCT;
    Mode = VTK_LANDMARK_RIGIDBODY;}; 

And I’m trying to do this:

 macrolist_kinematics =[[ ...
                                   'classoperation Main.Studies.HumanModel.Scaling.GeometricalScaling.Left.Thigh.MyScalingLaws.LandmarksCT  "Set Value"\
                                --value=%s' %(LandmarkSTR),
                                  ...
                                  ... RunKinOpt ... ]]

with a String like this:

LandmarkSTR = 
"{{0.1389704, -0.02541524, -0.8504597},
 {0.07091749, -0.01174339, -0.6284968},
 {0.1561644, -0.04397405, -1.044624},
 {0.1457588, 0.01952965, -1.04857},
 {0.1191651, -0.05498121, -1.04815},
 {0.09407188, 0.006200216, -1.052578}}"

I tested it for Float[1] and Float[3] which worked fine therefore I thought writing strings in any way is permitted. The only point is, that it should be in the specific form of the syntax of the AnyBody value. Is it possible that there are some problems with a Matrix in terms of Float[6][3].

Oh, sorry, you mentioned Python script and i went into the ‘Python mode’.

I am quite certain that it may work in the scenarios where nothing depends on this variable, but if it has some dependency - symbolic link will break and the values will not apply (to the dependencies). And to check the syntax, which to me looks fine, you can right click on the landmarkCT value and try to set this line manually - i would expect it to work.

Do you get broken dependency warnings? What are the symptoms of not working code?

P.

It’s a little bit trick to debug because he end up with a failed kin. opt. and not with errors related to scaling issues. I could debug so far that input/interpreting is the key problem. When I run the model “manually” with my own STL and your “default” AnyBody TargetLandmarkPoints it produces the same error as the script does. Is there any value which I could dump with my script to see if I have access to AnyFloat LandmarksCT = DesignVar(…) at all? I couldn’t find anyone which gets me information about proper transformation.

I thought about getting six strings like this

{%(ams)s,%(fc)s,%(lac)s, %(lpc)s, %(mac)s, %(mpc)s}" %(adict)

on the DesignVar insteat of one single string into Float[6][3]. It would mean a lot of work for me. Do you think it is worth to try?

Would it not be just easier to write an AnyScript include file from Python that contains these landmarks prior to loading the model? Why do you try to set them?

Pavel

Dear Pavel,

I’m not sure how AnyBody is interpreting the content of this file. If AnyBody is reading it as a string it should be the same problem just from another direction. Do you know what AnyBody expect to read for a AnyFloat[6][3]. Six vectors, one matrix, 18 values or something completly different?

Felix, I think i lost you on that one, I may not fully understand the problem then. Could we step back a little and have a look at what you’re trying to do again?
Do you have a Python script, which loads a model, prepares the matrix for your simulation and then trying to set the values? Or is it different?

I am sorry - I may be a little slow on this one, but if i get the right question I may just answer right away.

Pavel

Dear Pavel,

okay, I’m trying to pick you up: I’ve got those landmarks on my own stl geom. In order to get the right expression I have to change the landmarks from a Float to a String with my python script. I’m passing this String to a python modul named AnyMacroing where all my macrolists and therefore all my (class-)operations are.

One of those macrolists is called macrolist_kinematics. Within this list I’m loading my GaitModel, set the define statements for KinOpt=1 and InverDyn=0, (trying to) input the values of the target landmark geometry and run everything.

Or in the as you wrote it:

Preparing Matrix.

(with AnyPyTools):
Loading Model.
Setting the values of the Prepared Matrix.
Run KinOpt.

EDIT:
Setting the values of the prepared … actually works for single Floats and Vectors. But not on a Matrix like Float[x][x]. Or at least it seams to be like that. I don’t know what exactly is the problem what makes it difficult to explain properly. Sorry :frowning:

Dear Felix,

Ok, then i think i understood it well. I do not think you need to be using SetValue in this case - that’s a bit of an overkill and it does not work if you have dependencies (as i said).

For example, if you have a code like that:

    AnyMatrix desvar = DesignVar({{0,0,0},{0,1,0},{1,0,0}});
    AnyMatrix test = desvar;

You can set the value of desvar by providing a string like: “{{0,0,0},{0,1,0},{1,0,0}}” - it will update the value of desvar, but not test.

The solution - make a small Python function, which will write your matrix in AnyScript syntax into a file, and include this file in the model. On loading this file will be picked up and since the values are static - you need them before loading the model and not while running the model (SetValue makes more sense within a running analysis or changing the model when it is already loaded). Eventually the code will look like (2 blocks of code):


... in the morphing code
AnyFunTransform3DLin2 transformation = {
#include "AutomaticallyWrittenMatrix.any"
Points0 = .SomeLandmarksHere;
Points1 = AutomaticallyWrittenMatrix;
};
... AutomaticallyWrittenMatrix.any
AnyMatrix AutomaticallyWrittenMatrix = {{...}};

Let me know if this helps you. Maybe I misunderstood something else again.

Kind regards,
Pavel