hexagon logo

Can we use Python commands in commands attributes during creating custom dialogue box?

Can we use Python commands in commands attributes during creating custom dialogue box?
  • Hi,
     
    You can use something like this in your dbox definition (some manual edits to the cmd):
    !
    interface dialog_box create &
      dialog_box_name = .gui.dbox1 &
      location = 844.0, 281.0 &
      height = 200.0 &
      width = 400.0 &
      units = pixel &
      horiz_resizing = scale_all &
      vert_resizing = scale_all &
      title = "dbox1" &
      iconifiable = no &
      start_commands = "var set var=$_self.ans int=(eval(run_python_code('test_module.execute_some_commmands()')))" &
    ....
     
    !
    language switch_to python
    import test_module
    Adams.switchToCmd()
    !
     
    I hope this helps.
     
    Regards,
    Rishi
  • Hello I used below python commands after cmd command for dialogue box.
     
    language switch_to python
    import Adams
    import os
    import glob
    def copy_files(source_pattern, destination_file):
    with open(destination_file, 'w') as output_file:
    for filename in glob.glob(source_pattern):
    with open(filename, 'r') as input_file:
    for line in input_file:
    output_file.write(line)
    if __name__ == '__main__':
    source_pattern = 'Run_Angle_*.acf'
    destination_file = 'Simscript_Run.acf'
    copy_files(source_pattern, destination_file)
     
    I used these python command to copy texts from all acf file into one single acf file titled Simscript_Run.acf
     
    but it is not working
     
    If I execute separate python code (not in adams) it copies as expected.
     
    Or if it is possible to create single acf files for multiple runs.
  • I recently had a case where blank chars did not work inside cmd-language.
    I.e. language switch_to python allows only for commands starting at the very beginning if the line without indentation.
    Thus I suspect your def() and if statements don't work.