Workshop-1
External Connection with a Python code
1 © 2011 ANSYS, Inc. November 29,
2012
Objectives
This workshop demonstrates
• How to use External connection system in Workbench with
third-party software
– How to update WB input parameters using output
parameters from other software
2 © 2011 ANSYS, Inc. November 29,
2012
Prerequisites
This workshop assumes that you have reviewed
• Introduction to External Connection.pptx
Start with “update.py” file
• This Python file is our “External Application”
– Reads the input parameters from a file
• For display purpose only (not used in WB)
– Performs some calculation
• Could also invoke an external code
– Read a output parameter file
Use
– InputParams.dat The input parameters for the external
application
– OutputParams.dat The output from the external application…
to be used in WB for updating the geometry length
– Box.wbpj project
• Length already defined as an input parameter
3 © 2011 ANSYS, Inc. November 29,
2012
Information
“SimpleExternal.xml” performs following functions
• Reads area and width from “InputParams.dat” and creates input parameters in WB
– For display purpose only (not used in WB)
• Execute a external code (update.py)
• Reads length from “OutputParams.dat” and creates an output parameter in WB
– For use in WB to update the geometry length
“update.py” needs to performs the following actions
• Read area and width from “InputParams.dat”
• Calculate length and writes to “OutputParams.dat”
4 © 2011 ANSYS, Inc. November 29,
2012
The external (Python) code
A similar function has been
explained in the Workshop-2
in WB Python Scripting
Instead of doing the computation here,
one could invoke an external
application and wait for that to
generate the OutputParams.dat file
5 © 2011 ANSYS, Inc. November 29,
2012
Steps
• Create an “SimpleExternal.xml” file
– Explained in next few slides
• Keep the “InputParams.dat” and “OutputParams.dat”
in the working directory
• Open “Box.wbpj” file
• Create External Connection System
– Read “SimpleExternal.xml” file using Read
configuration
• Update the External Connection System
• Link the External Connection parameter “Length” to
“Box1.Length”
6 © 2011 ANSYS, Inc. November 29,
2012
Creating the XML file
Refer to documentation // External Connection Add-in // External
Connection Add-in :: 0 // Process Configuration XML File Details
The <Configuration> node contains the
<Instructions> and other attributes such as:
• SystemName - This is the user-visible string that is
assigned to the system
• CellName - This is the user-visible string that is
assigned to the cell
The information related to initialization (including
parameters definition) and update is provided
inside the global <Instructions> node. A
WorkingDirectory is defined inside the Instructions
node
Refer to next slide on ‘format’
7 © 2011 ANSYS, Inc. November 29,
2012
Creating the XML file (2)
[ Instruction Type ] - The type determines where the
instruction will be executed.
• Init - The parameter will be executed when the
configuration is read
• Update - The parameter will be executed when the project
is updated
8 © 2011 ANSYS, Inc. November 29,
2012
Creating the XML file (3)
[ Parameter Name ] - A unique name that represents a single
parameter in the Workbench environment.
[ Type ] - The general type of the parameter. It must be one of two
possible values:
• Input
• Output
[ Rule Name ] - A name given to the XML node that represents a single
parsing rule for the parameter defined by the rule's parent node.
Multiple rules can be defined for each parameter.
[ Rule Type ] - The type of the rule defined. This can be one of the
following values.
• File - The file rule defines the text file that contains the parameter
value.
• PreString - The text that immediately precedes the actual parameter
value in the file.
• DataType - Describes the type of data that represents the parameter.
9 © 2011 ANSYS, Inc. November 29,
2012
Linking output from ExternalConnection to Box length
P1 is constant
P1 is linked to P5
External Connection system and
the Parameters
10 © 2011 ANSYS, Inc. November 29, Need to solve as input parameter value changed
2012