3

I want to write Macros/Programs for Catia V5 with the programming language C#.

How is it possible to access the Catia applicataion via c#(and Visual Studio). I searched a bit and found out that Catia provides an API, which the Microsoft COM Technologie provides for 'COM-languages' like c# & python.

This is how I imagine the connection/interaction between a C# Programm and Catia:

C# - .NET <-bi-directional integration-> COM <-> Catia API

Is that correct ?

Also: How do I setup everything in Visual Studio , so that I can access the Catia API (and code completion etc.)

Blackpanther0001
  • 258
  • 1
  • 3
  • 14

3 Answers3

5

1) Add INFITF typelib library in reference which is interface to CATIA application

2) Define CATIA as global variable as like

   INFITF.Application CATIA;

3) Bind the catia application to your CATIA variable as below statement

   CATIA = (INFITF.Application)Marshal.GetActiveObject("Catia.Application");

Hope this would helps you to get started.

NaijaProgrammer
  • 2,892
  • 2
  • 24
  • 33
  • Thanks, you are the best ! Whre can I download the INFITF library ? I have foun this instruction called "How to: Add References to Type Libraries" (https://msdn.microsoft.com/en-us/library/fwawt96c(v=vs.110).aspx). And don't know how to do the first step "1.Install the COM DLL or EXE file on your computer, unless a Windows Setup.exe file performs the installation for you." – Blackpanther0001 Nov 23 '16 at 16:12
0

You can do this:

  1. Add the INFITF typelib library in reference, which is an interface to the CATIA application
  2. INFITF.Application CATIA;
  3. Create Button inside; e.g.,
    Private void buttonX(object sender, EventArgs e){
        CATIA.Visible = true;
    }
    
SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
0
  1. Adding reference to CSProj:

As suggested by Selin Raja M; you have to "Add INFITF typelib library in references which is the interface to CATIA application (CATIA V5 InfInterfaces Object Library)". Simply follow: Project --> References --> Add ---> COM --> CATIA V5 InfInterfaces Object Library

  1. Binding the CATIA Application and Using inside CSProj

     using INFITF; 
     namespace SampleCatiaProj {
        public class LoadDocumentClass {
              public static INFITF.Application CATIA;
              public bool LoadDoc() {     
                 CATIA = INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
                 CATIA.Visible = true;
                 CATIA.DisplayFileAlerts = true;
    
                 ProductStructureTypeLib.ProductDocument oRootProductDocument;
                 oRootProductDocument = (ProductStructureTypeLib.ProductDocument)CATIA.ActiveDocument;
    
                 // Some code goes here
    
                 // Keep on adding code as per CATIA V5 automation API
    
                 return true;
           }
        }
     }
    

For practice programs, refer to this link

nitishhsinghhh
  • 23
  • 2
  • 10