© Dassault Systèmes, 2008
高级专题
第4讲
Introduction to Python and Scripting in Abaqus
L4.2
© Dassault Systèmes, 2008
概要
• 探究用户数据
• Abaqus 的体系结构
• 监控分析作业
• 定制数据
• 插件程序
• 调试脚本
• Abaqus 中的Python开发环境 (PDE)
• 基于对象编程
• Python 中的类
• 实例
• 习题
© Dassault Systèmes, 2008
探究用户数据
Introduction to Python and Scripting in Abaqus
L4.4
© Dassault Systèmes, 2008
探究用户数据
• 查询对象属性
查询专门属性。例如:
>>> odb = openOdb('cantilever.odb')
>>> odb.__members__
['analysisTitle', 'closed', 'description', 'diagnosticData', 'isReadOnly',
'jobData', 'name', 'parts', 'path', 'rootAssembly', 'sectionCategories',
'sectorDefinition', 'steps', 'userData']
>>> odb.__methods__
['Part', 'SectionCategory', 'Step', 'UserXYData', 'close', 'getFrame',
'save', 'update']
使用 print 语句。 Abaqus 的对象状态可以用 print 语句来打印,例如:
>>> print odb
({'analysisTitle': Cantilever beam model', 'closed': FALSE, 'description':
'DDB object', 'diagnosticData': 'OdbDiagnosticData object', 'isReadOnly':
FALSE, 'jobData': 'JobData object', 'name': 'cantilever.odb', 'parts':
'Repository object', 'path': 'd:\temp\cantilever.odb', 'rootAssembly':
'OdbAssembly object', 'sectionCategories': 'Repository object',
'sectorDefinition': None, 'steps': 'Repository object', 'userData':
'UserData object'})
Introduction to Python and Scripting in Abaqus
L4.5
© Dassault Systèmes, 2008
探究用户数据
• prettyPrint 函数
>>> from textRepr import *
>>> prettyPrint(odb)
({'analysisTitle': 'Cantilever beam model',
'closed': FALSE,
'description': 'DDB object',
'diagnosticData': 'OdbDiagnosticData object',
'isReadOnly': FALSE,
'jobData': 'JobData object',
'name': 'cantilever.odb',
'parts': 'Repository object',
'path': 'd:\temp\cantilever.odb ',
'rootAssembly': 'OdbAssembly object',
'sectionCategories': 'Repository object',
'sectorDefinition': None,
'steps': 'Repository object',
'userData': 'UserData object'})
• 缺省情况下,只打印 1 层,第 2 个变量的含义是深度(prettyPrint.py).
>>> prettyPrint(odb, maxRecursionDepth=2)
• 设置默认深度 – 影响 textRepr 函数和打印的 Abaqus 对象.
>>> session.textReprOptions.setValues(maxRecursionDepth=3)
Introduction to Python and Scripting in Abaqus
L4.6
© Dassault Systèmes, 2008
探究用户数据
• 更多 textRepr 函数
• textRepr 模块中的函数:
getIndentedRepr, getPaths, getTypes, prettyPrint,
prettyPrintToFile, prettyPrintToFileName, prettyPrintToTerm,
printPaths, printPathsToFile, printPathsToFileName,
printPathsToTerm, printTypes
• 函数名:
prettyPrint(object <, maxRecursionDepth, maxElementsInSequence,
significantDigits, _internalMembersMethods>)
printPaths(object <, maxRecursionDepth, maxElementsInSequence,
pathRoot, _internalMembersMethods>)
printTypes(object <, maxRecursionDepth, maxElementsInSequence,
pathRoot, _internalMembersMethods>)
printPathsToFileName(fileName, object <, maxRecursionDepth,
maxElementsInSequence, pathRoot, _internalMembersMethods >)
• 注意:可选参数显示在 <...>中
• 使用 __doc__来检查参数
Introduction to Python and Scripting in Abaqus
L4.7
© Dassault Systèmes, 2008
探究用户数据
• 打印路径
>>> from odbAccess import *
>>> from textRepr import *
>>> odb = openOdb('cantilever.odb')
>>> printPaths(odb, pathRoot='odb')
odb.analysisTitle
odb.closed
odb.description
odb.diagnosticData
odb.isReadOnly
odb.jobData
odb.name
odb.parts
odb.path
odb.rootAssembly
odb.sectionCategories
odb.sectorDefinition
odb.steps
odb.userData
• 通过增加深度来显示更多数据
>>> printPaths(odb, 2, pathRoot='odb')
. . .或选择组分之一
>>> printPaths(odb.steps['Step-1'], 2, pathRoot='step')
Introduction to Python and Scripting in Abaqus
L4.8
© Dassault Systèmes, 2008
探究用户数据
• getPaths
• 返回的字符串可以进一步被处理
>>> x = getPaths(odb.steps['Step-1'].frames[87].fieldOutputs,
pathRoot='fieldOutputs')
>>> print x
fieldOutputs['S']
fieldOutputs['PE']
fieldOutputs['RF']
fieldOutputs['PEEQ']
fieldOutputs['LE']
fieldOutputs['PEMAG']
fieldOutputs['AC YIELD']
fieldOutputs['CF']
fieldOutputs['U']
>>> y = x.splitlines()
>>> print y[3]
fieldOutputs['PEEQ']
Introduction to Python and Scripting in Abaqus
L4.9
© Dassault Systèmes, 2008
探究用户数据
• printTypes
• 返回每个组分(member)的类型
>>> stress = odb.steps['Step-1'].frames[87].fieldOutputs['S']
>>> printTypes(stress, pathRoot='stress')
tuple stress.componentLabels
string stress.description
FieldLocationArray stress.locations
string stress.name
SymbolicConstant stress.type
tuple stress.validInvariants
FieldValueArray stress.values
• 利用 getPaths() 和 eval(path) 打印每个组分值
for path in getPaths(obj).splitlines():
print '%-20s %s' % (eval(path), path)
© Dassault Systèmes, 2008
Abaqus 的体系结构
评论1