Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

another C# question

Status
Not open for further replies.

itsmyjob

Mechanical
Joined
Apr 11, 2002
Messages
2,375
Location
CA
ok I'm getting into C# those days and here is my question:

Code:
CATIA.ActiveWindow.Layout = catWindowSpecsOnly

works fine in one line, but:

Code:
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
 
Code:
((SpecsAndGeomWindow)myCatia.ActiveWindow).Layout = (CatSpecsAndGeomWindowLayout) 0;

Eric N.
indocti discant et ament meminisse periti
 
Any useful websites regarding Catia? Also thinking to start a little bit with c#.

Regards,
Jenia Ladkov
 
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
 
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
 
Here's example of simple code (VS 2015 & WPF). Omit backgroundworker subs.
Code:
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
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
 
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
 
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
- Text along a curve for Catia V5
 
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
 
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:
#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:
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
 
can you check this?


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
 
Hmmm to control the env may be useful. Have never thought about that. Thanks a lot for link.

Regards,
Jenia Ladkov
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top