Two mechanisms are available to store data in your extension. These mechanisms are
based on the callbacks <onload> and
<onsave> or on attributes. These mechanisms are
available for any ANSYS product that supports ACT.
The callback <onsave> is called each time the target
product saves the project. Consequently, this callback allows the creation of
dedicated files to store data, in addition to 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.
Attributes are defined by name and content. The content can be simply defined by a
single value, such as an integer or a double, or with more complex data. The content
must be serializable. To accomplish this, implement the serialization interface
provided by .Net. 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 extension, an ACT load or result, and a property.
Attributes are created or edited with the method:
Attributes["attribute_name"] = attribute_valueContent 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"]