54.8 How are GUI plug-ins executed?

ABAQUS/CAE executes a GUI plug-in by sending a message to the GUI object specified in the registration command for that plug-in. As with the kernel plug-ins, the first time that a GUI plug-in is invoked, ABAQUS/CAE updates the kernel’s sys.path list with that plug-in’s directory. In addition, ABAQUS/CAE sends the plug-in’s kernelInitString to the kernel and updates the GUI’s sys.path list to include that plug-in’s directory. You can use the kernelInitString to initialize the kernel for commands that will be sent by the plug-in’s GUI. The next time that plug-in is invoked, only the message will be sent to the GUI object.

If you need to import files into the GUI that are not located in the same directory as the plug-in, you must augment the sys.path list as shown in the previous example. In addition, if you need to augment the kernel’s sys.path list, you should supply code similar to the following in the plug-in’s kernelInitString, in this example the name of the file containing the plug-in is myForm_plugin.py:

from abaqusGui import AFXForm, getAFXApp

class MyForm(AFXForm):
                
    form code goes here

import os

# Full path (with name) to this file
absPath = os.path.abspath(__file__)  

# Full directory specification
absDir = os.path.dirname(absPath)    

# Full subdirectory specification
subDir = os.path.join(absDir, 'mySubDir') 
initString  = "sys.path.append('%s')\n" % subDir

# myModule is located in subDir
initString += 'import myModule'  
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerGuiMenuButton(buttonText='My Utility', 
    object=MyForm(toolset), kernelInitString=initString )