CADMonkey

Difficulty using ObjGet to link to open application

18 posts in this topic

Hi Guys,

i need to access the API in an application called catia (CAD). I can do what i need from Excel in VBA;

Sub test()

Dim CATIA As Object
Set CATIA = GetObject(, "CATIA.Application")
Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Open("\\share\thefile.CATPart")

End Sub

But I cannot get it to work from Autoit;

#include <MsgBoxConstants.au3>

Func _test()

    $oCatia = ObjGet("","CATIA.Application") ; Get an existing Catia Object

    $documents1 = $oCatia.Documents

    $partDocument1 = $documents1.Open("\\share\thefile.CATPart")


    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "Catia File Test" & @CRLF & "Error Getting an active Catia Object. Error code: " & Hex(@error, 8))
        Return False
    EndIf


EndFunc

I get no error, it just does nothing!

I tried using the autoit scriptomatic, but it threw errors!

Any pointers on how to use objGet would be gratefully received!

Share this post


Link to post
Share on other sites



Add a COM error handler to your script to get more detailed error information.

See the help file for ObjEvent for an example.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You should see this.

https://www.autoitscript.com/autoit3/docs/functions/ObjEvent.htm

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

    ; Create Internet Explorer object
    Local $oIE = ObjCreate("InternetExplorer.Application")
    ; Check for errors
    If @error Then Return

    $oIE.Visible = True ; set visibility

    ; Custom sink object
    Local $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2")

    ; Navigate somewhere
    $oIE.navigate("http://www.google.com/")
    ; Check for errors while loading
    If @error Then
        $oIE.Quit()
        Return
    EndIf

    ; Wait for page to load
    While 1
        If $oIE.readyState = "complete" Or $oIE.readyState = 4 Then ExitLoop
        Sleep(10)
    WEnd

    ; Deliberately cause error by calling non-existing method
    $oIE.PlayMeARockAndRollSong()

    ; Check for errors
    If @error Then MsgBox($MB_SYSTEMMODAL, "COM Error", "@error is set to COM error number." & @CRLF & "@error = 0x" & Hex(@error))

    ; Wait few seconds to see if more events will be fired
    Sleep(3000)

    ; Nothing more to do. Close IE and return from the function
    $oIE.Quit()

    #forceref $oErrorHandler, $oIEEvents
EndFunc   ;==>Example

; BeforeNavigate2 method definition
Func _IEEvent_BeforeNavigate2($IEpDisp, $IEURL, $IEFlags, $IETargetFrameName, $IEPostData, $IEHeaders, $IECancel)
    ConsoleWrite("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--BeforeNavigate2 fired--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " & @CRLF & _
            "$IEpDisp = " & $IEpDisp() & "  -  " & ObjName($IEpDisp) & @CRLF & _ ; e.g. default property and name for the object
            "$IEURL = " & $IEURL & @CRLF & _
            "$IEFlags = " & $IEFlags & @CRLF & _
            "$IETargetFrameName = " & $IETargetFrameName & @CRLF & _
            "$IEPostData = " & $IEPostData & @CRLF & _
            "$IEHeaders = " & $IEHeaders & @CRLF & _
            "$IECancel = " & $IECancel & @CRLF & _
            "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " & @CRLF & @CRLF)
EndFunc   ;==>_IEEvent_BeforeNavigate2

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

Direct from the example :P

Share this post


Link to post
Share on other sites

HI,

I have tried the script.

I get the following in the output window;

comerrortests.au3 (11) : ==> COM Error intercepted !
    err.number is:         0x80020006
    err.windescription:    Unknown name.

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     
    err.lastdllerror is:     0
    err.scriptline is:     11
    err.retcode is:     0x00000000

I have tried looking up that error, but nothing seemed to apply.  Any suggestions would be greatly appreciated!

Share this post


Link to post
Share on other sites

ObjGet only works when CATIA is up and running. If not you will get this error. It can be ignored when you start up CATIA then.

Global $oCATIA = ObjGet("", "CATIA.Application")
If Not IsObj($oCATIA) Then
    $oCATIA = ObjCreate("CATIA.Application")
    If @error Or Not IsObj($oCATIA) Then Return SetError(1, @error, 0)
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks for the quick reply Water, but the application is already running.

As in the first post, i can access it from excel using CATIA.Application, but Autoit does not find it.

I have tested the autoit code, and it finds EXCEL.Application ok.

Any other thoughts?

Share this post


Link to post
Share on other sites

As in the first post, i can access it from excel using CATIA.Application, but Autoit does not find it.

You mean by VBA?

Can you post the code please?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You mean by VBA?

Can you post the code please?

 

Hi Water,

the VBA code is in the initial post.

The other difficulty is that the program starts with via a configuration script, so I cannot objcreate. (hence why i need objget)

Share this post


Link to post
Share on other sites

ObjGet allows to directly specify the file to open with the associated application

$oPartDocument1 = ObjGet("\\share\thefile.CATPart")

Maybe this works. If it doesn't copy the file to a local drive and try again.

See the help file for ObjGet for further examples.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

ObjGet allows to directly specify the file to open with the associated application

$oPartDocument1 = ObjGet("\\share\thefile.CATPart")

Maybe this works. If it doesn't copy the file to a local drive and try again.

See the help file for ObjGet for further examples.

 

The error occurs before it gets to the part document.

 

To clarify, the code (modified from the example linked above) that gives the error is;

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

    ; Create Internet Explorer object
    Local $oIE = ObjGet("", "CATIA.Application")
    ; Check for errors
    If @error Then Return

    $oIE.Visible = True ; set visibility

    ; Deliberately cause error by calling non-existing method
    $oIE.PlayMeARockAndRollSong()

    ; Check for errors
    If @error Then MsgBox($MB_SYSTEMMODAL, "COM Error", "@error is set to COM error number." & @CRLF & "@error = 0x" & Hex(@error))

    ; Wait few seconds to see if more events will be fired
    Sleep(3000)

    ; Nothing more to do. Close IE and return from the function
    $oIE.Quit()

;~     #forceref $oErrorHandler, $oIEEvents
EndFunc   ;==>Example


; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

The error given in the output;

comerrortests.au3 (11) : ==> COM Error intercepted !
    err.number is:      0x80020006
    err.windescription: Unknown name.

    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    0
    err.scriptline is:  11
    err.retcode is:     0x00000000

+>13:52:59 AutoIt3.exe ended.rc:0
+>13:52:59 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.3662

The 'err.scriptline is:   11' above leads me to;

Local $oIE = ObjGet("", "CATIA.Application")

Thanks again.

Share this post


Link to post
Share on other sites

 What does this script return?

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oError = ObjEvent("AutoIt.Error", "_ErrFunc")

    ; Open the document
    $oPartDocument1 = ObjGet("C:\temp\testfile.CATPart")
    ; Check for errors
    If Not @error Then MsgBox($MB_SYSTEMMODAL, "Info", "Document successfully opened.")

EndFunc   ;==>Example


; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    MsgBox($MB_SYSTEMMODAL, "COM Error", @ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode))
EndFunc   ;==>_ErrFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

CATPART_Open_Test.au3 (11) : ==> COM Error intercepted !
    err.number is:      0x80004002
    err.windescription: No such interface supported

    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    0
    err.scriptline is:  11
    err.retcode is:     0x00000000

Hi Water,

I get the above error (line 11 is the objget line).  It is weird, because the application tries to open the file, but it fails at the last. The file even appears in the history and I can manually open it from that list!

I have tried the same method using VBA (excel) and it opens the file ok.

Just 'thinking out lout' so to speak, but the catia application on this machine is 32bit and the OS is 64bit win 7.  Does autoit see a difference between the 32 and 64 bit, and is there a way to force autoit to use 32bit?

Share this post


Link to post
Share on other sites

Add

#AutoIt3Wrapper_UseX64=N

at the top of your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

a 'swing and a miss' there i'm afraid. (I tried with Y and N!)

Having spoken with a collegue, this apparently works from python to catia.

Share this post


Link to post
Share on other sites

Then I have run out of ideas I'm afraid :(


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Many thanks for your help Water.

Looks like I need to learn python!

Share this post


Link to post
Share on other sites

Had the same issue except that I knew that this used to work with previous versions of AutoIt.

autoit-v3.3.8.1 is working but not working since autoit-v3.3.10.0

$obj = ObjGet("", "CATIA.Application")

autoit-v3.3.10.0 to autoit-v3.3.14.2i are returning :

    err.number is:      0x80020006
    err.windescription: Unknown name.

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

Thank you for posing this reply pcjco.  I have the same problem with my com app.

It works fine in autoit-v3.3.8.1  but not in any later versions 

I get the same error - 0x80020006 Unknown name.

 

Does anybody know why this was working and now is a bug in ALL later versions?

My compiled 3.3.8.1 version still works but can not make changes unless I use the earlier versions of Autoit.

 

I wish that someone could research why this stopped working.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now