Welcome to the COE Discussion Forum! 

 

To participate in the discussion forum, you must be logged in to the website.  If you forget your login information, please contact COE Headquarters at coe@coe.org or (800) 263-2255.

If you are new to the COE Discussion Forum and would like to participate, please register.

 

The COE 2008 Fall Industry Workshops

Automotive
Oct. 15-16
Troy, Michigan

 

Aerospace & Defense
Oct. 27-28
Wichita, Kansas

   

Register Today!

COE DISCUSSION FORUM
Subject: How to use VB.NET in CATIA V5?

You are not authorized to post a reply.   
Author Messages
COE-FORUM-USER

09 Oct 2006 10:44 AM
Dear guys,

I have been using CATIA V5 for 2 years and 3 years VB.NET. However, I have just start combining CATIA and VB 3 months. Now, I can write a application or script by VB 6 (not VB.NET) in CATIA and I have had some of VB applications such as:

- Import Points from Excel

- Create Multi Holes at the same time

- A program like TG1 license

In order words, I can control how to write a program in CATIA by VB. However, because I want to write a program in CATIA by VB.NET (not VB 6 anymore ) from now on. Thus, my most concerns know are:

1. How can I use VB.NET in CATIA? If anyone has a simple program, please send it to me or explain here such as creating a new CAT Part. It would be very great.

2. I know how to run VB application in CATIA. However, whenever I run VB application, I have to open CATIA and go to Marco to select application to run it. That is not what I want now. I want to run VB application without opening CATIA first like running a command. I mean, when I run VB application, it will call CATIA later.

I also looked up some of topcis about VB.NET here but none of them were clear. Thats why I post my message here for help. Any suggestions will be appreciated.

Tony Tran
COE-FORUM-USER

09 Oct 2006 11:30 AM
The biggest thing you'll note that VB.Net type defintions require the Namespace to be added.

Look up INFITF, MECMOD, ProductStructureTypeLib, etc in the object browser for hints.


example:

Dim CATIA As INFITF.Application

CATIA = GetObject(, "CATIA.Application")
If CATIA Is Nothing Then CATIA = CreateObject("CATIA.Application")
COE-FORUM-USER

09 Oct 2006 01:40 PM
Thank you for replying so fast. I got the answer for my first question. How about the second question? Suppose that I complie a VB.NET program to .EXE. How can I run this program outside of CATIA? For example: hole.exe CATIA or something else like that

Good day,

Tony Tran
COE-FORUM-USER

09 Oct 2006 02:12 PM
I'm not sure I understand the question...

.EXE files are running separate from CATIA. They are Windows programs. The above code merely links the EXE to a CATIA session (or creates a session if not present). You can start the EXE's .Net makes by double-clicking them in Windows Explorer. Until you ask for a connecetion to a CATIA session in the code you are running outside of CATIA.
COE-FORUM-USER

09 Oct 2006 02:56 PM
Here is a VB.NET console application which gets Catia and creates a new part:


Module Main
Sub Main()
Console.WriteLine("Hello World!")
Dim oCat as System.Type = System.Type.GetTypeFromProgID("Catia.Application")
Dim CATIA as Object = System.Activator.CreateInstance(oCat)
Console.WriteLine(CATIA.Caption)
Dim oDoc as Object = CATIA.Documents.Add("Part")
Console.WriteLine(oDoc.Name)
End Sub
End Module

Tested in SharpDevelop 2.0.

As mentioned before, just double click the .exe and the application will run. Alternatively, you could add an icon to the toolbar. This has probably been discussed elsewhere in the forum.

By the way, I'm a .NET novice so this may not be the best idea in the world

BJORN_D

10 Oct 2006 02:28 AM
Hi dragonvn

You can also find lots of info by searching the net for office automation with VB.NET (word, excel etc.) Much of the information about getting the application etc. can be used for handling CATIA as well.

Jack Smith mentioned Sharp Develop, I'm using it right now.
An awesome program for making VB.NET programs and it is amazing that it is free!

http://www.icsharpcode.net/OpenSource/SD/Default.aspx

-Bjorn D
COE-FORUM-USER

10 Oct 2006 03:45 AM
Hi All

here some samples VB .NET


' SUB
Dim CATIA As INFITF.Application
Try
CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")
Catch ex As System.Runtime.InteropServices.COMException
MessageBox.Show("CATIA V5 starten!", "Error",MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
Dim MyPartDoc As PartDocument = CATIA.Documents.Add("Part")
Dim MyPart As Part = MyPartDoc.Part
Dim MyHB As HybridBody = MyPart.HybridBodies.Add()
Dim MyHSF As HybridShapeFactory = MyPart.HybridShapeFactory
Dim MyP As HybridShapePointCoord = MyHSF.AddNewPointCoord(10, 10, 10)
MyHB.AppendHybridShape(MyP)
MyPart.Update()
' END SUB

here some possibilities to get CATIA

Dim CATIA As Object
CATIA = GetObject(, "CATIA.Application")
MsgBox(CATIA.ActiveDocument.Name)


Object / Marshal

Code:
--------------------------------------------------------------------------------
Dim CATIA As Object
CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")
MsgBox(CATIA.ActiveDocument.Name)
--------------------------------------------------------------------------------


Application / Marshal

Code:
--------------------------------------------------------------------------------
Dim CATIA As INFITF.Application
CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")
MsgBox(CATIA.ActiveDocument.Name)
--------------------------------------------------------------------------------


Application / GetObject

Code:
--------------------------------------------------------------------------------
Dim CATIA As INFITF.Application
CATIA = GetObject(, "CATIA.Application")
MsgBox(CATIA.ActiveDocument.Name)
--------------------------------------------------------------------------------


COE-FORUM-USER

10 Oct 2006 09:14 AM
Thank you so much. I will try it and let you guys know later.

Tony Tran
COE-FORUM-USER

10 Oct 2006 10:00 AM
Now I got these problem when I insert this code

<blockquote>Quote
<hr>
SUB
Dim CATIA As INFITF.Application
Try
CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")
Catch ex As System.Runtime.InteropServices.COMException
MessageBox.Show("CATIA V5 starten!", "Error",MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
Dim MyPartDoc As PartDocument = CATIA.Documents.Add("Part")
Dim MyPart As Part = MyPartDoc.Part
Dim MyHB As HybridBody = MyPart.HybridBodies.Add()
Dim MyHSF As HybridShapeFactory = MyPart.HybridShapeFactory
Dim MyP As HybridShapePointCoord = MyHSF.AddNewPointCoord(10, 10, 10)
MyHB.AppendHybridShape(MyP)
MyPart.Update()
' END SUB<hr></blockquote>

<b>Type 'INFITF.Application' is not defined.</b>

<b>Type 'PartDocument' is not defined.</b>

=====================

So, is there any library or reference that I need to add in?

I found some topics at other sites but I cannot understand clearly what they are talking because it isn't English

http://ww3.cad.de/foren/ubb/Forum137/HTML/000861.shtml#000004

http://ww3.cad.de/foren/ubb/Forum137/HTML/001893.shtml#000002

http://ww3.cad.de/foren/ubb/Forum137/HTML/001778.shtml#000014

http://ww3.cad.de/foren/ubb/Forum137/HTML/000496.shtml#000005

http://ww3.cad.de/foren/ubb/Forum137/HTML/001778.shtml#000016

http://ww3.cad.de/foren/ubb/Forum137/HTML/001860.shtml#000001

http://ww3.cad.de/foren/ubb/Forum137/HTML/001860.shtml#000007

From these topics, I just know what I have to import:

Imports INFITF
Imports MECMOD
Imports HybridShapeTypeLib

However I do not understand this dialogue. Please translate this for me

Quote


Damit du nicht
Dim MyHB As MECMOD.HybridBody
schreiben mußt, muß der Namespace MECMOD entweder mit Imports MECMOD importiert werden (in 1.Zeile schreiben), oder global für das ganze Projekt bei den Namespaces Haken setzen.(Rechtsklick auf Projekt -> Eigenschaften. Unter Verweise (s. Bild))



Good day,

Tony Tran
COE-FORUM-USER

10 Oct 2006 02:11 PM
You'll have to include some references...
>> CATIA V5 InfInterfaces Object Library
>> CATIA V5 MecModInterfaces Object Library

In .Net, just about every Dim needs a namespace
>> Dim MyPartDoc As PartDocument = CATIA.Documents.Add("Part")
changes to
>> Dim MyPartDoc As MECMOD.PartDocument = CATIA.Documents.Add("Part")

Note that the VB.Net IDE should help you when you finish typing "As"; it should have a list of Namespaces it knows and once you hit the "." it should list the types within that namespace. If it stops helping, you've gone into a reference that it doesn't know.
COE-FORUM-USER

11 Oct 2006 09:10 AM
Yeah...it worked. Thank you so much guys.

By the way, do you know there is any CATIA programming books using VB.NET that I can learn?

Tony Tran
COE-FORUM-USER

12 Oct 2006 10:28 AM
Hi guys,

I have a question today, it looks like very simple thing but I could not find it.

What are references for Parameters and Dimension?

--> Sorry, I got it. I should import this Library: CATIA V5 KnowledgeInterfaces Object to use Dimension, Parameters, relations and formulas.

Good day,

Tony Tran
You are not authorized to post a reply.
Forums > COE Forums > CATIA V5 Programming > How to use VB.NET in CATIA V5?



ActiveForums 3.6

    

401 North Michigan Avenue, Chicago, IL 60611-4267 | (312) 321-5153 | (800) COE-CALL (U.S.)