Hello everybody, I'm a newbie here... I'm a software developper in C#, I'm not a master of c# but I know enough to code Windows desktop software in WindowsForm (and sometimes in WPF).
I use CATIA v5r22 sp6 (HD2+FS1+KT1 modules) on Windows 7 pro x64 and Microsoft Visual Studio Community 2015.
Now I try to code my first Catia macro in C# with Visual Studio because I don't know VBA very well (and I hate it... ).
I have no problem to intercept COM object of my Catia session, but I don't know why I can't use the Catia.ActiveDocument !
My (little) code:
Visual Studio explain that's an implicit cast problem between "myPartDocument" in MECMOD.PartDocument format and "myCatia" in INFITF.Application format.
If you have any idea, please I need some help... Many thanks in advance!
I use CATIA v5r22 sp6 (HD2+FS1+KT1 modules) on Windows 7 pro x64 and Microsoft Visual Studio Community 2015.
Now I try to code my first Catia macro in C# with Visual Studio because I don't know VBA very well (and I hate it... ).
I have no problem to intercept COM object of my Catia session, but I don't know why I can't use the Catia.ActiveDocument !
My (little) code:
Code:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
// partie spécifique à CATIA
using INFITF;
using MECMOD;
using PARTITF;
using KnowledgewareTypeLib;
using ProductStructureTypeLib;
namespace MacroCatiaTest1
{
public partial class Form1 : Form
{
bool CatiaRunning = false;
public Form1()
{
InitializeComponent();
}
private void BTtest_Click(object sender, EventArgs e)
{
INFITF.Application myCatia = null;
try
{
myCatia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
CatiaRunning = true;
}
catch (Exception PresenceCatia)
{
MessageBox.Show("CATIA n'est pas lancé!\nMacro impossible à executer!\n\n" + PresenceCatia.Message, "Erreur critique", MessageBoxButtons.OK, MessageBoxIcon.Error);
CatiaRunning = false;
}
if (CatiaRunning)
{
myCatia.Visible = true;
myCatia.DisplayFileAlerts = true;
try
{
[b]PartDocument myPartDocument = (PartDocument)myCatia.ActiveDocument;[/b] ==> Here is my problem...
Part myPart = myPartDocument.Part;
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}
}
}
}
Visual Studio explain that's an implicit cast problem between "myPartDocument" in MECMOD.PartDocument format and "myCatia" in INFITF.Application format.
If you have any idea, please I need some help... Many thanks in advance!