The CATIA automation API provides an extensive set of functionality across many different workbenches. Depending on what functionality your program will provide, you may need to consider what licenses are required. In this article, I will show how to add code to your program to check whether certain licenses have been granted.
Every workbench requires some license to access its functionality. Most companies have some form of basic licensing scheme so that when you startup CATIA, you always get some “base” licenses that meet the needs of most users. Typically, there are also some additional shared licenses available for specialized workbenches.
Licenses are split into two types, static and dynamic. Static licenses are typically those that were requested when CATIA started. These licenses can be seen in Tools-Options on the General-Licensing page. Dynamic licenses are requested by the user after CATIA is started by going to the Tools-Options on the General-Shareable Products page.
In most cases, if end users need a license to use some CATIA functionality, your program will also need that license to do the same things. In the case where a required license has not been granted and you try to use that functionality, your program will throw an error. A simple check for the required license allows you to warn the user and prevent your program from crashing.
License scenarios to watch out for
Typically, when developing a program you will first try out the scenario and understand the commands interactively in CATIA. You may even record a macro while manually performing some actions. During this process, if you had to start CATIA using a special environment or if you had to request a shareable license in Tools-Options then you definitely want to look more closely at license issues.
Additionally, if you plan to distribute your program to other sites within your company or especially to other companies you may want to understand more closely whether your program will run on different base license configurations. Fortunately, I believe the majority of the CATIA automation API functionality will run with the licenses that a “typical” company will have. However, it’s just something to consider.
How it works
The CATIA license APIs can do a number of different things but in this article I am only going to discuss how to check whether a license has been granted. However, since I’m sure you are probably wondering about it, I will mention that you cannot request a new license or release one using the CATIA automation API.
License information is managed via CATIA settings, so all we need to do is access the proper SettingController objects. Static licenses are managed by the LicenseSettingAtt object and dynamic licenses are managed by the DynLicenseSettingAtt object. Both of these objects provide a method called GetLicense that will let you know if the license has been granted. Since many licenses can be granted either way, I typically just check both.
Understanding license names
You will need to know the proper name of each license before making a call to these objects. The easiest way to get this information is to go to the relevant tab page in Tools-Options then click the “dump parameters values” button in the lower left corner then open the file in a text editor and look for the item of interest.
The code below was written as a custom function to make it easy to simply drop into any new code project. You simply pass in the name of the license to check and whether you want to check only shareable, only static or both. The function will return true if the license has been granted or false if not.
Function IsLicenseGranted(ByVal iName As String, _ ByVal iControllerOption As Integer) As Boolean ' Author: Mike Berry (v5vb.wordpress.com) ' Arguments: ' iName Name of license to check (ex. "KIN.prd") ' iControllerOption 0 = Check static and dynamic ' 1 = Check static only ' 2 = Check dynamic only Dim objLicCtrl As LicenseSettingAtt Dim objDynLicCtrl As DynLicenseSettingAtt Dim blnLic As Boolean Dim blnDynLic As Boolean 'Check static license 'If license is granted, GetLicense will return the name of the license 'Or "NotRequested" if not granted Set objLicCtrl = CATIA.SettingControllers.Item("CATSysLicenseSettingCtrl") If objLicCtrl.GetLicense(iName) = "NotRequested" Then blnLic = False Else blnLic = True End If 'Check dynamic license 'If license is granted, GetLicense will return "Requested" 'Or "Undef" if not granted Set objDynLicCtrl = CATIA.SettingControllers.Item("CATSysDynLicenseSettingCtrl") If objDynLicCtrl.GetLicense(iName) = "Requested" Then blnDynLic = True Else blnDynLic = False End If 'Return result for the requested setting controllers Select Case iControllerOption Case 0 IsLicenseGranted = blnLic Or blnDynLic Case 1 IsLicenseGranted = blnLic Case 2 IsLicenseGranted = blnDynLic End Select End Function
In your program, simply use the function like this:
Sub CATMain() Dim blnLicGranted As Boolean Dim strMsg As String 'Check for a specific license blnLicGranted = IsLicenseGranted("KIN.prd", 0) If blnLicGranted = False Then strMsg = "This program requires the ""KIN"" license." &vbCrLf strMsg = strMsg &"Please get it, then try again..." MsgBox strMsg, vbExclamation, "License Required" End If End Sub
If the required license has not been granted, then the user would see a message like this,
Please take a moment to rate this article…Just click the stars up near the title.