Professional Documents
Culture Documents
Workbench Scripting PDF
Workbench Scripting PDF
ANSYS Workbench
Scripting in
ANSYS 12
12.1
1
November 2009
Agenda
Scripting Overview
ANSYS 12.1 fully supports Workbench journaling and
scripting
Project concepts & operations
Parameter
P
t managementt
Native applications
Project Schematic
Schematic, Design Exploration
Exploration, Engineering Data
Journaling
Workbench operations are recorded in a
journal file
Only
O l operations
ti
which
hi h modify
dif d
data
t model
d l
Files have *.wbjn extension
Each session creates a new journal file
Playing back the journal recreates the session
Journals should not be confused with log files
Log
L fil
files record
d specific
ifi W
Workbench
kb
h events
t
Log files cannot be replayed
2009 ANSYS, Inc. All rights reserved.
Journaling
Two types of Workbench journals
Automatically recorded session journals
Restore work from a complete session
NOT designed to archive simulation projects
Replaying Journals
Replay a journal at any time during an
interactive session
File
Fil Scripting
S i ti Run
R S
Script
i t Fil
File
Replaying Journals
A journal can also be replayed from the
command line
Add R
R <filename.wbjn>
fil
bj
Add I for interactive mode or B for batch
Operation
Run Workbench in batch mode. The user interface is not
displayed and a console window is opened. The functionality of
the console window is the same as the Workbench Command
Window.
-X
-F
F <ANSYS W
Workbench
kb
h Load
L d the
th specified
ifi d Workbench
W kb
h project
j t file
fil on start-up.
t t
project file>
-E <command>
Command Window
Scripting commands can be entered manually
in Command Window
11
Command Window
Command Window supports:
Command completion
Command history
Keyboard
y
shortcuts for cursor navigation
g
and
editing
12
Scripting Basics
Script: a set of instructions to be issued to
Workbench
Can
C b
be a modified
difi d jjournall or a completely
l t l new
set of instructions written directly
Scripts and journals use the same programming
languagePython
Use scripts for:
Automating repetitive tasks
Performing Workbench operations in batch
mode
2009 ANSYS, Inc. All rights reserved.
13
14
Methods
Method: command that is bound to an object
Can change property values, create or delete
properties,
ti
or iinvoke
k complex
l calculations
l l ti
and
d
operations
Like properties, methods are accessed via dot
operator
parameter1.SetQuantityUnits("m")
parameter1 is an object of type Parameter
SetQuantityUnits
y
is a method called to set the
objects units to meters
2009 ANSYS, Inc. All rights reserved.
15
Parameter = DOEModel.GetParameter(Name="P1")
O
d l G
(
" 1")
Parameter.Nature = "NatureUsability"
Parameter.AddLevels(Levels=["65","70","75","80
"])
Note: Python
y
is a loosely-typed
y yp language;
g g you
y do not
need to declare variables.
2009 ANSYS, Inc. All rights reserved.
16
17
System:
A collection of components that
together provide a workflow to
achieve an engineering
simulation goal.
Systems are created from
System Templates.
18
Component:
A collection of data and a data
editor that work together to
achieve a CAE-related task.
A Component is represented
by a Cell in the Workbench
Project Schematic.
19
20
Data Entity:
A data structure defined within a
d
data
container.
i
Ad
data
container often has several data
entities.
21
Example:
Change a Material Property
# Q
Query
y for the static structural analysis
y
template
p
ss_template = GetTemplate(TemplateName="Static Structural",
Solver="ANSYS")
# Create an analysis system from the template
ss_system
= ss_template.CreateSystem()
# Query for the Engineering Data container
ed_container = ss_system.GetContainer(ComponentName="Engineering Data")
# Q
Query f
for th
the material
t i l d
data
t entity
tit i
in th
the d
data
t container
t i
steel = ed_container.GetMaterial(Name="Structural Steel")
# Query for the property data entity associated with structural steel
elasticity = steel.GetProperty(Name="Elasticity")
# Set Youngs
Young s modulus
elasticity.SetData(Variables="Young's Modulus", Values=2E+11)
2009 ANSYS, Inc. All rights reserved.
22
Data-Integrated Applications
Native applications
Built entirely on new Workbench Framework
Fully supported by Workbench scripting
E.g.,
g Project
j
Schematic, Design
g Exploration,
p
Engineering Data
Data-integrated applications
Share data and parameters with Workbench,
native
ti applications,
li ti
and
d other
th d
data-integrated
t i t
t d
applications
Created independently
p
y from new Workbench
Framework
Often have their own scripting languages
E.g.,
E
M h i l Mechanical
Mechanical,
M h i l APDL
APDL,
CFX, FLUENT, DesignModeler
2009 ANSYS, Inc. All rights reserved.
23
Data-Integrated Applications
Application
Application-level
level scripting can be embedded in a
Workbench script
APDL,
APDL CCL
CCL, Scheme
Scheme, JScript,
JScript etc.
etc
Some data-integrated applications record their
operations in the Workbench journal
CFX, FLUENT
24
Example:
Create Geometry
The following Workbench script sketches an elliptical
curve in DesignModeler:
# create a geometry system
system = GetSystem(Name="Geom")
# query the data container of the geometry system
geometry = system.GetContainer(ComponentName="Geometry")
# send a JScript command to DM to create an ellipse
geometry.SendCommand(Command = """var ps1 = new Object();
ps1.Plane = agb.GetActivePlane();
ps1.Origin = ps1.Plane.GetOrigin();
ps1.XAxis = ps1.Plane.GetXAxis();
ps1.YAxis = ps1.Plane.GetYAxis();
ps1.Sk1
1 Sk1 = ps1.Plane.NewSketch();
1 Pl
N Sk t h()
ps1.Sk1.Name = "Sketch1";
with (ps1.Sk1) { ps1.El7 = Ellipse( 8.0, 10.0, 9.0,
6 0 5
6.0,
5.0,
0 12
12.0);
0); }
agb.Regen();""")
2009 ANSYS, Inc. All rights reserved.
25
Documentation
Online Help includes:
Overview
How-to
Complete
C
command reference
f
Many examples
26
27
28
29