There are numerous ways to deploy your various CATIA macros and VBA projects to a larger group of users. It is possible to create custom toolbars, use macro libraries or even execute them from a file folder. After experimenting over the years with different methods, I have found that using a catalog works very well. In this article, I will first discuss some issues associated with using some of those other methods then I’ll discuss the catalog option.
Custom toolbar button
It is possible to easily create your own custom toolbars in CATIA and add commands to them. You can also define a custom icon for each button and even the tooltip text that should appear when a user hovers their mouse over the icon. Each button can launch a CATIA command or in this case a macro or VBA project. I’m not going to discuss how to do this because it is covered well enough in the CATIA help docs (see notes at end of article).
Creating a custom toolbar gives a very professional appearance but unfortunately in most cases, it only works well on your PC. Distributing and maintaining that toolbar for many users can be a nightmare. There are actually several reasons for this, but the primary reason is due to the fact that the definition for that custom toolbar and all of its buttons is actually saved in CATSettings files.
In case you aren’t familiar with how CATSettings work I’ll briefly explain. First, realize that CATSettings aren’t just things you find in the Tools-Options panel – almost everything you do that affects the appearance of CATIA gets saved back to CATSettings. There are many CATSettings files and they are somewhat divided up by basic categories. However, one problem is that the same CATSetting file that manages your toolbars also manages many other settings.
The first time you start up CATIA, it usually grabs default settings that your company has defined and copies them to a folder specific to your login. From that point on, all changes you make are saved in your unique CATSetting files. When you consider this, what if you need to make a change to one of the macros referenced on a toolbar? Or remove one? Or add a new one? You can make those changes to your company default CATSettings but then to roll them out, you must force everyone to throw away some of their own local setting customizations and take the new default ones. This may work for just a few buttons or if the macros are very mature and don’t require any maintenance over time but in general it’s not a good option.
A macro library is typically a folder containing some CATScript and/or catvbs files or it is a specific catvba project. Macro libraries can be easily defined from the Tools-Macro dialog panel and this information finally gets saved into the CATSettings.
Overall, this is actually a fairly decent option. Once the macro libraries are defined, they can quickly be accessed by pressing ALT-F8. In the case of a folder based macro library, you also get good flexibility to add, modify or delete macros within that folder without impacting users. However, in the case of VBA based macro libraries, each one is setup as a separate library so like the toolbar option, they are not easily added, removed, etc. for a larger user group.
The user experience with a macro library is ok, but not great especially when the number of programs increases or when you have many different libraries. It can be cumbersome to switch between a lot of different libraries, there are not visual images for each program and you cannot include additional information about them to help the user understand what each one does.
Deploying macros through a catalog
I like using a catalog to deploy my programs because it offers so much flexibility and provides a good user experience as well. Like the options discussed above, I am not going to show how to make a catalog. The CATIA help docs do a decent job of that (see notes at end of article). Instead, I’ll outline some of the advantages of using catalogs below.
Single organized source
You can very easily provide all your programs through a single catalog. It doesn’t matter if you have 5 or 500 programs. You can organize them into as many chapters as you like for easy navigation. A single catalog can also refer to macros that are stored in any number of file folders across your network. Additionally, a catalog can point at other catalogs. This means your company can create one root catalog that points at other separate catalogs for parts, drawings, macros and so on. Then all users simply access a single catalog that points at these child catalogs. To the user, it just appears as a single catalog but on the back end, it provides great flexibility for the administrators. This root catalog should also be defined as a favorite in Tools-Options and moved to the top of the list. This way, when the user clicks the catalog browser button they always go directly to that “root” catalog.
The items in a catalog are called components and are stored in families. Think of families kind of like chapters except that in the catalog world, chapters only create structure while the families hold all the items. On each family, you have the ability to define keywords. They may be strings, numbers, etc. and each component in that family can assign its own value to each keyword. The result is a list of components in the family but each of the columns of keywords are also sortable by clicking on them. In the case of macros, you might use keywords to define the name of the macro, the version, a description, license requirements and so on. It might look something like this:
|The best macro||1.0||Does some great stuff||None|
|A better macro||2.3||Does even more stuff||KIN|
|Another macro||1.2||Exports lots of data||None|
If you have a lot of items in the catalog or maybe have too many chapters, it may not be easy to find what you want. Luckily, catalogs can be searched (filtered) by the user fairly easily, especially when keywords are added to the families. The filter will offer a list of all keywords and allow you to define the criteria using “and” logic. Finally, the results are displayed in a list along with all of the keyword values.
By security, I am referring to the ability to access and execute any given macro or program. Catalogs only store links to the items they refer to, not the actual documents. So when it comes to security, you will manage user permissions on the folders that contain those various documents. The catalog itself does not provide any security. For example, you might only want only one department to have access to certain macros – just put them in a specific folder and set the permissions accordingly. If the user selects that item from the catalog and does not have read access to that folder, CATIA will notify them that the file cannot be found or might have been deleted.
A nice aspect of using the toolbar option is the ability to set an icon for each macro. Catalogs can also provide an image for each macro but they use a larger image than an icon on a toolbar. This allows you to create an even more detailed preview to help the user recognize a specific function and maybe understand what it does. For high quality previews, store the images in a file folder that everyone has access to and let the catalog refer to them.
How do I launch a VBA project from a catalog?
Scripts are easy to include in a catalog, but catvba projects require just a bit more work. I like to launch my VBA projects from a separate script then just let the catalog refer to that script like any other macro. This can very easily be done using CATIA’s SystemService API. So, in this scenario, when the user clicks on an item in the catalog, behind the scenes, this is what happens:
User clicks item in catalog → Catalog executes script → Script launches VBA project
You can use essentially the same script as a template for every VBA project and simply edit a few variables each time that define the path of the file, the module name and the procedure name to be run. Here is an example:
Sub CATMain() Dim strPath As String Dim strModule As String Dim strProcedure As String Dim varArgs() As Variant 'Use empty array if procedure has no args 'Dim varArgs(2) As Variant 'Or size the array if procedure has args Dim strMsg As String 'Define where to find the VBA project and what to run inside it strPath = "C:\MyMacros\VBAProject1.catvba" strModule = "modMain" strProcedure = "CATMain" 'If the procedure has arguments, define them in the array 'As an example, a Sub with 3 input arguments in the VBA project 'Sub CATMain(iInputfile, iOutputFile, iPart) 'varArgs(0) = "C:\Data\InputData.txt" 'varArgs(1) = "C:\Data\OutputData.txt" 'Set varArgs(2) = CATIA.ActiveDocument.Part 'Launch the VBA project On Error Resume Next Call CATIA.SystemService.ExecuteScript(strPath, _ 2, strModule, strProcedure, varArgs) If Err.Number <> 0 Then ‘Any number other than zero is an error 'Add your own custom error message to the user strMsg = "An error occurred while trying to run the macro..." MsgBox strMsg, 16, "Error" End If End Sub
Related Help Documentation
For more information on making custom toolbars or creating catalogs, please refer to the CATIA help documentation. The locations listed below assume you are starting at the help documentation home page. If you have a question that is not covered in the help docs, post a comment and I’ll try to help.
Creating custom toolbars
Home – Infrastructure – CATIA Infrastructure User Guide – Customizing Toolbars
Creating and managing catalogs
Home – Infrastructure – Component Catalog Editor
Please take a moment to rate this article…Just click the stars up near the title.