Extension Data Storage

ACT provides two mechanisms for storing data in your extension. These mechanisms are based on the callbacks <onload> and <onsave> or on attributes.

  • The callback <onsave> is called each time the target product saves the project. Consequently, this callback allows the creation of dedicated files in which to store data. It also allows data to be stored in the standard Ansys Workbench project.

  • The callback <onload> is called each time the target product loads the project. The process here is similar to the callback <onsave>, but it is now devoted to reading in additional data.

  • Attributes represent an interesting way to store data because they do not require the creation of external files. The remainder of this describes how to use attributes to store data.

Attributes are defined by name and content. The content can be defined by a single value, such as an integer or a double, or it can be defined with more complex data. The content must be serializable. To accomplish this, implement the serialization interface provided by the .NET framework. Types such as integer, double, list, and dictionary are serializable by default.

Attributes are automatically saved and resumed with the project. Attributes can be associated with an ACT extension, load or result, or property.

Attributes are created or edited with the method:

Attributes["attribute_name"] = attribute_value

Content can be retrieved with the method:

attribute_value = Attributes["attribute_name"]

An example follows of an attribute associated with a property:

prop.Attributes["MyData"] = 2
val = prop.Attributes["MyData"]

A similar example follows for an attribute associated with a load:

load.Attributes["MyData"] = 2
val = load.Attributes["MyData"]

A similar example follows for an attribute associated with an extension:

ExtAPI.ExtensionMgr.CurrentExtension.Attributes["MyData"] = 2
v = ExtAPI.ExtensionMgr.CurrentExtension.Attributes["MyData"]

An attribute associated with an extension can be shared between products using the same extension. For example, two Mechanical sessions can share data.

The command to store the attribute in a shared repository is:

ExtAPI.ExtensionMgr.CurrentExtension.SetAttributeValueWithSync("MyData", 2.)

Similarly, the command to retrieve the content stored in a shared repository is:

ExtAPI.ExtensionMgr.CurrentExtension.UpdateAttributes()
v = ExtAPI.ExtensionMgr.CurrentExtension.Attributes["MyData"]