HOPEX Power Studio > Customizing the Metamodel > Managing the Metamodel > MetaAttributes > Using VB Scripts to Calculate Characteristics
Using VB Scripts to Calculate Characteristics
You can:
define new attributes or parameters for a HOPEX object.
determine value read and save modes for this parameter using HOPEX macros.
To calculate an attribute by creating a macro:
1. Open the explorer on the new attribute or new parameter.
2. Right-click the attribute (or parameter) and select New > Macro
The macro creation wizard appears.
3. Select Create Macro (VB)Script.
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.
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)
Define 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)
Define 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.