Automating Repetitive Tasks Using Macros

This section provides background information about automating repetitive tasks using macros.

If you perform a task repeatedly, you can take advantage of a macro to automate it. A macro is a series of functions, written in a scripting language, that you group in a single command to perform the requested task automatically.

You can create macros by editing a file (written in a scripting language) to insert the functions you wish. You can also modify an existing macro to best fit your needs. Once the macro is created, you can run it by selecting Tools > Macro > Macros..., selecting the macro, and clicking Run. Macros are stored in the PLM database.

Note: you can use a setting to administer macro libraries opened by default using the Tools>Macro>Macros... tab. You administer this aspect using the Tools>Options>General>Macros>Default Macro Libraries tab. Macro libraries opened by a user and not belonging to administered settings are stored as preferences.

Script Development Tools and Languages

This section describes script development tools and languages.

You can use the following scripting tools and languages:

CATScript
These macros are written in Basic Script, stored in PLM directories, and can be run on both Windows and AIX.
Visual Basic Script (VB Script)
At minimum level 5.0 which is part of the operating system. Although CATScript macros written in previous releases continue to work, we recommend that you prefer VB Script to CATScript.
Visual Basic for Applications (VBA) Version 6.2
This product is installed with Version 6: macros written using VBA can only be run on Windows. Among the advantages of using VBA, note:
  • that IntelliSense facilitates editing
  • that VBA contains a debugger
  • Graphic user interface development (this is not possible with CATScript or VB Script macros).
Microsoft VSTA
Scripting technology, which stands for Visual Studio Tools for Applications. This technology aims to replace VBA over time. It is empowered by the unified .NET framework and based upon the familiar Visual Studio's IDE. VSTA endeavors to provide a smooth transition from legacy Visual Basic language to the enhanced Visual Basic .NET (VB.NET) language. VSTA also adds support for C Sharp (C#), which offers users a more powerful and structured advanced programming language. V6 provides users with the benefits of the new Microsoft VSTA v1.0 scripting technology (including the .NET framework v3.0, debugging facilities, rich IDE, 64-bit native support) while leveraging their existing investments by continuing to support VBA v6.2 in V6.
VSTA is available side-by-side with VBA and VBS. This offers a new functionality for the end-user who can still edit and run VBA and VBS macros, while also creating new VSTA macro libraries and edit or run macros in the same fashion.
For that purpose, the Macros GUI is similar to that of V5 while some VSTA-specific panels and controls have been added.

A Few Definitions

This section contains important definitions.

Macro
Program written in a simple script language to allow customization of V6 and automation of repetitive user tasks. So far, a macro program was most often written in VBScript (for .catvbs and .CATScript files) or in VB (for .catvba VBA projects).
Macro library
Container for macro programs, stored in the ENOVIA V6 database as a PLM representation. From an external standpoint, macro library, macro container and macro project are synonyms which stand for the same concept.
VSTA add-in
The terminology used by Microsoft, corresponding to DS' notion of VSTA macro in V6. A macro, as such, adds functionality in the host application (in CATIA, for example).
IDE
Integrated development environment, also known as DTE: design-time environment.

How Macros Are Stored

This section describes how macros are stored.

Macros are stored as PLM objects.

In editing mode, the PLM object is seen as modifiable. All dialog commands that modify it are enabled. This mode doesn't imply that the modifications done on the object will be saved successfully. An object can be modifiable and not savable in database.

In read only mode, the PLM object is seen as non modifiable. All dialog commands that can modify it are disabled. The end user will have the possibility to manage the editability of macros. End users are informed when they risk to loose their modifications on a macro library because this library is modified or locked by someone else.

Macro Editability

The ability to edit macros is the same as for all other PLM entities: you can either edit entities or access them in read only mode.

If you create a new library of macros, this new PLM entity is in editing mode.

If you open an existing library, the mode depends on a PLM access setting common to all PLM entities.

To set the default behavior, select Tools>Options... then the PLM Access category, then the Open Options tab. Checking the option Display a warning if read-only data are edited will start your macro session in read only mode; otherwise, your macro session will start in editing mode.

This setting also manages the lock strategy for macro libraries.

Two buttons available in the dialog Tools>Macro>Macros...>Macro libraries ... will allow you to switch the mode of the selected library. In editing mode, these two buttons are disabled because all libraries are opened in editing mode and this mode cannot be switched.

This will allow other PLM users to be aware that the macro is being edited.

When a user interaction involves a modification of the current library (for example Tools>Macro>Macros...>Delete of the current macro, or after pushing the save button in the VBA editor) and if saving in the database of the modified library has failed, a pop-up window informs the user of this failure.

The in-session library has taken into account the modifications but the database library hasn't been updated. This scenario can occur, for example, if the library has been locked by another user or if the library has been modified in the database since the last time it was opened.

User Interface

In Tools>Macro>Macros..., if the current library is in read only mode, access to certain commands is modified as follows:


  • all commands involving a modification of the library are disabled (Create ..., Rename ..., Delete, Obfuscate...) and the command for editing the current macro is named "Browse..."
  • a small "do not enter" sign is displayed at the bottom left of the library icon (the small icon just on the left of the library name):




  • if the current library is in editing mode, all modification commands are enabled, the editing command is named Edit... and no "do not enter" sign is displayed:



You can switch from one mode to the other by clicking the Macro libraries... button then by clicking either the Switch to Read Only button or the Switch to Edition button.

You will only be able to switch between the two modes if you check the option Display a warning if read-only data are edited.

For example, click the Switch to Edition button:



to switch to editing mode, and the Switch to Read Only button:



to switch to read only mode.

Limitations

This section describes limitations.

Because the PLM entity for storing macros is a macro library, switching between read only and editing mode is only possible for whole macro libraries and not for single macros. In others words, it is not possible to have a macro in read only mode inside a macro library in read/write mode.

Concurrent modifications of a macro library in the database are not supported.