Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catia V5-R29 Automation Crash in Drafting with VB.NET code 1

Status
Not open for further replies.

Altan_D

Automotive
Nov 1, 2019
3
Hello All,

I have a VB.Net program uses Drafting, HybridShape and Part libraries which works fine from Catia R18 to R26. Some computers upgraded to R29 and it's now crashing in some drafting methods. It gives an exception as in the attachment snapshot. Problem happen first at myView.Activate(). If I disable this line, then it also crashes at myView.Tables.Add()

Code works fine when I try as CatScript or VBA macro in R29 but crashes with VB.NET. Is there anyone can help me about this problem?

Code:
Private Sub btncatdrawing_Click(sender As Object, e As EventArgs) Handles btncatdrawing.Click

        Dim CATIA As Application

        Try
            CATIA = Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")
        Catch ex As Runtime.InteropServices.COMException

            MessageBox.Show("CATIA V5 is not opened, start program first!", "DrawingTool - Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

            WindowState = FormWindowState.Normal

            Exit Sub
        End Try

        Dim partDocument1 As PartDocument
        partDocument1 = CATIA.ActiveDocument


        Dim FPath As String

        FPath = "C:\users\" & Environ("Username") & "\Desktop\Template.CATDrawing"

        Dim documents1 As Documents
        documents1 = CATIA.Documents

        Dim myDoc As DrawingDocument
        Try
            myDoc = CATIA.Documents.Open(FPath)
        Catch ex As Exception

            WindowState = FormWindowState.Normal
            MessageBox.Show("C:\users\" & Environ("Username") & "\Desktop\Template.CATDrawing is not found!", "DrawingTool - Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Exit Sub

        End Try

        myDoc = CATIA.ActiveDocument

        Dim mySheet As DrawingSheet
        mySheet = myDoc.Sheets.ActiveSheet

        Dim myView As DrawingView
        myView = mySheet.Views.Add("DrawingTool")
        myView.Activate()

             Dim MyTable As DrawingTable

        MyTable = myView.Tables.Add(100, 100, 5, 9, 7.5, 21)

End Sub
 
 https://files.engineering.com/getfile.aspx?folder=64e755a0-5067-4c88-b1bc-1ceca95ffa6d&file=Capture.JPG
Replies continue below

Recommended for you

Hi,

It runs perfectly for me. No errors. R29 GA.
References in the image attached.
Capture_qdqbci.png


Calin
 
Dear Calin,

Thank you for your reply.

I don't understand why it crashes. As I mentioned before it works perfect from R18 to R26. I checked the V5Automation.chm file comes with R29 version. It doesn't show any change in Drafting methods also.

Which IDE are you using? I initially developed the program in Visual Studio 2017 then upgraded to VS 2019 and continued coding in VS 2019. Same days we upgraded some computers to Catia R29. Could it be because of VS 2019?

Altan
 
Hi,

I'm using VS2012, target framework is .NET 4.5.2

Is your code crashing on all computers with R29? Can you run a test on a R29 GA (rollback the SP if any)?

Calin
 
Hi.

Remove all references and recreate them using tlb files located in R29 code\bin directory.
 
Hi All,

I followed your advices and simply replaced the references with the ones coming with R29. This solves the problem for users have R29 but now it fails on previous versions of CATIA. So what understand is, even CATIA doesn't mention any change in V5Automation.chm file for some methods we use, there are somethings changing (maybe the order of calling methods), so old references do not work.

I want my code to be universal for CATIA, so someone out of the forum advised me using late binding instead of early binding for version independency. This is much reliable than using CATIA references, at least it solved my version problem in DRAFTING methods, now it's working fine from CATIA R18 to R29 with late binding.

However another new issue came up in GSD methods with late binding. Basically I try to create a line with point-direction and a SecondUptoElement. Code fails when using Line's SecondUptoElem property and given error is "Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))"

Can anyone try below code and see if it's working? Basically create a point then create a line from point up to a plane.
And also any idea why "SecondUptoElem" property is not working in late binding?

Code:
Option Strict Off
Public Class Form1

    Public CATIA As Object

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        On Error Resume Next
        CATIA = GetObject(, "CATIA.Application")

        If Err.Number = 0 Then '0 means no error
            CATIA = CreateObject("CATIA.Application")
            Err.Clear()
        End If

        Dim partDocument1 As Object
        partDocument1 = CATIA.ActiveDocument

        Dim part1 As Object
        part1 = partDocument1.Part

        Dim hybridShapeFactory1 As Object
        hybridShapeFactory1 = part1.HybridShapeFactory

        Dim hybridShapePointCoord1 As Object
        hybridShapePointCoord1 = hybridShapeFactory1.AddNewPointCoord(100.0, 0.000000, 0.000000)

        Dim bodies1 As Object
        bodies1 = part1.Bodies

        Dim body1 As Object
        body1 = bodies1.Item("PartBody")

        body1.InsertHybridShape(hybridShapePointCoord1)

        part1.InWorkObject = hybridShapePointCoord1

        part1.Update

        Dim reference1 As Object
        reference1 = part1.CreateReferenceFromObject(hybridShapePointCoord1)

        Dim originElements1 As Object
        originElements1 = part1.OriginElements

        Dim hybridShapePlaneExplicit1 As Object
        hybridShapePlaneExplicit1 = originElements1.PlaneYZ

        Dim reference2 As Object
        reference2 = part1.CreateReferenceFromObject(hybridShapePlaneExplicit1)

        Dim hybridShapeDirection1 As Object
        hybridShapeDirection1 = hybridShapeFactory1.AddNewDirection(reference2)

        Dim hybridShapeLinePtDir1 As Object
        hybridShapeLinePtDir1 = hybridShapeFactory1.AddNewLinePtDir(reference1, hybridShapeDirection1, 0, 10, False)

        hybridShapeLinePtDir1.SecondUptoElem = reference2 

        body1.InsertHybridShape(hybridShapeLinePtDir1)

        part1.InWorkObject = hybridShapeLinePtDir1

        part1.Update

    End Sub
End Class
 
Hi.

> I want my code to be universal for CATIA, so someone out of the forum advised me using late binding instead of early binding for version independency. This is much reliable than using CATIA references, at least it solved my version problem in DRAFTING methods, now it's working fine from CATIA R18 to R29 with late binding.

That's a bad advice in a long term. You want to leverage type control features of C# which is not possible with late-binding. And it's actually good that you've faced errors in the early stages and didn't mess things up more.

As a general rule, you have to generate CATIA interop libraries (from .tlb) yourself with tlbimp.exe for each release. And yes, you will have two versions of your app, each with it's own set of libraries.

It's definitely manageable and the right way to go to maintain RELIABLE applications.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor