54.6.3 An example of adding a kernel plug-in to the Plug-ins menu

You use the registerKernelMenuButton() command to make a kernel plug-in available from the Plug-ins menu. The following example illustrates how you associate the simple function described in An example of a Python module and a function, Section 54.4, with a Print Current Viewport item in the Plug-ins menu. (The function prints the current viewport to a PNG file.) The registration command references the kernel function printCurrentVP that is located in the Python module myUtils:

from abaqusGui import getAFXApp
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerKernelMenuButton(
    buttonText='Print Current Viewport',
    moduleName='myUtils', functionName='printCurrentVp()' )

The first two lines in the example provide access to the commands in the Plug-in toolset. The next line inserts a Print Current Viewport menu item under the Plug-ins menu in the main menu bar. When the user clicks Print Current Viewport, ABAQUS/CAE issues the following command to the kernel:

myUtils.printCurrentVp()

The buttonText argument accepts a pipe-separated ( | ) list of words. The pipe separates submenu names from the menu button name. This allows you to group several plug-ins under one menu. For example, if you have defined more functions in myUtils.py, you can use the following version of myUtils_plugin.py to register them under a cascading menu:

from abaqusGui import getAFXApp
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerKernelMenuButton(
    buttonText='My Utils|Print Current Viewport',
    moduleName='myUtils', functionName='printCurrentVp()' )

toolset.registerKernelMenuButton(
    buttonText='My Utils|Print Sections',
    moduleName='myUtils', functionName='printSections()' )

toolset.registerKernelMenuButton(
    buttonText='My Utils|Print Materials',
    moduleName='myUtils', functionName='printMaterials()' )
The previous example results in the menu structure shown in Figure 54–3:

Figure 54–3 The effect of registering plug-ins under a cascading menu.