通常情况下,用户可以在RSG对话框构造器中快速创建下拉框,并自动生成代码,RSG对话框构造器提供了Standard、MDB repository和 ODB repository三类下拉框。
- Standard类型为普通的下拉框
- MDB repository类型为包含了Abaqus模型数据库的下拉框,用户可以在其中选择零件、载荷、分析步、材料等信息
- ODBrepository类型是包含了Abaqus 计算结果数据库的下拉框,用户可以在其中选择零件、实例、单元集、材料等信息
建议尽可能采用Abaqus RSG对话框构造器内嵌的MDB repository和 ODB repository类型的下拉框,当上述两种类型满足不了使用要求时再选用 Standard类型的下拉框。
基本语法
AFXComboBox(p, ncols, nvis, text, tgt=None, sel=0, opts=0,x=0, y=0, w=0, h=0, pl=DEFAULT_PAD, pr=DEFAULT_PAD,pt=DEFAULT_PAD, pb=DEFAULT_PAD)
实例演示
打开上述插件程序,当切换模型、零件或者创建新的集合时,自定义的下拉框中会自动更新,程序的执行效果如图4.30所示。可以参照该实例创建更多类型的自定义下拉框。
代码及过程展示
首先在RSG对话框构造器中分别创建一个MDB repository类型和 Standard标准型下拉框,将插件保存后会自动生成部分代码,所生成的代码中有关MDB repository类型下拉框部分不需要修改,标准型下拉框需要修改。注册文件由RSG对话框构造器自动生成,未进行修改。
保存后自动生成的代码
【 testCombo_plugin.py 】
from abaqusGui import getAFXApp, Activator, AFXMode
from abaqusConstants import ALL
import os
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerGuiMenuButton(
buttonText='Combo',
object=Activator(os.path.join(thisDir, 'testComboDB.py')),
kernelInitString='',
messageId=AFXMode.ID_ACTIVATE,
icon=None,
applicableModules=ALL,
version='N/A',
author='N/A',
description='N/A',
helpUrl='N/A'
)
【 testComboDB.py 】
from rsg.rsgGui import *
from abaqusConstants import INTEGER, FLOAT
execDir = os.path.split(thisDir)[1]
dialogBox = RsgDialog(title='Com', kernelModule='', kernelFunction='', includeApplyBtn=False, includeSeparator=True, okBtnText='OK', applyBtnText='Apply', execDir=execDir)
RsgComboBox(name='ComboBox_1', p='DialogBox', text='Part:', keyword='partName', default='', comboType='MDB', repository='parts', rootText='Model:', rootKeyword='modelName', layout='HORIZONTAL')
RsgComboBox(name='ComboBox_2', p='DialogBox', text='set', keyword='setName', default='', comboType='STANDARD', repository='', rootText='', rootKeyword=None, layout='')
RsgListItem(p='ComboBox_2', text='Item 1')
RsgListItem(p='ComboBox_2', text='Item 2')
RsgListItem(p='ComboBox_2', text='Item 3')
dialogBox.show()
修改自动生成的代码
【testCombo_plugin.py 】
# -* - coding:UTF-8 -*-
from abaqusGui import *
from abaqusConstants import ALL
import osutils, os
###########################################################################
# Class definition
###########################################################################
class testcombobox_plugin(AFXForm):
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def __init__(self, owner):
# Construct the base class.
#
AFXForm.__init__(self, owner)
self.radioButtonGroups = {}
self.cmd = AFXGuiCommand(mode=self, method='',
objectName='', registerQuery=False)
pickedDefault = ''
self.modelNameKw = AFXStringKeyword(self.cmd, 'modelName', True)
self.partNameKw = AFXStringKeyword(self.cmd, 'partName', True)
self.elesetKw = AFXStringKeyword(self.cmd, 'eleset', True)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getFirstDialog(self):
import testcomboboxDB
return testcomboboxDB.testcomboboxDB(self)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def doCustomChecks(self):
# Try to set the appropriate radio button on. If the user did
# not specify any buttons to be on, do nothing.
#
for kw1,kw2,d in self.radioButtonGroups.values():
try:
value = d[ kw1.getValue() ]
kw2.setValue(value)
except:
pass
return True
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def okToCancel(self):
# No need to close the dialog when a file operation (such
# as New or Open) or model change is executed.
#
return False
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Register the plug-in
#
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerGuiMenuButton(
buttonText='test combobox',
object=testcombobox_plugin(toolset),
messageId=AFXMode.ID_ACTIVATE,
icon=None,
kernelInitString='',
applicableModules=ALL,
version='N/A',
author='N/A',
description='N/A',
helpUrl='N/A'
)
【testComboDB.py】
# -* - coding:UTF-8 -*-
from abaqusConstants import *
from abaqusGui import *
from kernelAccess import mdb, session
import os
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)
class testcomboboxDB(AFXDataDialog):
def __init__(self, form):
AFXDataDialog.__init__(self, form, '测试下拉框',
self.OK|self.CANCEL, DIALOG_ACTIONS_SEPARATOR)
okBtn = self.getActionButton(self.ID_CLICKED_OK)
okBtn.setText('OK')
frame = FXHorizontalFrame(self, 0, 0,0,0,0, 0,0,0,0)
#系统自动创建MDB repository类型下拉框,父级对象为model
self.RootComboBox_1 = AFXComboBox(p=frame, ncols=0, nvis=1, text='Model:', tgt=form.modelNameKw, sel=0)
self.RootComboBox_1.setMaxVisible(10)
names = mdb.models.keys()
names.sort()
for name in names:
self.RootComboBox_1.appendItem(name)
if not form.modelNameKw.getValue() in names:
form.modelNameKw.setValue( names[0] )
msgCount = 7
form.modelNameKw.setTarget(self)
form.modelNameKw.setSelector(AFXDataDialog.ID_LAST+msgCount)
msgHandler = str(self.__class__).split('.')[-1] + '.onComboBox_1PartsChanged'
exec('FXMAPFUNC(self, SEL_COMMAND, AFXDataDialog.ID_LAST+%d, %s)'
% (msgCount, msgHandler) )
# 系统自动创建MDB repository类型下拉框,子对象为part
self.ComboBox_1 = AFXComboBox(p=frame, ncols=0, nvis=1, text='Part:',
tgt=form.partNameKw, sel=0)
self.ComboBox_1.setMaxVisible(10)
self.form = form
#系统自动生成的标准型下拉框,对象为空
self.ComboBox_2 = AFXComboBox(p=self, ncols=0, nvis=1, text='set:',
tgt=form.elesetKw, sel=0)
self.ComboBox_2.setMaxVisible(10)
#新增代码,创建单元集合下拉框
msgCount4 = 45
form.partNameKw.setTarget(self) #设置目标
form.partNameKw.setSelector(AFXDataDialog.ID_LAST+msgCount4) #设置消息ID
msgHandler4 = str(self.__class__).split('.')[-1] + '.onComboBox_2elesetChanged'
exec('FXMAPFUNC(self, SEL_COMMAND, AFXDataDialog.ID_LAST+%d, %s)'
% (msgCount4, msgHandler4) )
#消息映射
def show(self):
AFXDataDialog.show(self)
self.currentModelName = getCurrentContext()['modelName']
self.form.modelNameKw.setValue(self.currentModelName)
mdb.models[self.currentModelName].parts.registerQuery(self.updateComboBox_1Parts)
mdb.models[self.currentModelName].parts.registerQuery(self.updateComboBox_2eleset)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def hide(self):
AFXDataDialog.hide(self)
mdb.models[self.currentModelName].parts.unregisterQuery(self.updateComboBox_1Parts)
mdb.models[self.currentModelName].parts.unregisterQuery(self.updateComboBox_2eleset)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def onComboBox_1PartsChanged(self, sender, sel, ptr):
self.updateComboBox_1Parts()
return 1
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def updateComboBox_1Parts(self):
modelName = self.form.modelNameKw.getValue()
# Update the names in the Parts combo
#
self.ComboBox_1.clearItems()
names = mdb.models[modelName].parts.keys()
names.sort()
for name in names:
self.ComboBox_1.appendItem(name)
if names:
if not self.form.partNameKw.getValue() in names:
self.form.partNameKw.setValue( names[0] )
else:
self.form.partNameKw.setValue('')
self.resize( self.getDefaultWidth(), self.getDefaultHeight() )
#新增sets更新
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def onComboBox_2elesetChanged(self, sender, sel, ptr): #自定义下拉框函数
self.updateComboBox_2eleset()
return 1
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def updateComboBox_2eleset(self): #更新下拉框内容
modelName = self.form.modelNameKw.getValue()
partName = self.form.partNameKw.getValue()
# Update the names in the Parts combo
if partName!='': #判断是否有part,避免在无零件时报错
self.ComboBox_2.clearItems()
names = mdb.models[modelName].parts[partName].sets.keys()#指向零件的所有集合
names.sort()
for name in names:
self.ComboBox_2.appendItem(name) #逐项添加到下拉框中
if names:
if not self.form.elesetKw.getValue() in names:
self.form.elesetKw.setValue( names[0] )
else:
self.form.elesetKw.setValue('')
self.resize( self.getDefaultWidth(), self.getDefaultHeight() )