Creating a macro to calculate a MetaAttribute
A calculated MetaAttribute is a virtual MetaAttribute that computes its value from a calculation macro.
The calculation macro:
is implemented by a function
E.g.: GetAttributeValue(ByVal Object, ByVal AttributeID, ByRef Value)
may include:
constant values
values retrieved from other MetaAttributes
values retrieved from other calculated MetaAttributes
Calculated MetaAttribute values are not stored, but constantly recomputed, even if the value has not changed.
You can add MetaTriggers to calculated MetaAttributes so as to store their values in the repositories.
Creating the calculation macro
To calculate a MetaAttribute using a macro:
1. Open the explorer on the new MetaAttribute (or new parameter).
2. Right-click the MetaAttribute (or parameter) and select New > Macro
The macro creation wizard appears.
3. Select Create a (VB)Script Macro.
4. Click Next.
5. (Optional) Modify the default Name ("AttributeName".Macro) of your macro.
*A macro is an object containing a VB Script code sequence interpreted at execution.
6. Click Finish.
7. Configure the calculation macro.
Configuring the calculation macro
To configure the calculation macro:
1. Edit the "AttributeName".Macro macro and note that in particular the VB Script contains the following functions:
*If they are not present, standard implementation is selected.
GetAttributeValue(ByVal Object, ByVal AttributeID, ByRef Value)
Defines attribute access mode. The parameters are:
Object: corresponds to the object of which attribute value is requested.
AttributeID: absolute identifier of the attribute (or taggedValue).
Value: the function returns the attribute value for this object.
SetAttributeValue(ByVal Object, ByVal AttributeID, ByVal Value)
Defines attribute save mode. The parameters are:
Object: corresponds to the object of which the attribute value must be updated.
AttributeID: absolute identifier of the attribute (or taggedValue).
Value: the function saves the attribute value for this object.
*The attribute nature (_AtNature) should be Virtual.
For both of these functions, attribute change mode is a character string.
Conversion must be carried out to change text format to the internal format of the attribute.
Example:
Sub GetAttributeValue (ByVal object, ByVal AttID, Value)
' internal value reading in integer format.
numValue = CInt(objet.GetProp(AttID, "Physical"))
if numValue < 20 then
Value = "Young"
elseif numValue < 35 then
Value = "Youthful"
elseif numValue < 55 then
Value = "Mature"
else
Value = "Elderly"
end if
End Sub
You can directly implement read-only and read/write access in the attribute format (without passing via standard conversion).
In this case, you must implement the following two functions, of which prototypes are similar to those above:
GetExtendedAttributeValue(ByVal Format as LONG, ByVal Object, ByVal AttributeID, ByRef Value)
SetExtendedAttributeValue(ByVal Format as LONG, ByVal Object, ByVal AttributeID, ByVal Value)
The difference is in the additional parameter: Format. The possible values are:
0 internal: value in internal format (binary, integer,...)
1 external: value in external format, but before display processing (certain objects have external form that is textual with the addition of index identifiers, as for class attributes or association roles).
3 Display: value in external format used in Web sites or Word documents (expurgated when identifiers in external format occur).
If one of the two extended functions is implemented, call by GetProp with "Physical" format on the same attribute is prohibited since it would lead to an infinite recursion.