hexagon logo

I am trying create .bat file to run .acf within gui dialogue box, but facing the issue in writing bat file.

simulation set solver_preference = write_files_only
simulation set save_files = yes
simulation set file_prefix = (eval("$f_prefix"))
simulation single scripted &
sim_script_name = $f_script_name
 
language switch_to python
import Adams
with open('$f_prefix.bat', 'w') as file:
pass
import Adams
import glob
import subprocess
 
bat_file = $f_prefix.bat
 
bat_content = """
@echo off
SET MDI_ADAMS_RETRY=10
title bat_test
call C:/Progra~1/MSC.Software/Adams/2023_4/common/mdi.bat ru-s $f_prefix.acf
"""
with open(bat_file, 'w') as f:
f.write(bat_content.strip())
   
Parents
  • We're using bat/csh files a lot.

    The simple solution is to use 

    file text open file = "xxx.bat"

    then several lines of 

    file text write 

    and a 

    file text close

    At the end call it via system command = "xxx.bat"

    Works loke a charm.

    I tried the switch language mode a couple of times, but it didn't behave well (quite similar to your issues) and also it didn't have any huge speed advantage.

    My solution was to write complete xxx.py scripts and read them like

    file python read file = "xxx.py"

Reply
  • We're using bat/csh files a lot.

    The simple solution is to use 

    file text open file = "xxx.bat"

    then several lines of 

    file text write 

    and a 

    file text close

    At the end call it via system command = "xxx.bat"

    Works loke a charm.

    I tried the switch language mode a couple of times, but it didn't behave well (quite similar to your issues) and also it didn't have any huge speed advantage.

    My solution was to write complete xxx.py scripts and read them like

    file python read file = "xxx.py"

Children
No Data