Using the AnyPyTools for am parametric Study in AnyBody on the MandibleChewingandChlenching Model

Hey Everyone,
We currently have a project, where we want to study the influence of CMD (Cradio mandibular Dysfunction) on the movement of the Jaw. Therefore we have collected al lot of data. Because we have a lot of Patients we had the idea to use a Python Script to automatize the Scaling Process. Therefore we worked through these Tutorials: AnyPyTools’ documentation! — AnyPyTools 1.17.1 documentation.
In the Section Creating many macros they introduce a simple parameter Study. We now tried to do the same with our Mandible model. At first we just wanted to Change one Value once and then run the Simulation and dump the Values. But unfortunately there seems to be a problem with the SetValue command. Maybe someone can help to explain, why it wont work. Here is the Python code and the Log with the Error:
from anypytools.macro_commands import (MacroCommand, Load, SetValue, SetValue_random, Dump, SaveDesign, LoadDesign, SaveValues, LoadValues, UpdateValues, OperationRun)

from anypytools import AnyPyProcess
from anypytools import AnyMacro
import numpy as np

macro = [
Load('MandibleChewingAndClenching.main.any'),
Dump('Main.Model.ScaleMandibleX'),
UpdateValues(),
SetValue('Main.Model.ScaleMandibleX', 0.85),
UpdateValues(),
OperationRun('Main.RunApplication'),
Dump('Main.Study.Output.Abscissa.t'),
Dump('Main.Study.Output.TMJ_Forces.TMJ_ForceR'),
Dump('Main.Study.Output.TMJ_Forces.TMJ_ForceL'),
]

app = AnyPyProcess()
output = app.start_macro(macro)

Logfile:
########### MACRO #############
load "MandibleChewingAndClenching.main.any"
classoperation Main.Model.ScaleMandibleX "Dump"
classoperation Main "Update Values"
classoperation Main.Model.ScaleMandibleX "Set Value" --value="0.85"
classoperation Main "Update Values"
operation Main.RunApplication
run
classoperation Main.Study.Output.Abscissa.t "Dump"
classoperation Main.Study.Output.TMJ_Forces.TMJ_ForceR "Dump"
classoperation Main.Study.Output.TMJ_Forces.TMJ_ForceL "Dump"

######### OUTPUT LOG ##########

AnyBody Console Application
AnyBodyCon.exe version : 8. 1. 4. 12797 (64-bit version)

Build : 20335.7200
Copyright (c) 1999 - 2025 AnyBody Technology A/S

Current path: g:\Daten_Johann\CMD_Projekt\Python_Test\20250805_AMMR_DIBASYS_JMAmotion_FK\Application\Validation\MandibleChewingAndClenching

Macro command > load "MandibleChewingAndClenching.main.any"

Loading Main : "g:\Daten_Johann\CMD_Projekt\Python_Test\20250805_AMMR_DIBASYS_JMAmotion_FK\Application\Validation\MandibleChewingAndClenching\MandibleChewingAndClenching.main.any"
Scanning...
AMMR version detected : 2.4.3
'System.Compatibility.AnyBody75_AMMR24_CompatibilityOnOff' set to :On'
WARNING(SYS7) : : 'AnyBody75_AMMR24_CompatibilityOnOff' : Compatibility mode auto-detected : AMMR 2.4.x or earlier has been detected and associated compatibility setting has been turned 'On'

  • AnyMuscle::MuscleModel is renamed to '_MuscleModel' to avoid conflict with AMMR definitions.
    It is recommended to update to a newer AMMR, or set this compatibility-mode to 'Off' and fix conflicts in your own version.
    Parsing...
    Constructing model tree...
    Linking identifiers...
    WARNING(SYS3) : g:\Daten_Johann\CMD_Projekt\Python_Test\20250805_AMMR_DIBASYS_JMAmotion_FK\Body\Mandible\SymmetricMandible_AU\Jnt.any(27) : 'ReactionForceTMJ_R' : 'AnyGeneralMuscle' : Deprecated class : The 'AnyGeneralMuscle' class is deprecated and will eventually be removed. Please consider replacing it by 'AnyMuscleGeneric' or 'AnyRecruitedActuator'.
    WARNING(SYS3) : g:\Daten_Johann\CMD_Projekt\Python_Test\20250805_AMMR_DIBASYS_JMAmotion_FK\Body\Mandible\SymmetricMandible_AU\Jnt.any(57) : 'ReactionForceTMJ_L' : 'AnyGeneralMuscle' : Deprecated class : The 'AnyGeneralMuscle' class is deprecated and will eventually be removed. Please consider replacing it by 'AnyMuscleGeneric' or 'AnyRecruitedActuator'.
    Evaluating constants...
    Configuring model...
    Evaluating model...
    Loaded successfully.
    Elapsed Time : 0.205000

Macro command > classoperation Main.Model.ScaleMandibleX "Dump"

Main.Model.ScaleMandibleX = 0.82999999999999996;

Macro command > classoperation Main "Update Values"

Updating expressions...
...Finished updating expressions

Macro command > classoperation Main.Model.ScaleMandibleX "Set Value" --value="0.85"

ERROR(OBJ1) : g:\Daten_Johann\CMD_Projekt\Python_Test\20250805_AMMR_DIBASYS_JMAmotion_FK\Application\Validation\MandibleChewingAndClenching\MandibleChewingAndClenching.main.any(68) : 'ScaleMandibleX' : 'Set Value' operation on this value-object is not allowed

Macro command > classoperation Main "Update Values"

Macro command > operation Main.RunApplication

Error : Main.RunApplication : Select Operation is not expected or object is not AnyOperation.

Closing model...
Saving modified values...
Deleting loaded model...
...Model deleted.

Thanks in Advance
Johann

Hi @johann

AnyBody handles variables differently depending on if they are considered constants or values that can be changed after load (sometimes called design variables).

I think that is the issue because your error message say:

'Set Value' operation on this value-object is not allowed

You can check your variable in the model tree. If it has an (Editable*) postfix, then it is possible to change the value after the model is loaded.

You can force variables to be editable (design var), by creating the value like this in the script :

AnyVar ScaleMandibleX = DesignVar(<some initial value>); 

The DesignVar() function will force the system to not consider your variable as a constant.

Hope this helps.

1 Like

Thanks for the Tip, it instantly worked!