6.7 Accessing kernel data from the GUI

You can use the abaqusGui module or the kernelAccess module to access the kernel mdb and session objects from the GUI in Abaqus/CAE. Each module has advantages and disadvantages for programming in the GUI. You access the objects from each module in the same way:

from abaqusGui import mdb, session
or
from kernelAccess import mdb, session
In each case the imported objects are proxies for the actual objects in the kernel.

You can query the abaqusGui module mdb and session proxy objects for attributes of objects, but they cannot be used for arbitrary method calls (repository methods such as keys(), values(), and items() are allowed). The abaqusGui proxy objects are regularly updated from the kernel, and accessing them is an in-process function call (fast). However, in some cases the proxy objects can get out of date. For example, when a script is running the proxy objects are not updated until it ends.

You can use the kernelAccess module mdb and session proxy objects to execute any Abaqus Scripting Interface kernel command. In addition to querying attributes of the kernel objects, you can call their methods and obtain any return values as if you were executing the code in the kernel. The kernelAccess proxy objects are always up-to-date because accessing them calls the kernel object synchronously, creating inter-process communication (IPC) traffic. This immediate interaction with the kernel creates a performance disadvantage when you use the kernelAccess proxy objects instead of the abaqusGui module proxy objects. For example, call the getVolume method of the Part object:

from kernelAccess import mdb, session
partNames = mdb.models['Model-1'].parts.keys()
v = mdb.models['Model-1'].parts['Part-1'].getVolume() 

This procedure involves GUI-kernel communication via the IPC mechanism, so it is not recommended for use where performance is a concern. In other words, you should only use this procedure for accessing data or calling methods that do not take a “long time” to execute. If performance does become a problem, you can access the mdb and session objects from the abaqusGui module instead of the kernelAccess module.

Although you can import the kernelAccess module in a script that is executed before the application startup script has completed, you cannot query the mdb and session objects until the application startup script has completed. In other words, you can import the kernelAccess module in your scripts in code that is executed during the initial construction of the GUI; however, you should not attempt to access either the mdb or session object until it is needed because of some user interaction in the GUI. For more information, see Startup script, Section 11.2