0

I'm trying to access CATIA functions in updating document life cycle in Smarteam in excel macro, the following lines

Dim CATEngine As StiEngine

Set CATEngine = CATIA.GetItem("CAIEngine")

keeps returning error 91: variable not set issue.

From this link I'm not why a simple command like this is returning this error http://catiadoc.free.fr/online/interfaces/interface_StiEngine.htm

perhaps I'm not loading certain libraries/ integrations properly? all insights welcome

This is the code from other module that worked, non option explicit and non global definitions (i've tried global define CATIAEngine, but it returns ambiguity error):

Sub checkUUID()

    Dim FoundObj As ISmObject
    Dim wbNew As Workbook, wsNew As Worksheet
    Dim checkDOCUUID As Document
    Dim Products As Products
    Set wbNew = ActiveWorkbook
    Set wsNew = wbNew.Sheets(1)
    Set SmEngine = CreateObject("SmApplic.SmFreeThreadedEngine")
    SmEngine.Init "SmTeam32"
    Set SmSession = CreateObject("SmApplic.SmSession")
    SmSession.Init SmEngine, "MySession", "SmTeam32"
    wsNew.Activate
    Dim childList() As String

    Set SmDatabase = SmEngine.Databases(0)
    ID = SmDatabase.Alias           'Provider=SQLOLEDB.1;Persis Security Info=False;User ID=SMARTUSER;Initial Catalog=Smarteam;Data Source=ST2008SQL\SQLSMARTEAM
    Pass = SmDatabase.Password      'ProvidSMARTEAM_7kikX/GtJNG6d7BcYeTi8cf4IuVCgWjDrvo/Oo4xdZgHjg+fDpzdEEll7tcGT96tcB7pP8krz1hw6pDgzXchTrwfm1t0FKGsDK6C7EvQW7+grVLwZamcVpnmz6ibMWAogHWcLM+H6ID87NIXwBLXNaJxm3tKg6eZ84nzNSkCGFc=
    Call SmSession.OpenDatabaseConnection(ID, Pass, True)

    If SmSession.IsServiceEnabled("SmGUISrv.SmCommonGUI", Reason) Then
        Set GUIServices = SmSession.GetService("SmGUISrv.SmCommonGUI")
    End If

    GUIServices.Dialogs.ExecuteLogin

    Set FSO = CreateObject("Scripting.filesystemobject")


    tempFolderName = "C:\ST Temp\UUID\"
    If Len(Dir("C:\ST Temp\", vbDirectory)) = 0 Then
        MkDir "C:\ST Temp\"
    End If

    If Len(Dir("C:\ST Temp\UUID\", vbDirectory)) = 0 Then
        MkDir tempFolderName
    End If

    CatiaConnect                                'launch Catia V5
    CatIntgConnect                              'connect to ST using ST CATIA integration
    CATIA.DisplayFileAlerts = False             'disable all the warning's and disables all the user interaction





CatIntgConnect

Sub CatIntgConnect()

    Set CATEngine = CATIA.GetItem("CAIEngine")

    ' -----------------------------------------------------------
    ' CATIA V5 Operations are performed in the background
    ' -----------------------------------------------------------
    Dim BooleanUI As Boolean
    If (CATEngine.UseGraphicalUI) = True Then
            CATEngine.UseGraphicalUI = True
            BooleanUI = True
    End If
    ' -----------------------------------------------------------
    ' Connect to the SmarTeam database (if not already connected)
    ' -----------------------------------------------------------
    Dim BoolConnect As Boolean
    BoolConnect = False
    If Not CATEngine.IsConnected() = True Then
             CATEngine.Connect "", ""             'to perform automation via CATIA SMARTEAM integration, must type in the userid and password
             BoolConnect = True
    End If
End Sub
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
Nicolas
  • 1
  • 1
  • a) Are you in an [Option Explicit](https://i.stack.imgur.com/xyVrl.gif) environment? b) Do you have the VBE's Tools, References, Smarteam libraries all set? –  Sep 19 '18 at 18:23
  • 1
    What's `CATIA` exactly? If it's `Nothing`, that's why it's blowing up. – Mathieu Guindon Sep 19 '18 at 18:25
  • I looked up Option Explicit, and I believe this is not the environment. There are other working modules that had this work: Dim FoundObj As ISmObject Set SmEngine = CreateObject("SmApplic.SmFreeThreadedEngine") SmEngine.Init "SmTeam32" Set SmSession = CreateObject("SmApplic.SmSession") SmSession.Init SmEngine, "MySession", "SmTeam32" ... ... CatiaConnect 'launch Catia V5 CatIntgConnect 'connect to ST using ST CATIA integration CatIntgConnect starts with line CATEngine = GetItem("CAIEngine") – Nicolas Sep 19 '18 at 18:31
  • If `Option Explicit` isn't at the top of the module, then VBA will happily compile pretty much anything you throw at it. Always use Option Explicit. Debug > Compile VBAProject. Does it compile? Is `CATIA` defined or the VBE is saying it's an undeclared variable? Help us out here... – Mathieu Guindon Sep 19 '18 at 18:33
  • Sorry the comments were sent before finishing and it took me a while to edit the full content... new user blurrgh. it does compile, with the CATIA application and Smarteam application opened, running this CATIA.GetItem appeared to have no problem for other modules, and is what the previous maintainer of this script said as the necessary set up. – Nicolas Sep 19 '18 at 18:40
  • ok the edit on first comment still looked horrible... A lot of the SmEngine and SmSession are dealing with Smarteam (CATIA bonded database), with CATIA open, it is connected to Smarteam, and therefore able to update life cycle through CATIA, it is viable in manual operations in CATIA. So trying to automate these tasks in CATIA through VBA script using CATIA API, I was told the environment would just require CATIA application to be opened while running script, in regular module mode, and correct CATIA API syntax. – Nicolas Sep 19 '18 at 18:47
  • Dont edit your comments, [edit] your post! – Mathieu Guindon Sep 19 '18 at 18:54
  • `CATEngine = GetItem("CAIEngine")` isn't the same as `Set CATEngine = CATIA.GetItem("CAIEngine")`. Put a breakpoint on that line of code (F9), then run it. When the breakpoint is hit, press Ctrl+G then type `?CATIA Is Nothing` if the word `True` gets printed out, you need to `Set CATIA` to a valid object reference. – Mathieu Guindon Sep 19 '18 at 18:58
  • Yes it did return true! and what is an example of valid object reference? sorry I just have not seen Set CATIA in any other sections of the code – Nicolas Sep 19 '18 at 19:11
  • i've prompt using it to the IT guys, it will probably take a while for them to get back to me – Nicolas Sep 19 '18 at 19:54
  • ok i finally got rubberduck, and yes somewhere in a script there is a line: Set CATIA = GetObject(, "CATIA.Application"), after adding this definition the line works! Great helps, and great plugin! – Nicolas Sep 19 '18 at 22:19

0 Answers0