Creating and Editing a Macro

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Programmers' Reference > Scripting Editor > Macros >

Creating and Editing a Macro

The following operations enable you to create a new macro and edit an existing macro.

 

 

Creating a new macro

Right-click the Macro folder in the Scripting Projects tree and select Add Macro from the context menu. (The Add Macro command can also be selected from the context menu of any item in the Scripting Projects tree.) Alternatively, click the New Macro icon in the toolbar of the Scripting Projects tree.

 

The newly created (and empty) macro document is displayed in the Main Window, and the name of the macro is displayed in the title bar of the Scripting Editor (screenshot below).

 

ScrMacroTree

 

 

Naming or renaming a macro

To name or rename a macro, click the macro name in the Scripting Project tree and press the F2 function key, or right click the name and select Rename from the context menu.

 

 

Opening a macro

To open a macro, right-click the macro in the Macros folder of the Scripting Project tree (see screenshot above), and select the Open command. The macro is displayed in the Main Window and its name is displayed in the title bar of the Scripting Editor (screenshot below). Alternatively, double-clicking a macro in the Scripting Project tree opens it in the Main Window.

 

ScrMacroTitleBarAuth

 

 

Editing the macro

To edit a macro, enter or edit its code in the Main Window. For example, the following code creates the Form named Form1 in memory and then shows it. Form1 must already have been created (using the Scripting Editor's Form creation) before this macros is run.

 

objForm = CreateForm( 'Form1' );

objForm.ShowDialog();

 

The following macro uses the RemoveAllNamespaces function to remove all namespaces in the active XML document.

 

if(Application.ActiveDocument != null)        {

         RemoveAllNamespaces(Application.ActiveDocument.RootElement);

         Application.ActiveDocument.UpdateViews();

}

 

The RemoveAllNamespaces function itself will have to be defined in the Global Declarations script. After the RemoveAllNamespaces function has been defined, the  macro is complete and can be run.

 

Note:Macros do not support parameters or return values.

 

 

Setting a macro as an Auto-Macro

When a macro is set as an Auto-Macro it can be run automatically when: (i) Authentic Desktop is started, or (ii) an Altova Authentic Desktop project is loaded in Authentic Desktop. To specify whether Auto-Macros should be run in each of these two events, check the Run Auto-Macros option in the Automatic Script Processing pane of the relevant dialogs:

 

When Authentic Desktop is started: the Scripting tab of the Authentic Desktop Options dialog (Tools | Options menu command).
When an Authentic Desktop project is loaded into Authentic Desktop: the Scripting dialog (screenshot below, Project | Scripting Settings menu command).

 

ScrMacrosAutoRunSPPAuth

 

To set a macro as an Auto-Macro, right-click the macro in the Scripting Project tree and select the command Set as Auto-Macro. This is a toggle command; so to remove the Auto-Macro setting of a macro, select the command again.

 


© 2019 Altova GmbH