2.5. Text Menu Input from Character Strings

When writing a Scheme extension function for Ansys Fluent, it is often convenient to be able to include menu commands in the function. This can be done with ti-menu-load-string. For example, to open graphics window 2, use

(ti-menu-load-string "di ow 2") 

A Scheme loop that will open windows 1 and 2 and display the front view of the mesh in window 1 and the back view in window 2 is given by

(for-each
 (lambda (window view)
   (ti-menu-load-string (format #f "di ow ~a gr view rv ~a"
 window view)))
 ’(1 2)
 ’(front back)) 

This loop makes use of the format function to construct the string used by menu-load-string. This simple loop could also be written without using menu commands at all, but you need to know the Scheme functions that get executed by the menu commands to do it:

(for-each
 (lambda (window view)
   (cx-open-window window)
   (display-mesh)
   (cx-restore-view view))
 ’(1 2) ’(front back)) 

String input can also provide an easy way to create aliases within Ansys Fluent. For example, to create an alias that will display the mesh, you could type the following:

(alias ’dg (lambda () (ti-menu-load-string "/di gr"))) 

Then any time you enter dg from anywhere in the menu hierarchy, the mesh will be drawn in the active window.


Important:   ti-menu-load-string evaluates the string argument in the top level menu. It ignores any menu you may be in when you invoke ti-menu-load-string.

As a result, the command

(ti-menu-load-string "open-window 2 gr") ; incorrect usage 

Will not work even if you type it from within the display/ menu—the string itself must cause control to enter the display/ menu, as in

 (ti-menu-load-string "display open-window 2 mesh")