Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

visual basic 2015

Status
Not open for further replies.

Santa123

Mechanical
Oct 2, 2006
80
0
0
PL
Hello everyone,

When I try get an instance of Catia, I get an error "An unhandled exception of type 'System.InvalidOperationException' occurred in Catia_1.exe".
I added reference to all needed libraries. Could you give me some guidenlines.


Code:
Imports INFITF
Imports DRAFTINGITF

Public Class Form1

    Public Shared Catia As Application = GetObject(vbNullString, "CATIA.Application")
    Public Shared MyDrawing As DrawingDocument = Catia.ActiveDocument
    Public Shared oSel As Selection = Catia.ActiveDocument.Selection

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lblDrawingName.Text = MyDrawing.Name
    End Sub

End Class

Regards
Santa

 
Replies continue below

Recommended for you

R u sure that you have active Catia instance and your active doc in this Catia is DrawingDocument? Your code works fine in right setup (First Catia instance has DrawingDocument as Active document). For any other setup you have to handle errors that occur.
 

I Added Referece:
- COM + Services Type Library
- CATIA V5 ApplicationFrame Object Library
- CATIA V5 CATMatInterfaces Object Library
- CATIA V5 DraftingInterfaces Object Library
- CATIA V5 InfInterfaces Object Library
- CATIA V5 SrtuctureInterfaces Object Library

When I changed my code to:

Code:
Imports INFITF
Imports DRAFTINGITF

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
         Dim Catia As Application = GetObject(vbNullString, "CATIA.Application")
         Dim  MyDrawing As DrawingDocument = Catia.ActiveDocument
         Dim oSel As Selection = Catia.ActiveDocument.Selection

        lblDrawingName.Text = MyDrawing.Name
    End Sub

End Class

I got error in line:
Code:
Dim Catia As Application = GetObject(vbNullString, "CATIA.Application")
 
Not at my pc at the moment. I'm writing from mobile so it's hard for me to check your second code. As I wrote earlier, your first thread Code worked for me with only this two references.

- CATIA V5 DraftingInterfaces Object Library
- CATIA V5 InfInterfaces Object Library

The important thing is that you have active at least one catia. If there are more instances, program will bind on one that you started first. Catia App that you use needs a drawing as an active document. If not so, you can not set active document as drawingdocument.

You should be able to find a proper solution for binding or starting a new setion of catia on-line. Then you should check for active document type and set drawingdocument only if type fits.
 
try with this ...
Code:
Imports INFITF
Imports DRAFTINGITF

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim CATIA As Application
        Try
            CATIA = GetObject(vbNullString, "CATIA.Application")
        Catch ex As Exception
            MessageBox.Show("You don't have active Catia!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Close()
            Exit Sub
        End Try
        If CATIA.Documents.Count <> 0 Then
            If TypeName(CATIA.ActiveDocument) = "DrawingDocument" Then
                MessageBox.Show("It works")
                Dim MyDrawing As DrawingDocument = CATIA.ActiveDocument
                Label1.Text = MyDrawing.Name
            Else
                MessageBox.Show("It works but ActiveDoc isn't a drawing")
                Close()
            End If
        Else
            MessageBox.Show("Catia works but it has no documents.")
            Close()
        End If
    End Sub
End Class

be sure that you have added

- CATIA V5 DraftingInterfaces Object Library
- CATIA V5 InfInterfaces Object Library
 
Well I must say that the reason why the upper code does not work, is beyond me. You could try to replace next line in code:

Code:
CATIA = GetObject(vbNullString, "CATIA.Application")

with

Code:
CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")

or check in this thread for further options with binding to Catia:

Link

Hope this helps or someone more experienced comes to this thread.
Regards
Roman
 
I messed up a bit, it turns out that I can't run cnext.exe /regserver
I got error:
Creating registry key
HKEY_CLASSES_ROOT\.CAT3DEXPOperation_ENOVIAV5 failed
Access denied
 
Status
Not open for further replies.
Back
Top