Ansys Products

Ansys Products

Discuss installation & licensing of our Ansys Teaching and Research products.

Problem with running the script at startup ICEM

TAGGED: ,

    • Turex Siv
      Subscriber

      Hello, Please help me understand the problem.

      Created a script in TCL (test1.tcl):
      proc test1 { } {
         mess "*** start script ***\n"
      }

      test1

      I launch it in ICEM CFD when starting from a bat file:
      "%ICEMCFD_ROOT145%\win64_amd\bin\icemcfd.bat" -script test1.tcl

      The script is executed at startup, the message is displayed on the ICEM CFD command line, but when I then try to call my function on the command line again:
      test1
      then the error occurs:
      Error: invalid command name "test1"

      ICEM CFD forgot about my function.
      If I load the script from the ICEM command line:
      source test1.tcl
      then after this my function is executed again, now ICEM has remembered it.
      The ICEM programming documentation says that all 4 methods of loading scripts are equivalent.
      What's the matter? How do I make ICEM remember my functions after loading via -script?

      Windows 10. ANSYS 2022R2, ANSYS 14.5.7

    • mjmiddle
      Ansys Employee

      The "ICEM CFD Scripting Basics" section mentions 4 ways to run your script, but does not say that procedures defined with these different methods can communicate with each other.

      ICEM CFD has a scripting interpreter, GUI interpreter, and batch interpreter. A Tcl interpreter is an isolated code space that can have certain protections set. Sometimes interpreters can communicate with each other depending on the protections set. When you launch ICEM CFD by command line with the -script argument, it runs this script in the script interpreter. When you run script inside the ICEM CFD message window, by typing individual commands or with the "source" command it is run in the gui interpreter. It is not easy to call functions and variables from the gui interp that are defined in the script interp.

      ic_gui_set allows gui_interp access from the script_interp that is used with "icemcfd -script" startup.

      one argument retrieves variable value.
      two arguments sets a variable value.
      Three or more arguments executes a function.  Include a blank 3rd argument to make 3 if only sending 1 argument to function.
      Only works, though, for procedures that take in 2 arguments or more.
      If 3rd arg is blank, such as {}, then it will not return the value of the function. ic_gui_set needs 3 or more non-blank args to return a function value.

    • mjmiddle
      Ansys Employee
      Example:
      set viewer [ic_gui_set tdv_default]
      ic_load_tetin box.tin
      # This does iso view:
      set pi 3.1415926
      set pi4 [expr {$pi / 4.0}]
      # ic_gui_set tdv_rot($viewer) {0 0 0 1}
      ic_gui_set tdv_rotate_axis $viewer 0 1 0 $pi4
      ic_gui_set tdv_rotate_axis $viewer 1 0 0 -$pi4
      # requires redraw after tdv_rotate_axis where tdv_along_axis does not
      ic_gui_set tdv_trans_update $viewer 1
      ic_gui_set tdv_scale_to_fit $viewer {}
       
      # Since "aie_view top" takes one 1 argument, use the call that takes 2:
      #ic_gui_set tdv_along_axis $viewer -y
    • mjmiddle
      Ansys Employee

      My previous example showed calling functions and variables from the script interp that are defined in the gui interp. Going the other way seems easier. Do this to call your test1 procedure from the ICEM CFD message window:

      interp eval script_interp test1

    • Turex Siv
      Subscriber

      Thank you very much for your answer, this explains the behavior of ICEM.

      I was able to load my scripts into gui_interp at startup ICEM:

      ic_gui_set eval source test1.tcl

      Apparently I misunderstood the documentation:

      "All 4 methods can be used with the GUI displayed, but only the last two can be done in batch mode. source D:/user/script.tcl can be typed in the message window, or ANSYS ICEM CFD can be started in batch mode by adding the -batch argument to the ANSYS ICEM CFD startup command (icemcfd -batch). Then you can source the script from the shell."

Viewing 4 reply threads
  • The topic ‘Problem with running the script at startup ICEM’ is closed to new replies.