def initialize_operations(self): """build the macrolist executed by AnyPyTools""" operation_cmd = { AnyPy.LOAD: Load(self.main_filepath), AnyPy.INITIAL_CONDITIONS: OperationRun('Main.Study.InitialConditions'), AnyPy.KINEMATICS: OperationRun('Main.Study.Kinematics'), AnyPy.INVERSE_DYNAMICS: OperationRun('Main.Study.InverseDynamics'), # AnyPy.SET_ORDER: SetValue('Main.HumanModel.Mannequin.InterpolationFunctions.intorder', # env.config.order), AnyPy.SAVE_H5: SaveData('Main.Study', self.output_path), AnyPy.DUMP_JOINT_ANGLES: Dump('Main.Study.Output.JointAngleOutputs'), AnyPy.DUMP_STEPS: Dump('Main.Study.nStep'), AnyPy.DUMP_LEAP_VECTORS: Dump('Main.HumanModel.Mannequin.Posture.Right') } if env.config.load: self.add_operation(AnyPy.LOAD) if env.config.initial_conditions: self.add_operation(AnyPy.INITIAL_CONDITIONS) if env.config.kinematic: self.add_operation(AnyPy.KINEMATICS) if env.config.inverse_dynamics: self.add_operation(AnyPy.INVERSE_DYNAMICS) if env.config.nstep: self.set_step() # if env.config.order: # self.add_operation(AnyPy.SET_ORDER) if env.config.plot: # requirement for plot is run of kinematic analysis self.add_operation(AnyPy.LOAD) self.add_operation(AnyPy.KINEMATICS) # dump interpolated joint angles self.add_operation(AnyPy.DUMP_JOINT_ANGLES) # dump nStep self.add_operation(AnyPy.DUMP_STEPS) # dump Mannequin vectors including the joint angles from the bvh file self.add_operation(AnyPy.DUMP_LEAP_VECTORS) if self.output_path: # save study output to hdf5, to view and replay analysis later self.add_operation(AnyPy.SAVE_H5) for operation in self.operations: self.macrolist.append(operation_cmd[operation])
def Create_Macro(Height): #creates the macro containing the AMS-operations F_or_L = 'Lower' Body_Height = 1.8 BW = 96.84 Fat_Percentage = 31.33 Mechanical_Output = 5 Cadence = 5 Saddle_Height = Height Saddle_Pos = -0.26 Pedal_Arm_Length = 0.2 Pedal_Arm_Width = 0.107 macro = [ Load('../Application/Examples/BikeModel/BikeModel-' + F_or_L + 'Body.main.any'), SetValue('Main.HumanModel.Scaling.Scaling.AnthroData.body_height', Body_Height), SetValue('Main.BikeParameters.MechOutput', Mechanical_Output), SetValue('Main.BikeParameters.Cadence', Cadence), SetValue('Main.BikeParameters.SaddleHeight', Saddle_Height), SetValue('Main.BikeParameters.SaddlePos', Saddle_Pos), SetValue('Main.BikeParameters.PedalArmLength', Pedal_Arm_Length), SetValue('Main.BikeParameters.PedalArmWidth', Pedal_Arm_Width) ] macro.append( SetValue('Main.HumanModel.Scaling.Scaling.AnthroData.Body_Mass', BW)) macro.append( SetValue('Main.HumanModel.Scaling.Scaling.FatPercent', Fat_Percentage)) macro.append(OperationRun('Main.RunApplication')) macro.append( Dump( 'Main.Study.Output.Model.HumanModel.Right.Leg.InterfaceFolder.HipJoint_SeqZYX.HipFlexion.Pos' )) return macro
def Check_Scaling(Height): F_or_L = 'Lower' Body_Height = 1.8 Mechanical_Output = 5 Cadence = 5 Saddle_Height = Height Saddle_Pos = -0.25 Pedal_Arm_Length = 0.2 Pedal_Arm_Width = 0.107 macro = [ Load('../Application/Examples/BikeModel/BikeModel-' + F_or_L + 'Body.main.any'), SetValue('Main.HumanModel.Scaling.Scaling.AnthroData.body_height', Body_Height), SetValue('Main.BikeParameters.MechOutput', Mechanical_Output), SetValue('Main.BikeParameters.Cadence', Cadence), SetValue('Main.BikeParameters.SaddleHeight', Saddle_Height), SetValue('Main.BikeParameters.SaddlePos', Saddle_Pos), SetValue('Main.BikeParameters.PedalArmLength', Pedal_Arm_Length), SetValue('Main.BikeParameters.PedalArmWidth', Pedal_Arm_Width) ] macro.append(OperationRun('Main.Study.InitialConditions')) Check_study_macro = AnyMacro(macro) Check_results = app.start_macro(Check_study_macro) Error_Storage = [] for data in Check_results: #checks every result entry if 'ERROR' in data: #if there has been an error during the operations, its likely to be an error caused by the scaling fo the bike or the model Error_Storage.append(1) if len(Error_Storage) == 0: return 'OK' else: return 'Error'
def run_model(saddle_height, saddle_pos, silent=False): """Run the AnyBody model and return the metabolism results""" macro = [ Load("BikeModel2D.main.any"), SetValue("Main.BikeParameters.SaddleHeight", saddle_height), SetValue("Main.BikeParameters.SaddlePos", saddle_pos), OperationRun("Main.Study.InverseDynamics"), Dump("Main.Study.Output.Pmet_total"), Dump("Main.Study.Output.Abscissa.t"), ] app = AnyPyProcess(silent=silent) results = app.start_macro(macro) return results[0]
def post_operations(self): macro_output_path = 'classoperation Main.Study.Output "Load data" --file="{}"'.format( self.output_path) """build the macrolist executed by AnyPyTools""" operation_cmd = { AnyPy.LOAD: Load(self.main_filepath), AnyPy.LOAD_H5: MacroCommand(macro_output_path), AnyPy.REPLAY: OperationRun("Main.Study.ReplayKinematics") } self.macrolist = [] for operation in operation_cmd: self.macrolist.append(str(operation_cmd[operation])) print('Starting Anybody with the macros:\n{}'.format(self.macrolist)) print('Executing "{}" in "{}"'.format(self.any_path, self.any_model)) # save current working directory and change to Anybody project folder cwd = os.getcwd() os.chdir(self.any_path) # write macro file to be opened by AnyBody GUI macro_replay_path = os.path.join(self.any_path, 'replay.anymcr') with open(macro_replay_path, 'wb') as macro_file: macro_file.write("\n".join(self.macrolist).encode("UTF-8")) macro_file.flush() anybodycmd = [ os.path.realpath( 'C:/Program Files/AnyBody Technology/AnyBody.7.1/AnyBody.exe' ), "-m", macro_file.name ] # execute AnyBody GUI with the command from anybodycmd subprocess.Popen(anybodycmd) # change back to original folder os.chdir(cwd)
from anypytools import AnyPyProcess from anypytools.macro_commands import Load, OperationRun app = AnyPyProcess(num_processes=3) macro = [Load("main.any"), OperationRun("Main.Study.InverseDynamics")] app.start_macro(macro, search_subdirs="model[1-9].*main.any")
from anypytools import AnyPyProcess from anypytools.macro_commands import Load, OperationRun app = AnyPyProcess(num_processes = 3) macro = [Load("main.any"), OperationRun('Main.Study.InverseDynamics') ] app.start_macro(macro, search_subdirs= "model[1-9].*main.any" )