An example of a Python module and a function

A kernel plug-in associates a Python module and a function with a menu item or a toolbox icon. For example, the kernel plug-in shown below is a simple function defined in the file myUtils.py that prints the current viewport to a PNG file. The file myUtils.py is a Python module.

def printCurrentVp():

    from abaqus import session, getInputs
    from abaqusConstants import PNG
    name = getInputs( (('File name:', ''),), 
        'Print current viewport to PNG file')[0]
    vp = session.viewports[session.currentViewportName]
    session.printToFile(
        fileName=name, format=PNG, canvasObjects=(vp, ))

The first line of the example (def printCurrentVp():) is a function definition that contains the indented commands. A plug-in requires a function definition. As a result, if you want to create a kernel plug-in by extracting the commands written to the abaqus.rpy replay file, you must first wrap the commands in a function definition. For more details on writing kernel scripts and creating function definitions, refer to the Abaqus Scripting User's Guide and to the Abaqus Scripting Reference Guide.

After you have written a kernel plug-in, you can execute it from the Plug-ins menu in the Abaqus/CAE main menu bar after you register it with the Plug-in toolset. For more information, see How do I make a plug-in available from Abaqus/CAE?.