AnyMoCap / BVH_Xsens (AMMR): model runs if I only edit SubjectSpecificData, but any new .any file I include causes parser errors ('.' unexpected, '{' unexpected, 'AnyFolder' when 'Main' was expected)

Hello,

I am working with the AnyMoCap BVH_Xsens example in AMMR and I am running into a persistent parsing issue when trying to add any new AnyScript code.

Software:
AnyBody Modeling System 8.1.x (Faculty Research License)

Model:
AMMR → Application → MocapExamples → BVH_Xsens (AnyMoCap framework)

Goal:
I imported my own Xsens BVH file and can successfully run the full example pipeline (MarkerTracking and InverseDynamicStudy). However, I cannot add any additional AnyScript code via a new .any file, even a very simple test, without getting syntax/parser errors.

What works:

  1. I navigated to:
    C:\AnyBody\AMMR\Application\MocapExamples\BVH_Xsens
  2. I copied my BVH file into:
    BVH_Xsens\BVH-files
    The file is copied successfully.
  3. In the Subjects folder, I copied an existing subject/trial folder, renamed it to my subject identifier (for example: S_H\S_H_Trial01), and loaded Main.any from that folder.
  4. Initially, many files were read-only due to Windows permissions. I removed the read-only attribute at the AMMR folder level (right click → Properties → uncheck Read-only, apply to subfolders and files).
  5. I edited only SubjectSpecificData.any (for example, body mass and body height). After this change, the model loads and RunAnalysis works correctly.

So the baseline AnyMoCap example works, and editing the provided hook files works.

What does NOT work:

As soon as I try to add any new AnyScript code, the model fails during parsing.

For example, I created a new file called TestFolder.any in the same directory as Main.any and added the following minimal content:

Main.TestFolder =
{
AnyIntVar TestValue = 1;
};

Then I added this line to Main.any (after the AnyMoCap model include):

#include "TestFolder.any"

This immediately causes parsing errors when loading the model.

Typical errors I see:

  • ERROR(SCR.PRS11): '{' unexpected
  • ERROR(SCR.PRS11): '.' unexpected
  • ERROR(SCR.PRS12): 'AnyFolder' when 'Main' was expected

These errors occur before any analysis runs.

Observations:

  • The model works as long as I only edit existing files pulled in via #path (SubjectSpecificData.any, TrialSpecificData.any).
  • Any attempt to include a new .any file causes parsing errors, even with very simple content.
  • I have tried different file names, moving the include line, and simplifying the code further, but the result is always the same.
  • This makes me suspect there are specific constraints on how the BVH_Xsens / AnyMoCap example is intended to be extended.

My question:

What is the correct and supported way to add custom AnyScript code to the AnyMoCap BVH_Xsens example?

Is it expected that users should only modify SubjectSpecificData.any and TrialSpecificData.any?
If it is possible to include new files, what scope or structure should the included file have?

I am not trying to apply external forces yet; I am only trying to understand why any new code added via a separate .any file fails to parse.

Thank you very much for your help.


Hello Sondos,

Welcome to the AnyScript Forum! Firstly, can I please ask you to update your affiliation in the user profile to write your organization name?

I am not sure why you are seeing the AMMR files as read only. Are you working in the installation directory? Have you copied the files yourself from the installation directory? The AMMR files in the installation directory are marked as read-only to prevent accidental changes. Please see this page and its subpages to understand how to work with AMMR.

Regarding the error you are seeing, please update the code to

Main = {
  AnyFolder TestFolder = {
    AnyIntVar TestValue = 1;
  };
};

You are outside the scope of Main at the place where you typed your code. Therefore, you must open the scope of Main, and then inside Main, you can use the full statements like Main.TestFolder. Also, you have to define TestFolder somewhere in your model using the AnyFolder class. Main.TestFolder looks for an object called TestFolder, and you will get an unresolved object error, if you haven't defined it correctly.

I strongly recommend you spend some time going through the tutorials before you start working on your own models.

Best regards,
Dave

Hi Dave,

Thank you for the explanation, and apologies for the confusion earlier.

You are correct — I was initially working inside the AMMR installation directory. I have since copied the BVH_Xsens example to a separate working directory and am only modifying files in my local copy.

I understand the scoping point you raised and that code such as

Main = {
  AnyFolder TestFolder = {
    AnyIntVar TestValue = 1;
  };
};

is required when opening the Main scope explicitly. My difficulty is that, within the BVH_Xsens / AnyMoCap workflow, I am trying to extend an existing branch of the model (specifically Main.EnvironmentModel) without redefining Main or interfering with objects that are already created by the framework.

To clarify the actual use case motivating this question:

My end goal is to add a brief external perturbation force to the trunk during inverse dynamics, applied at or near the trunk’s center of mass. The perturbation is intended to be:

  • defined as a percentage of body weight (e.g., 10–15% BW),

  • applied only for a short time window (impulse-like),

  • and used to study balance/instability responses rather than to drive the motion.

Conceptually, this would be implemented using an AnyForce3D attached to a trunk-fixed reference frame and time-gated using the study time. However, before implementing the force itself, I wanted to confirm where such user-defined objects are intended to be added in the AnyMoCap/BVH_Xsens structure.

So my main questions are:

  1. What is the supported way to add custom AnyScript objects (e.g., external forces, additional reference frames) to the BVH_Xsens / AnyMoCap example?

  2. Is there a recommended hook file or include location under EnvironmentModel for user extensions?

  3. Or is the intended workflow that users should only modify SubjectSpecificData.any and TrialSpecificData.any, and not include new .any files?

At the moment, including a new .any file that defines even simple objects under EnvironmentModel leads to parsing/scope issues unless I explicitly redefine Main, which I suspect is not the intended pattern for this example.

Thank you very much for your guidance — I want to make sure I am extending the AnyMoCap framework in a way that is consistent with its design.

Best regards,
Sondos

Hi Sondos,

This can be done in several ways.

A1: I think it would be most natural to go to the LabSpecific file and add code like this

Main ={

EnvironmentModel ={#include “MyImpulseForce.any; };

};

But the same lines could also have been added TrialSpecific or SubjectSpecific files.

When you add your code inside EnviromentModel this will ensure that InverseDynamicStudy will pick it up and add it to the study, since EnvironmentModel is already used by the Study.

If instead you would have written

Main ={

AnyFolder MyOwnEnvironmentModel ={#include “MyImpulseForce.any; };

};

The predefined studies in the mocap would not know that this folder should be include, so that would have had to be done manually (also possible)

A2: So I would recommend to make your own file with this content.

A3: That would also be possible but better to do as described above.

It is perfectly ok to open Main and add things, this is normal practice and provides a lot of freedom.

Some comments on the force you will add:

  • Note that the force will not change the motion only the force, i think you are already aware of this.
  • If you have multiple trials you likely would want to add the forces at different time instances, these time instances I would add inside the trial specific data and then have the AnyForce3D to use.
  • Typically if you want a force to be an impluse you would first define a function of time that represents the force impluse, and then use this function in the AnyForce3D to apply the force.
    • ForceFunction def: use e.g. AnyFunInterpol or AnyFunSquareWave for this.
    • Applying the force write something like this
    • AnyForce3D MyForce = {
      F=MyForceFunction(Main.Studies.InverseDynamicStudy.t);
    • };

Hope it helps

Best regards

Søren