Altova StyleVision 2023 Enterprise Edition

Macros are scripts that contain JScript (or VBScript, depending on your project's language) statements, such as variable declarations and functions.

 

If your projects should use macros, you can add them as follows: right-click inside the Project pane, select Add Macro from the context menu, and then enter the macro's code in the main form. The code of a macro could be as simple as an alert, for example:

 

alert("Hello, I'm a macro!");

 

More advanced macros can contain variables and local functions. Macros can also contain code that invokes forms from the project. The listing below illustrates an example of a macro that shows a form. It is assumed that this form has already been created in the "Forms" folder and has the name "SampleForm", see also Forms.

 

// display a form
ShowForm( "SampleForm" );

 

In the code listing above, ShowForm is a command built into Scripting Editor. For reference to other similar commands that you can use to work with forms and .NET objects, see the Built-in Commands.

 

Only one macro can be run at a time. After a macro (or event) is executed, the script is closed and global variables lose their values.

 

To run a macro directly in Script Editor, click Run Macro scr_ic_run_macro. To debug a macro using the Visual Studio debugger, click Debug Macro scr_ic_debug_macro.

 

Running macros

To run a macro, you need to first bind the macro to an Authentic event. The macro will run when that Authentic event is triggered. For example, say you wish to run a macro before editing text in Authentic. You must go about this as follows:

 

1.In Design View, select the editable content for which the macro is to be set.

2.In the Properties sidebar (screenshot below), select the Authentic group of properties of the relevant design component.

ScrRunMacroSV

3.Select the Authentic event that will trigger the macro and open the dropdown list of this event's Value combo box. All the macros defined in the Scripting Project of the SPS will be listed. Select the macro you wish to associate with this function.

4.In Authentic View, when any Authentic event that has a macro assigned to it is triggered, then the macro will be executed.

 

See the section, Authentic Scripting >> Macros, for a detailed description of how to use macros in a StyleVision design document.

 

© 2017-2023 Altova GmbH