Skip to content

Commit

Permalink
Allow shims of AnyBodyCon exe files on PATH (#118)
Browse files Browse the repository at this point in the history
* allowed any extension for the AnyBodyCon executable

Formatted with black

* Refactored tools.py so changes to anybodycon doesn't affect linux

* Add changelog entry

* Update demo examples

* Bumped version to 1.13

* Update toml and dependencies

* Skipped test on older python versions
  • Loading branch information
melund authored Oct 22, 2024
1 parent 99c2ee5 commit 1c8a64e
Show file tree
Hide file tree
Showing 27 changed files with 1,603 additions and 1,412 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
test:
strategy:
matrix:
env: ["test", "test-py37"]
env: ["test"]
runs-on: windows-latest
needs: lint
steps:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

**Added:**
* Added a "LoadData" macro command can generate the macro for loading h5 files.
* Allow the "AnyBodyCon" executable on path to have any valid windows executable extension (exe, bat, cmd etc.).
This will allow users to use custom shim of the AnyBodyCon executables to point else where.

## v1.12.2

Expand Down
2 changes: 1 addition & 1 deletion anypytools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"NORMAL_PRIORITY_CLASS",
]

__version__ = "1.12.2"
__version__ = "1.13.0"


def print_versions():
Expand Down
6 changes: 3 additions & 3 deletions anypytools/abcutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def execute_anybodycon(
macro.append("exit")

if not os.path.isfile(anybodycon_path):
raise IOError(f"Can not find anybodycon.exe: {anybodycon_path}")
raise IOError(f"Can not find anybodycon: {anybodycon_path}")

with open(macrofile_path, "w+b") as fh:
fh.write("\n".join(macro).encode("UTF-8"))
Expand Down Expand Up @@ -444,8 +444,8 @@ class AnyPyProcess(object):
This defaults to the number of logical CPU cores in the computer.
anybodycon_path : str, optional
Overwrite the default anybodycon.exe file to
use in batch processing. Defaults to what is found in the windows
registry.
use in batch processing. Defaults to 'AnyBodyCon' on path, or
to what is found in the windows registry.
timeout : int, optional
Maximum time (i seconds) a model can run until it is terminated.
Defaults to 3600 sec (1 hour).
Expand Down
14 changes: 5 additions & 9 deletions anypytools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,23 +553,19 @@ def get_anybodycon_path() -> str | None:
If AnyBodyCon.exe is on path it will take precedence over
the registry lookup.
"""
anybodycon_path = shutil.which("AnyBodyCon.exe")

if anybodycon_path:
return anybodycon_path

if not ON_WINDOWS:
wineprefix = Path(os.environ.get("WINEPREFIX", Path.home() / ".wine"))
abtpath = wineprefix / "drive_c/Program Files/AnyBody Technology"
anybodycon_paths = list(abtpath.glob("*/AnyBodyCon.exe"))
if anybodycon_paths:
return str(anybodycon_paths[-1])
else:
if not anybodycon_paths:
return None
return str(anybodycon_paths[-1])

anybodycon_path = shutil.which("anybodycon") or lookup_anybody_in_registry()

anybodycon_path = lookup_anybody_in_registry()
if "~" in anybodycon_path:
anybodycon_path = _expand_short_path_name(anybodycon_path)

return anybodycon_path


Expand Down
150 changes: 87 additions & 63 deletions docs/Tutorial/Tutorial_files/BatchProcess/Demo.Arm2D.any
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
/**
File: Demo.Arm2D.any

Copyright (c) 1999-2011, AnyBody Technology A/S

All rights reserved.



This is a demonstration of a simple arm model comprising
two degrees of freedom and a selected number of muscles.
Features in this model are

- definition of muscles
- application of muscle recruitment analysis in
the AnyBodyStudy
- redundancy of the muscle configuration

* definition of muscles
* application of muscle recruitment analysis in the AnyBodyStudy</li>
* redundancy of the muscle configuration</li>

The file has the following sections:
- The Arm Model
- Reference frames
- Segments
- Joints
- Drivers
- Loads
- Muscles
- "The body study"

* The Arm Model

* Reference frames
* Segments
* Joints
* Drivers
* Loads
* Muscles

* "The body study"

Notice that all these section could be separate files
that are assemble in a single main file by #include
statements. All include statements must be inside the
"Main = {};" statement in this main file.
``Main = {};`` statement in this main file.

*/
Main = {


// Control if the external load is applied
#ifndef CONFIG
#define CONFIG "Loaded"
#endif

AnyFolder InputVariables = {
AnyVar MassArm ??= DesignVar(2);
AnyString Configuration = CONFIG;
};


ArmModelStudy = {
AnyFolder OutputVariables =
{
AnyVar DeltodeusA = Main.ArmModel.Muscles.DeltodeusA.Activity;
AnyVar DeltodeusB = Main.ArmModel.Muscles.DeltodeusB.Activity;
AnyVar Brachialis = Main.ArmModel.Muscles.Brachialis.Activity;
AnyVar Brachioralis = Main.ArmModel.Muscles.Brachioralis.Activity;
AnyVar BicepsShort = Main.ArmModel.Muscles.BicepsShort.Activity;
AnyVar BicepsLong = Main.ArmModel.Muscles.BicepsLong.Activity;
};
};


// =======================================================
// The Arm Model
// =======================================================
Expand Down Expand Up @@ -67,7 +82,7 @@ AnyFolder ArmModel = {
AnySeg UpperArm = {
r0 = {0,0,-0.2};
Axes0 = {{0,0,1},{0,1,0},{-1,0,0}};
Mass = 2.0;
Mass = Main.InputVariables.MassArm;
Jii = {0.005,0.01,0.01};
AnyRefNode ShoulderNode = {
sRel = {-0.2,0,0};
Expand All @@ -82,14 +97,16 @@ AnyFolder ArmModel = {
AnyRefNode Brachioradialis = { sRel = {0.05,0,0}; };
AnyRefNode TricepsShort = { sRel = {-0.1,0,0}; };

AnyDrawSeg DrwSeg= {};
viewRefFrame.Visible = On;
viewInertia.Visible = On;
viewNodes.Visible = On;
};

//---------------------------------
AnySeg LowerArm = {
r0 = {0.2,0,-0.4};
Mass = Main.InputVariables.MassArm;
Jii = {0.005,0.01,0.01};
Mass = 1.5;
Jii = Mass*{0.005,0.01,0.01};
AnyRefNode ElbowNode = {
sRel = {-0.2,0,0};
};
Expand All @@ -102,7 +119,9 @@ AnyFolder ArmModel = {
AnyRefNode Biceps = { sRel = {-0.15,0,0}; };
AnyRefNode Triceps = { sRel = {-0.25,0,-0.05}; };

AnyDrawSeg DrwSeg= {};
viewRefFrame.Visible = On;
viewInertia.Visible = On;
viewNodes.Visible = On;
};

};
Expand Down Expand Up @@ -174,15 +193,22 @@ AnyFolder ArmModel = {
AnyFolder Loads = {

//---------------------------------
#if CONFIG == "Loaded"
AnyForce3D HandLoad = {
AnyRefNode &HandNode = ..Segs.LowerArm.HandNode;
F = {0,0,-100}; // Global force in Newton
viewForce.Visible = On;


AnyFloat FoutTest = Fout;
};
#endif

//---------------------------------
AnyForce ElbowTorque = {
AnyJoint& Jnt = ..Jnts.Elbow;
F = {10}; // Force, equivalent to torque in Newton
viewForce.Visible = On;
};


Expand All @@ -198,100 +224,113 @@ AnyFolder ArmModel = {
// We define one simple muscle model, which we will use
// use for all muscles
AnyMuscleModel MusMdl = {
F0 = 300;
F0 = 3000;
};

//---------------------------------
AnyViaPointMuscle DeltodeusA = {
AnyMuscleViaPoint DeltodeusA = {
AnyMuscleModel &MusMdl = .MusMdl;
AnyRefNode &Org = Main.ArmModel.GlobalRef.DeltodeusA;
AnyRefNode &Ins = ..Segs.UpperArm.DeltodeusA;
AnyDrawMuscle DrwMus = {
viewMuscle = {
Visible = On;
RGB = {149/256,51/256,55/256};
Bulging =1.0;
ColorScale =1.0;
RGBColorScale = {0.957031, 0.785156, 0.785156};
MaxStress = 50000; //N/m^2 //This number is for graphics only!
};

};

//---------------------------------
AnyViaPointMuscle DeltodeusB = {
AnyMuscleViaPoint DeltodeusB = {
AnyMuscleModel &MusMdl = .MusMdl;
AnyRefNode &Org = Main.ArmModel.GlobalRef.DeltodeusB;
AnyRefNode &Ins = ..Segs.UpperArm.DeltodeusB;
AnyDrawMuscle DrwMus = {
viewMuscle = {
Visible = On;
RGB = {149/256,51/256,55/256};
Bulging =1.0;
ColorScale =1.0;
RGBColorScale = {0.957031, 0.785156, 0.785156};
MaxStress = 50000; //N/m^2 //This number is for graphics only!
};

};


//---------------------------------
AnyViaPointMuscle Brachialis = {
AnyMuscleViaPoint Brachialis = {
AnyMuscleModel &MusMdl = .MusMdl;
AnyRefNode &Org = ..Segs.UpperArm.Brachialis;
AnyRefNode &Ins = ..Segs.LowerArm.Brachialis;
AnyDrawMuscle DrwMus = {
viewMuscle = {
Visible = On;
RGB = {149/256,51/256,55/256};
Bulging =1.0;
ColorScale =1.0;
RGBColorScale = {0.957031, 0.785156, 0.785156};
MaxStress = 50000; //N/m^2 //This number is for graphics only!
};

};

//---------------------------------
AnyViaPointMuscle Brachioralis = {
AnyMuscleViaPoint Brachioralis = {
AnyMuscleModel &MusMdl = .MusMdl;
AnyRefNode &Org = ..Segs.UpperArm.Brachioradialis;
AnyRefNode &Ins = ..Segs.LowerArm.Brachioradialis;
AnyDrawMuscle DrwMus = {
viewMuscle = {
Visible = On;
RGB = {149/256,51/256,55/256};
Bulging =1.0;
ColorScale =1.0;
RGBColorScale = {0.957031, 0.785156, 0.785156};
MaxStress = 50000; //N/m^2 //This number is for graphics only!
};

};

//---------------------------------
AnyViaPointMuscle BicepsShort = {
AnyMuscleViaPoint BicepsShort = {
AnyMuscleModel &MusMdl = .MusMdl;
AnyRefNode &Org = ..Segs.UpperArm.BicepsShort;
AnyRefNode &Ins = ..Segs.LowerArm.Biceps;
AnyDrawMuscle DrwMus = {
viewMuscle = {
Visible = On;
RGB = {149/256,51/256,55/256};
Bulging =1.0;
ColorScale =1.0;
RGBColorScale = {0.957031, 0.785156, 0.785156};
MaxStress = 50000; //N/m^2 //This number is for graphics only!
};

};

//---------------------------------
AnyViaPointMuscle TricepsShort = {
AnyMuscleViaPoint TricepsShort = {
AnyMuscleModel &MusMdl = .MusMdl;
AnyRefNode &Org = ..Segs.UpperArm.TricepsShort;
AnyRefNode &Ins = ..Segs.LowerArm.Triceps;
AnyDrawMuscle DrwMus = {
viewMuscle = {
Visible = On;
RGB = {149/256,51/256,55/256};
Bulging =1.0;
ColorScale =1.0;
RGBColorScale = {0.957031, 0.785156, 0.785156};
MaxStress = 50000; //N/m^2 //This number is for graphics only!
};

};

//---------------------------------
AnyViaPointMuscle BicepsLong = {
AnyMuscleViaPoint BicepsLong = {
AnyMuscleModel &MusMdl = .MusMdl;
AnyRefNode &Org = Main.ArmModel.GlobalRef.BicepsLong;
AnyRefNode &Ins = ..Segs.LowerArm.Biceps;
AnyDrawMuscle DrwMus = {
viewMuscle = {
Visible = On;
RGB = {149/256,51/256,55/256};
Bulging =1.0;
ColorScale =1.0;
Expand All @@ -301,11 +340,12 @@ AnyFolder ArmModel = {
};

//---------------------------------
AnyViaPointMuscle TricepsLong = {
AnyMuscleViaPoint TricepsLong = {
AnyMuscleModel &MusMdl = .MusMdl;
AnyRefNode &Org = Main.ArmModel.GlobalRef.TricepsLong;
AnyRefNode &Ins = ..Segs.LowerArm.Triceps;
AnyDrawMuscle DrwMus = {
viewMuscle = {
Visible = On;
RGB = {149/256,51/256,55/256};
Bulging =1.0;
ColorScale =1.0;
Expand All @@ -322,26 +362,10 @@ AnyFolder ArmModel = {
// =======================================================
// "The body study"
// =======================================================
AnyBodyStudy Study = {
AnyBodyStudy ArmModelStudy = {
AnyFolder& Model = Main.ArmModel;
Gravity = {0,0,-9.81};
nStep = 40;

AnyOutputFile FileOutput = {
// Write output to a csv file with the number of steps in filename
FileName = "Output/TestOutput_"+ANYBODY_NAME_MAINFILEDIR+ ".csv";
Header = {
TitleSectionOnOff = Off;
ConstSectionOnOff = Off;
VarSectionOnOff = Off;
ColumnNamesOnOff = On;
};
AnyFloat MaxMusAct = .MaxMuscleActivity;
AnyFloat ElbowAngle = .Model.Drivers.ElbowMotion.Pos;
AnyFloat BicepsLong = .Model.Muscles.BicepsLong.Activity;
};



};


Expand Down
Loading

0 comments on commit 1c8a64e

Please sign in to comment.