Você está na página 1de 22

Introduction to IronPython Console extension

1 © 2011 ANSYS, Inc. December 3, 2012


Agenda
• The IronPython Console extension

• Using this extension for


– For navigating through the ACT APIs
– Interactive testing of the ACT commands
– Data access
– Debugging

2 © 2011 ANSYS, Inc. December 3, 2012


The IronPython Console extension
This extension is installed along with the
Workbench R14.5
This extension provides an interactive
environment to help the ACT developers
One can:
• Find out suitable commands for his/her extension
• Test code pieces even before developing an
extension
• Debug developed extensions

ANSYS Customization Suite license to required for


using this extension

3 © 2011 ANSYS, Inc. December 3, 2012


Using the extension

Extensions list

Command Line Editor

Information Window

Functions List

Command Output Window

4 © 2011 ANSYS, Inc. December 3, 2012


Data Access

5 © 2011 ANSYS, Inc. December 3, 2012


ExtAPI.Application
ExtAPI is the entry point for all data access

1 2

Type: ExtAPI. in the Command Line Type: ExtAPI.Application. to see


Editor to see available objects available objects under Application

3 4

This is a function. It requires Type a test message and press ‘Enter’


a single argument ‘msg’ of key to log the error message
‘str’(string) type
*always ignore ‘self’+

5
Select: ExtAPI.Application.LogError to
6 see©how to use
2011 ANSYS, Inc. it December 3, 2012
ExtAPI.SelectionMgr
First, select any geometric entity (example: a face) 2

1
Type: ExtAPI.SelectionMgr. to see
available objects under Application

Type: ExtAPI. in the Command Line


Editor to see available objects This returns a list of integers

Select: Ids to see what it offers and


3
press ‘Enter’ key to get the output

This is a class. So, we will get more


information by going inside it.

Select: ExtAPI.SelectionMgr.CurrentSelection The command output window shows


to
7 see how
© 2011 toInc.
ANSYS, use it December 3, 2012 the list of Ids under CurrentSelection
ExtAPI.DataModel
Lets get information on Geometry
ExtAPI.DataModel is the entry point for all data access from Model 2

1 GeoData is our
entry point for
Store the list of Ids under CurrentSelection Geometry related
data access
to a variable (e.g. myIds)
3

GeoData could also be reach via


GeoEntityById is a function. The input is an “id” and it
returns the geometric entity object reference.
ExtAPI.DataModel.AnalysisList[0].GeoData
From the returned object, we can get more information

4 5
Store the geometric entity as a
variable (e.g. myE)
See what is available under myE
Access the required data
Example: Area, No. of Edges, Body Id,
8 © 2011 ANSYS, Inc. December 3, 2012
Material for the Body,…
ExtAPI.DataModel (2)
Lets get more information on Mesh 2
1

MeshData is our Store the mesh reference as a


entry point for
Mesh related data variable (e.g. mesh)
access Access required data (e.g. Node and
Element counts etc.)
MeshData could also be reach via
ExtAPI.DataModel.MeshDataByName('Global') 4

Access the node-element connectivity


Access mesh data for the selected information (e.g. Nodes for Element ids 1
geometric entity & 4, Elements for node id 1, 209)

9 © 2011 ANSYS, Inc. December 3, 2012


ExtAPI.DataModel (3)
Lets get more information on Results

1 2

ResultsData is our
entry point for
Results related data
access

•Store the result reference as a variable


ResultName gives us a list of available (e.g. res)
results •Check available components for result “U”
Result function takes a result name as •Store the node ids on the selected entity
input and returns the result object (e.g. nIds)
•Access the X-Displacement nodal results
10 © 2011 ANSYS, Inc. December 3, 2012
on the stored node ids
Using an external module
• Ability to import and use external modules makes ACT even more powerful
• There are some predefined modules available under ‘library’
Some predefined modules in ‘library’. Example:
• units.py  for many unit conversion utilities
• materials.py  access Engineering Data
• graphics.py  utilities to draw nodes, elements,
geometric entities etc. in the Graphics window

User can add more modules here.. Or import from


different path
2

Store the material for the geometric


entity as a variable (e.g. myMat) Access Elasticity for myMat
11 © 2011 ANSYS, Inc. December 3, 2012 Access Bulk Modulus from Elasticity data
Demo

• Using the IronPython Console extension


– Application
– Selection Manager
– Data Model
• Geometry data
• Mesh data
• Results
– Using an external module

12 © 2011 ANSYS, Inc. December 3, 2012


Analysis Data Access
• Access number of load steps and step end times
• Access the magnitude of a Pressure load
• Change the Pressure magnitude value
There are a few things directly
accessible from the analysis (e.g.
StepsEndTime)

DataObjects under analysis


provide additional details (e.g.
detailed Analysis Settings, all
Loads, Supports, etc.)

• Access the Coordinate Systems


• Access the Named Selections

13 © 2011 ANSYS, Inc. December 3, 2012


Debugging

14 © 2011 ANSYS, Inc. December 3, 2012


Testing a piece of code – outside of extension

A function to set the property value of an


object under analysis
This file [‘test.py’ ] is at path: ‘D\Temp’
Lets import this file and call ‘myTest’ function

Modules from ‘sys.path’ can be imported


Add ‘D:\Temp’ to ‘sys.path’
Now import ‘test.py’
• Global variables and the functions in the
test module is visible in the function list
window

15 © 2011 ANSYS, Inc. December 3, 2012


Testing a piece of code – outside of extension (2)

Check the values for the Global variables

Change the values of a variable

Call the ‘myTest’ function to change


the X Component for the Force load

Since this module is an external


module, it needs access to ExtAPI

16 © 2011 ANSYS, Inc. December 3, 2012


Testing a piece of code – outside of extension (3)
1

Change the function to take the analysis as an argument


Add a help string to show the information window Reload the changed file

2 3

Define ‘analysis’ and call the ‘myTest’ function

17 © 2011 ANSYS, Inc. December 3, 2012


Debugging an extension
Select the Extension to debug

Use the Command Line Editor to


access all Extension related data
(Global variables, attributes,
functions,…)

2: Call the function

The “example” extension 1: Select

3: The MessageBox opens up


18 © 2011 ANSYS, Inc. December 3, 2012
Debugging an extension (2)
The “ACT_Post” extension
(we will see what this extension does later)
A part of the code we want to debug is shown below

1: Select

2: Access and change


Global variables
19 © 2011 ANSYS, Inc. December 3, 2012
Debugging an extension (3)

GetMaterials returns the list of


materials from the bodies selected
for the ACT result object

3: Access the ACT result object

4: Call the GetMaterials function


and store the returned value
5: import the “materials” module
and then access various material
properties
20 © 2011 ANSYS, Inc. December 3, 2012
Debugging an extension (4)

Lets get the:


• Geometry selected
• Material properties
• Result Type etc.

21 © 2011 ANSYS, Inc. December 3, 2012


Q/A

22 © 2011 ANSYS, Inc. December 3, 2012

Você também pode gostar