How are kernel plug-ins executed?

Abaqus executes a kernel plug-in by issuing a command to the kernel of the form moduleName.functionName. The module name and the function name are the names that you supplied in the registration command for that plug-in.

When Abaqus/CAE starts and imports a plug-in, the directory in which the plug-in is located is stored by Abaqus/CAE. The first time that the plug-in is invoked, Abaqus/CAE updates the kernel’s sys.path list with that plug-in’s directory. The next time that plug-in is invoked, Abaqus/CAE issues the commands inside the plug-in but does not update the sys.path.

For example, consider the myUtils_plugin.py and myUtils.py files described in previous sections. Assume that you stored these two files in a subdirectory called myPlugins in the abaqus_plugins directory in your home directory. The first time that you click Print Current Viewport in the Plug-ins menu, Abaqus/CAE sends the following commands to the kernel:

import sys
sys.path.append('path to your home dir/abaqus_plugins/myPlugins')
import myUtils
myUtils.printCurrentViewport()

The next time you click Print Current Viewport in the Plug-ins menu, Abaqus/CAE sends only the following command to the kernel:

myUtils.printCurrentViewport()

Since Abaqus/CAE updates the sys.path list, your plug-in code does not need to perform this task to import modules that it needs. This assumes that those modules are located in the same directory as the plug-in. If you have to import modules that are not located in the same directory, you must augment the sys.path list. If you need to augment the sys.path list, you should use functions that determine the file locations automatically, rather than hard-coding the path to the plug-ins in your file. This makes it easy to move plug-ins to different locations without having to modify their code. The following example of myUtils.py illustrates an example of augmenting the sys.path list:

import sys, 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') 
sys.path.append(subDir)

# myModule is located in subDir
import myModule  

rest of module code