Home > The CATIA Object Model > Checking CATIA licenses at runtime

Checking CATIA licenses at runtime


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.

License basics

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

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.

Add to: del.icio.us del.icio.us, StumbleUpon StumbleUpon, Digg Digg, Google Google

Advertisements
  1. grzechu
    March 25, 2010 at 2:30 am

    Very good topic. I just can’t agree with one thing. From my experience, in most cases (not all, of course) API program doesn’t need a license, which is needed to handle the same functionality “manually”. Thats one of the API’s advantages.

  2. March 25, 2010 at 6:00 am

    Good point and I agree, I have never had any license issues with the vast majority of the API. Typically, you only have to worry about licenses for FTA, DMU, machining, analysis and so on. However, that is because most of us run a pretty full featured P2 configuration. I basically mentioned it for the case where you might be distributing your program to someone who might be running a very basic P2 config or maybe even some P1 config. Maybe some of the things we take for granted may not work. I have not done much with lower license configs so I don’t know how much of an issue it is….just pointing it out to be thorough.

  3. ismail
    July 14, 2010 at 4:41 pm

    how can i get license for catia?

    • July 14, 2010 at 8:23 pm

      Find an authorized reseller and write a big check – it’s not cheap…

  4. November 20, 2011 at 2:02 pm

    Very usefull, thanks!

  5. CAD Template Developper
    March 27, 2013 at 3:47 pm

    Amazing subject.
    I try something after I read your subject but I didn’t find:
    Is it possible to get licence from server as STEP (ST1) for example to save something in STEP and then give it back?
    It would be useful because the licenses in my company are busy.

  6. Snaft
    April 4, 2014 at 8:29 am

    Hi,
    in the same vein, is it possible to display at runtime who is using busy licenses (taken from the license server) ?

  1. No trackbacks yet.

Leave a Reply to v5vb Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: