Custom Python Scripts to Retrieve and Update Parameters Not Supported by Component

The component allows you to supply custom Python scripts to retrieve and update parameters that are not supported by the component.

This page discusses:

The ANSYS Workbench component executes two specific user-supplied Python modules if you select Use Custom Script in the Advanced tab. The names of these modules must be userscript_dt.py (designtime script) and userscript_rt.py (runtime script). You can use these scripts to perform desired operations on those parameters that are not supported by the ANSYS Workbench component.

You can define only one, both, or neither of these modules. The component executes the designtime module (userscript_dt.py) after opening the ANSYS Workbench project file. Specific functions in the runtime module (userscript_rt.py) are executed before and after updating the ANSYS Workbench project.

Sample Designtime Script (userscript_dt.py)

import os

def runUserScript(projPath):

"""	
Before this function is called, the ANSYS Workbench project is already
open and the user should not reopen or close it.

This function gets called after fetching the PIDO parameters.

This function will accept a single parameter containing the path of the
user's work directory where the .wbpj file is located.

This function is required to create two text files, user_input_params.txt &
user_output_params.txt, in the user's work directory. As the name suggests, 
these two files must contain custom input & output parameter name-value pairs 
separated by "::". Each pair should be written on a separate line.

In the following code we are creating two dummy parameters - inputParam1 & 
outputParam1.

Note: The decimal point character should be ".", irrespective of the locale.
"""

with open(projPath + os.path.sep + "user_input_params.txt", "w") as inputFile:
inputFile.write("inputParam1::1.2")

with open(projPath + os.path.sep + "user_output_params.txt", "w") as outputFile:
outputFile.write("outputParam1::2.3")

Sample Runtime Script (userscript_rt.py)

import os

def runSetUserValues(projPath, custInputParamsDict):

"""
Before this function is called, the ANSYS Workbench project is already 
open and the user should not reopen or close it.

This function accepts two parameters.

1. projPath -> It contains the runtime directory path where the .wbpj 
file gets copied.

2. custInputParamsDict -> It is a Python dictionary object, and it 
contains the updated custom input param name-value pairs.

In this function, the user needs to update the values for the custom 
input parameters of the ANSYS Workbench project, located at the provided 
projPath to get the updated values of the custom output parameters.

Below is an example of how to get the custom input parameters created 
by the user.
"""

if (custInputParamsDict.__len__() > 0):	
for k, v in custInputParamsDict.iteritems():

# You should write code here to update value of parameter
# 'k' in ANSYS Workbench model with a new value 'v'

def runUserScript(projPath):
"""

This function gets called after solving the ANSYS Workbench project.

It accepts a single parameter containing the user's runtime directory 
path where the .wbpj file gets copied.

From this function, the user should fetch the custom output parameters
from the ANSYS Workbench project, and they should be written in a text 
file (user_output_params.txt) with name and value separated by "::". 
Each parameter is written on a separate line, as shown in the following 
code.

Note: The decimal point character should be ".", irrespective of the 
locale.

"""

with open(projPath + os.path.sep + "user_output_params.txt", "w") as outputFile:
outputFile.write("outputParam1::2.4")