'Use C# for Catia V5 Automation
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.)
Solution 1:[1]
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.
Solution 2:[2]
You can do this:
- Add the
INFITF
typelib library in reference, which is an interface to the CATIA application INFITF.Application CATIA;
- Create Button inside; e.g.,
Private void buttonX(object sender, EventArgs e){ CATIA.Visible = true; }
Solution 3:[3]
- 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
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | NaijaProgrammer |
Solution 2 | SecretAgentMan |
Solution 3 |