Using Macros
HOPEX enables addition of macros in descriptors. You can therefore communicate with Word via VB Script and use APIs to access the repository.
Adding a macro
To add a macro:
1. Right-click a group and select New > Macro.
The Create Macro dialog box opens.
2. Enter the macro name and click OK.
A VB Script tab appears.
 
Macro principle
The macro is called by the "Generate" method from the following code:
Explicit Option
Sub Generate(oObject, oContext, sUserData, sResult)
End Sub
oObject: the current object in the descriptor
oContext: macro generation context which supports the following properties: 
StyleSheet: report (MS Word) style sheet address
Current: current object on which macro executes
Parent: parent object
Root: descriptor entry point object
GenerationMode: rtf generation mode
IsConfidential: returns a boolean
sResult: string in which RTF generated by the macro is written
Macro availability
A macro can relate to one, several or all the MetaClasses.
The MetaClass to which the macro relates should appear in the Characteristics tab of the macro properties.
*If no MetaClass is indicated in the macro properties, this means that the macro relates to all the MetaClasses.
Macros example
Two macros are provided as standard. You can configure these by first duplicating them.
External Reference Content: manages insertion of content of external references in the report (MS Word). Various formats are proposed: 
.txt, .ini, .log, .xml: files are read in text format.
.rtf, .wri, .doc, .xls, .bmp, .gif, .jpg, .png, .tif: files are read/converted to .rtf or image format.
*In HOPEX Web Front-End, you cannot reproduce the content of external references.
Business process hypothesis achievement matrix: enables creation of a matrix type table.
M acro structure
The following code gives the structure enabling opening of a Word session in VB, creating an empty report (MS Word) and saving its content in RTF. Word APIs then enable writing of text, tables, etc.
Sub RTFGenerate(mgoContext, strResultRtf)
Dim oWordApplication
Set oWordApplication = CreateObject("Word.Application")
Dim oWordDocument
Set oWordDocument = oWordApplication.Documents.Add
' Enter your code here
mgoContext.GetRoot.SaveWordDocumentAsRTF oWordDocument, strResultRtf
oWordApplication.Quit
End Sub
SaveWordDocumentAsRtf is an _Operator that enables Word document content backup in RTF.
Taking inheritance into account in macros
Regarding inheritance, you can:
explicitly request by code the inclusion of inherited objects
specify a behavior for the macro by fixing its execution context
To specify behavior at macro level:
*In the macro properties, Characteristics tab, in the _ExecutionOptions field, specify the execution options:
not specified: the macro does not take inheritance into account
"Variation Inheritance": the macro takes inheritance into account
"Inherits caller options": the macro behaves like the caller macro
 
When you choose to take inheritance into account, the getCollections and getSelections functions of the macro include inherited objects.
Behavior regarding inheritance is the same for the following two expressions:
myApplication.getCollection("Service")
myApplication.getCollection("Service", " @inherited ")
*In macros, even if the Variation Inheritance execution option is selected, the "Inheriting" parameter (which shows objects that are inheriting) is deactivated. To take this parameter into account, it must be indicated specifically in the getCollection (see API documentation).