×
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

another C# question

another C# question

another C# question

(OP)
ok I'm getting into C# those days and here is my question:

CODE --> VBA

CATIA.ActiveWindow.Layout = catWindowSpecsOnly 

works fine in one line, but:

CODE --> C#

INFITF.Application myCatia = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Catia.Application");
INFITF.SpecsAndGeomWindow theWindow = (INFITF.SpecsAndGeomWindow) myCatia.ActiveWindow;
theWindow.Layout = (INFITF.CatSpecsAndGeomWindowLayout) 0 ; // the value of catWindowSpecsOnly 

is there a better way?

Eric N.
indocti discant et ament meminisse periti

RE: another C# question

(OP)

CODE --> C#

((SpecsAndGeomWindow)myCatia.ActiveWindow).Layout = (CatSpecsAndGeomWindowLayout) 0; 

Eric N.
indocti discant et ament meminisse periti

RE: another C# question

Any useful websites regarding Catia? Also thinking to start a little bit with c#.

Regards,
Jenia Ladkov

RE: another C# question

(OP)
i took a book from the library... A biginner's guide to C#

As per CATIA, I mostly use the chm file.

for help I use my best friend DuckDuckGo

Eric N.
indocti discant et ament meminisse periti

RE: another C# question

Can someone please upload small application written in C#? Maybe like hiding points on button click. Trying to switch to C# and completely stuck.
The good thing is I can connect to Catia V5 pc.

Regards,
Jenia Ladkov

RE: another C# question

Here's example of simple code (VS 2015 & WPF). Omit backgroundworker subs.

CODE --> C#

namespace CatiaV5HideShowManager
{
    /// <summary>
    /// Interaction logic for HideElements.xaml
    /// </summary>
    public partial class HideShowCatiaV5GeoElements : UserControl
    {
        private BackgroundWorker bgWorker = new BackgroundWorker();
        

        public event EventHandler BackgroundWorkerCompleted;

        static INFITF.Application myCatia;
        static INFITF.Document myDoc;
        static INFITF.Document myProductDoc;
        static INFITF.Selection mySelection;
        static INFITF.VisPropertySet myVisProperties;
        public HideShowCatiaV5GeoElements()
        {
            InitializeComponent();

            bgWorker.RunWorkerCompleted += delegate { OnBackgroundWorkerCompleted(); };
        }

        private void OnBackgroundWorkerCompleted()
        {
            if (BackgroundWorkerCompleted != null)
            {
                BackgroundWorkerCompleted(this, null);
            }
        }
        public void HideAll_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                myCatia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
            }
            catch (Exception)
            {
            }
            myDoc = (Document)myCatia.ActiveDocument;
            myProductDoc = (Document)myCatia.ActiveDocument;
            mySelection = (Selection)myProductDoc.Selection;
            myVisProperties = (VisPropertySet)mySelection.VisProperties;
            mySelection.Search("CatPrtSearch.Surface,All");
            myVisProperties.SetShow(CatVisPropertyShow.catVisPropertyNoShowAttr);
            mySelection.Clear();                  
        }
    }
} 

Sample application can be downloaded from https://github.com/OndrejMikulec/CatiaLubeGroove

Will be useful for those who want to switch to C#. I'm switching because of other applications and support where 99% of code written in C#.

Regards,
Jenia Ladkov

RE: another C# question

Why do you want to make your automation in C#?
All of the support is written in vb. What advantages did you found using C#. Unfortunately, I don't know nothing of C#.

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: another C# question

(OP)
major point (according to me) for each side:

.NET is available with C#, create DLL for reuse...
VBA code saved in database (3DX) for all to share

did you google "C# vs VBA" ?

also learning another code is always good...

Eric N.
indocti discant et ament meminisse periti

RE: another C# question

I find VB.NET much more convenient in combination with CATIA, Excel or any other Office application than C#. Both languages (VB.NET vs C#) are equally powerful, it is more or less a matter of personal preference. But VB.NET is definitelly more friendly to Automation (CATIA or any other COM application) and syntactically much closer to VBA or VBScript than C#.

Tesak
http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

RE: another C# question

In addition to Catia I've started to develop other applications. All the examples and support are in C#. Yea VB code looks more convenient. You have to use some additional visualization tools for VS to make c# code not to look like "Spaghetti". I'm not a pro in VB so it's time to me to switch to C#. Yea bad thing Catia C# support.

Regards,
Jenia Ladkov

RE: another C# question

How do I create Catia instance if there is not active session in Windows? At Exception I want to try to create Catia instance.
This is VB.net

CODE --> VB.Net

#Region "GET CATIA V5"
        Dim myCATIA As INFITF.Application
        On Error Resume Next
        myCATIA = CType(GetObject(, "CATIA.Application"), INFITF.Application)
        If Err.Number <> 0 Then
            myCATIA = CreateObject("CATIA.Application")
            myCATIA.Visible = True
        End If
#End Region 

CODE --> C#

public CatiaV5Connection()
        {
            InitializeComponent();

            #region Check Catia V5 connection
            try
            {
                myCatia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application");

                CatiaV5.Foreground = new SolidColorBrush(Colors.Green);
                Connected.Visibility = Visibility.Visible;
                Disconnected.Visibility = Visibility.Collapsed;
                CatiaV5.ToolTip = "Connected to Catia V5";
            }
            catch (Exception)
            {
                Connected.Visibility = Visibility.Collapsed;
                Disconnected.Visibility = Visibility.Visible;
                CatiaV5.Foreground = new SolidColorBrush(Colors.Red);
                CatiaV5.ToolTip = "Not connected to Catia V5";
            }
            #endregion
        } 

Regards,
Jenia Ladkov

RE: another C# question

(OP)
can you check this?

https://stackoverflow.com/questions/9679375/run-an...

I have the feeling it could be a better solution as to start CATIA you might want to control the env and some other option using arguments in the command line

Eric N.
indocti discant et ament meminisse periti

RE: another C# question

Hmmm to control the env may be useful. Have never thought about that. Thanks a lot for link.

Regards,
Jenia Ladkov

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