×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Interfacing with CATIA in C#

Interfacing with CATIA in C#

Interfacing with CATIA in C#

(OP)
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.

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);
               //AnnotationSets items always return a HRESULT: 0x80020009 (DISP_E_EXCEPTION), even though objects exist in the collection

                    ///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???

RE: Interfacing with CATIA in C#

(OP)
Well I solved on of my problems right after posting. I had forgotten that internally CATIA doesn't always use 0 indexing, so changing the for loops to begin on 1 properly returned the objects. Still can't figure out why you cannot see the functions running in a CATIA window though.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources