Abaqus/CAE中已经集成了较为丰富的功能组件,在编写GUI程序时,没有必要去做一些重复性的开发,在需要使用Abaqus/CAE内嵌的功能组件时,可以在自己的GUI程序中直接调用。例如,直接调用创建零件、创建材料或者划分网格的功能等。
Abaqus/CAE内嵌功能的实现需要借助mainWindow对象的getTargetFromFunction和getSelectorFromFunction两个函数命令,两个函数命令的作用是分别获取Abaqus/CAE内嵌功能的目标和选择器。
实例展示
直接点击按钮,调用Abaqus/CAE内部的东西:
代码展示
图形界面文件【testcheckbuttonDB.py】
# -* - coding:UTF-8 -*- from abaqusConstants import *from abaqusGui import *from kernelAccess import mdb, sessionimport osthisPath = os.path.abspath(__file__)thisDir = os.path.dirname(thisPath)class testcheckbuttonDB(AFXDataDialog): def __init__(self, form): AFXDataDialog.__init__(self, form, 'Test Check Button', self.OK|self.CANCEL, DIALOG_ACTIONS_SEPARATOR) okBtn = self.getActionButton(self.ID_CLICKED_OK) okBtn.setText('OK') GroupBox_1 = FXGroupBox(p=self, text='Element type', opts=FRAME_GROOVE) FXCheckButton(p=GroupBox_1, text='SOLID\t选择实体单元', tgt=form.ele_solidKw, sel=0) FXCheckButton(p=GroupBox_1, text='SEHLL\t选择壳单元', tgt=form.ele_shellKw, sel=0) mainWindow = getAFXApp().getAFXMainWindow() #创建材料,指定目标和选择器 target = mainWindow.getTargetFromFunction('Material->Create') selector = mainWindow.getSelectorFromFunction('Material->Create') FXButton(GroupBox_1, '创建材料', tgt=target, sel=selector ) #创建属性,指定目标和选择器 target = mainWindow.getTargetFromFunction('Section->Create') selector = mainWindow.getSelectorFromFunction('Section->Create') FXButton(GroupBox_1, '创建属性', tgt=target, sel=selector )
注册文件【testcheckbutton_plugin.py】
from abaqusGui import *from abaqusConstants import ALLimport osutils, os ############################################################################ Class definition########################################################################### class testcheckbutton_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.ele_solidKw = AFXBoolKeyword(self.cmd, 'ele_solid', AFXBoolKeyword.TRUE_FALSE, True, True) self.ele_shellKw = AFXBoolKeyword(self.cmd, 'ele_shell', AFXBoolKeyword.TRUE_FALSE, True, False) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def getFirstDialog(self): import testcheckbuttonDB return testcheckbuttonDB.testcheckbuttonDB(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 checkbutton', object=testcheckbutton_plugin(toolset), messageId=AFXMode.ID_ACTIVATE, icon=None, kernelInitString='', applicableModules=ALL, version='N/A', author='N/A', description='N/A', helpUrl='N/A')
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删