I am writing a small program to automate creating Jpgs from CATIA part captures. I had previously written a similar program in VB.net, but we are now transitioning to C#. I seem to be having a lot of trouble simply getting objects from many functions, and it seems like my program isn't fully attached to the CATIA process. When coding in VB.net, the main windows would display the functions I was calling, such as opening a part file. C# does not seem to do this, and many results simply return null, or errors such as base {System.Runtime.InteropServices.ExternalException} = {"Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))"} Here is a small except of my program as an example. This is after a part file has been opened through code.
I never had problems like this when coding in VB.net, where things just seemed to 'work'. Anyone know where I am going wrong here???
Code:
INFITF.Application CatiaInstance;
private void AttachToCatia()
{
CatiaInstance = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Catia.Application");
}
private void WorkWithAnnotationSets()
{
MECMOD.PartDocument ActivePartDocument = (MECMOD.PartDocument)CatiaInstance.ActiveDocument;
MECMOD.Part ActivePart = ActivePartDocument.Part;
if (ActivePart.AnnotationSets.Count != 0)
{
AnnotationTypeLib.AnnotationSets AnnotationSets = (AnnotationTypeLib.AnnotationSets)ActivePart.AnnotationSets;
///Loop through all annotation sets
for (int i = 0; i < AnnotationSets.Count; i++)
{
AnnotationTypeLib.AnnotationSet AnnotationSet = (AnnotationTypeLib.AnnotationSet)AnnotationSets.Item(i);
[b]//AnnotationSets items always return a HRESULT: 0x80020009 (DISP_E_EXCEPTION), even though objects exist in the collection[/b]
///Loop through annotations found in a particular annotation set
for (int x = 0; x > AnnotationSet.Annotations.Count; x++)
{
AnnotationTypeLib.Annotation Annotation = (AnnotationTypeLib.Annotation)(AnnotationSet.Annotations as AnnotationTypeLib.Annotations).Item(x);
}
//loop through captures found in a particular annotation set
for (int y = 0; y > AnnotationSet.Captures.Count; y++)
{
AnnotationTypeLib.Capture Capture = (AnnotationTypeLib.Capture)(AnnotationSet.Captures as AnnotationTypeLib.Captures).Item(y);
}
}
}
}
I never had problems like this when coding in VB.net, where things just seemed to 'work'. Anyone know where I am going wrong here???