4.4.2. Scripting

Scripting refers to the processes of editing and running a journal file in Ansys Workbench. You can create your own scripts and include the power of Python to implement high-level programming constructs for input, output, variables, and logic. The example that follows illustrates this for CFD-Post.

4.4.2.1. Example: Using a Script to Change an Existing Locator

If you have an Ansys Workbench project currently open, you can run a script to change how the results of the simulation are post-processed. For example, if you have opened CFD-Post from an Ansys Workbench system and CFD-Post is displaying a plane named "Plane 1", you can run the following script to change the plane to be colored by the variable Velocity or Pressure.

Before running this script, you would have to first open the Command Window dialog box (by selecting File > Scripting > Open Command Window from the Ansys Workbench main menu). To run the script, you would select File > Scripting > Run Script File from the Ansys Workbench main menu and then use the browser to open the file containing the script.

x = int(raw_input("Enter an integer: 1=Velocity, 2=Pressure: "))

if x == 1:
		print 'Velocity'
		CFX.SendCommand(
			Container="Results",
			Command="""PLANE:Plane 1
			Colour Mode = Variable
			Colour Variable = Velocity
		END""")

elif x == 2:
		print 'Pressure'
		CFX.SendCommand(
			Container="Results",
			Command="""PLANE:Plane 1
			Colour Mode = Variable
			Colour Variable = Pressure
		END""")

Depending on the value of x you input in the Command Window, the script includes the CCL in the appropriate CFX.SendCommand argument to set the values for Colour Mode and Colour Variable in the PLANE:Plane 1 object for either the Velocity or Pressure variable.