Passing a vector from python to anybody

Dear all

I am trying to pass a vector from python to anybody. The vector is a design variable ( so editable) in anybody and the class is a AnyVec3

In python, I am defining and setting it as follows:

DAcro1 = [{-0.014,0,0}]
SetValue('Main.HumanModel.BodyModel.Right.ShoulderArm.ModelParameters.Scapula.DAcro1',DAcro1),

Anybody performs the inverse dynamics analysis but in the end python states the analysis failed.
The logfile provides the following information:

Macro command > classoperation Main.HumanModel.BodyModel.Right.ShoulderArm.ModelParameters.Scapula.DAcro1 "Set Value" --value="{0, -0.014}"

ERROR(SCR.EXP11) : C:\Users\johan\Nextcloud\Johanna\AnyBody.7.3.x\21_01_ammr-master\Body\AAUHuman\ARM\ArmData1.1/ArmModelParameters.any(521) : 'DAcro1' : Incorrectly sized array reinitialization data for 'AnyFloat[3]'

||============================Edit Value==============================
||
|| DAcro1 = {0.0, 0.0, 0.0}
|| DAcro1 =||====================================================================
||==========================Message Dialog============================
|| Error : Set value is not allowed for given model running state.
|| Press : < OK (Any Key) > : OK
||====================================================================

Macro command > operation Main.Study.InverseDynamics

Macro command > run


  1. InverseDynamics (Operation: Main.Study.InverseDynamics):
    0.0) PreOperation (Operation: Main.Study.InverseDynamics.PreOperation):
    0.0.0) InitialConditions (Operation: Main.Study.InitialConditions):
    0.0.0) ...Design variables have been updated.
    0.0.1) ...Load-time positions have been re-established.
    0.0.2) ...Kinematic analysis completed.
    0.0.3) ...Dependent variables are fully updated.
  2. Inverse dynamic analysis...
  3. ...Inverse dynamic analysis completed
    Total simulation time: 61.541

It seems its setting the wrong values (--value="{0, -0.014}"), however I dont know where it is taken the x-component from as -0.014 is the x-component that I pass. The y- and z components are missing.

I assume there is an error with the brackets?

Would be great if you could illuminate me :slight_smile:

Thank you and best regards
Johanna

Hi @jmenze,

There are some quirks at play here so let me see if I can explain them :slight_smile:

Firstly, your python variable DArco1 is a list of a set, so the first element of your list is a python set with three elements.
Python sets do not be default have any order in the elements. This means that if you print the set or iterable over the elements you do not know in which order they will come. That is why your x coordinate is swithing place. Python lists however retain their order so you could use those instead when the order of elements are relevant.

Secondly, The SetValue class can only be used to assign strings or single numbers (int or float) to a anyscript variable. So in order to assign an array you must parse it as a string.

This could be something like:

DAcro1 = "{-0.014,0,0}"
SetValue('Main.HumanModel.BodyModel.Right.ShoulderArm.ModelParameters.Scapula.DAcro1',DAcro1),

Here we parse a string of the vector to the anyscript variable.

If you pass python lists to a SetValue class the idea is to generate a macro for each element in that list and not parse the list.

I hope this can help you, others feel free to write us again.

Best Regards,
Bjørn
AnyBody Technology

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