6.8 Receiving notification of kernel data changes

This section describes how the GUI can be notified when kernel objects and custom kernel objects are modified outside the GUI process. The following topics are covered:


6.8.1 Automatically registering a query on kernel objects

Queries provide a mechanism that allows the GUI process to be notified when data in the kernel change. Keeping the GUI and commands up-to-date, Section 6.5.3, describes how you use the registerQuery argument of the AFXGuiCommand constructor. The registerQuery argument is a Boolean flag that specifies whether to register a query automatically on the object being edited by the specified kernel command. If the kernel object specified in the AFXGuiCommand constructor changes, the infrastructure updates the keywords in the GUI with the latest values. As a result, you do not need to register a query explicitly. By default, registerQuery=FALSE, and the query is not automatically registered.

For example,

cmd = AFXGuiCommand(mode,'setValues',mdb.models[%s].parts[%s], TRUE)
In this example, if the user changes the current part, the path to the setValues method is updated to reflect the new current part. As a result, when the user clicks OK to commit a customized dialog box, the mode issues a setValues command that modifies the current part.


6.8.2 Manually registering a query on kernel objects

For objects not directly related to a command, such as a repository, you may wish to register a query yourself. You can register a query on an ABAQUS/CAE object using the registerQuery method. This method takes a callback function as an argument. When the object upon which the query is registered changes, the infrastructure automatically calls the function supplied in the registerQuery method. For example,

from abaqusGui import *
from kernelAccess import mdb

def onPartsChanged():
    print 'The parts repository changed.'
    keys = mdb.models['Model-1'].parts.keys()
    print 'The new keys are:', keys

mdb.models['Model-1'].parts.registerQuery(onPartsChanged)
In the previous example, if a part is created, deleted, renamed, or edited, the onPartsChanged method will be called.

The registerQuery method takes an optional second argument that determines whether or not the callback is called when the query is first registered. By default, this argument is TRUE, and the callback will be called when the query is first registered. If you specify FALSE as the second argument, the query callback is not called when the query is first registered.

Since registered queries create “traffic” between the kernel and GUI processes, you should unregister queries when you do not need them. To unregister a query, use the unregisterQuery method and pass the same arguments that you used in the registerQuery method. In most cases, you register queries within the show method that you write for your dialog box that needs the queries. Similarly, you unregister queries within the hide method that you write for your dialog box. If you do not unregister a query and the query fires when the dialog box is not posted, the application may abort if the callback tries to modify a widget in the dialog box.

If the user creates, deletes, renames, or edits a part in the following example, the application will call the onPartsChanged method and update the dialog box:

class MyDialog(AFXDataDialog):

    ...

    def onPartsChanged(self):

        # Code to update the part list 
        # in the dialog box

    def show(self):

        from kernelAccess import mdb
        mdb.models['Model-1'].parts.registerQuery(
            self.onPartsChanged)
        AFXDataDialog.show(self)

    def hide(self):

        from kernelAccess import mdb
        mdb.models['Model-1'].parts.unregisterQuery(
            self.onPartsChanged)
        AFXDataDialog.hide(self)


6.8.3 Recognizing when custom kernel data change

To receive notification in the GUI of changes made to custom kernel objects, those kernel objects must make use of special classes provided by the customKernel module. The customKernel module provides the following special classes, all of which are capable of notifying the GUI when the contents of the class changes:

For more information on the customKernel module, see Extending the ABAQUS Scripting Interface, Section 5.6 of the ABAQUS Scripting User's Manual.