Exemple #1
0
        public Selection GetIRobotMotion(Form FM, DataType.Dsystem DSystem, int SelectType = 9, string Mess = "请选择一个机器人")
        {
            FM.WindowState = FormWindowState.Minimized;
            INFITF.Application CatApplication = DSystem.DSApplication;
            Selection          USelect        = null;

            try
            {
                ProcessDocument PPRP = DSystem.DSActiveDocument;
                if (PPRP == null)
                {
                    USelect = DSystem.CDSActiveDocument.Selection;
                }
                else
                {
                    USelect = PPRP.Selection;
                }
            }
            catch (Exception)
            {
            }
            USelect.Clear();
            var Result = USelect.SelectElement2(DataType.InputObjectType(SelectType), Mess, true);

            if (Result == "Cancel")
            {
                return(null);
            }
            if (USelect.Count < 1)
            {
                MessageBox.Show("请先选择对象后再点此命令!");
                return(null);
            }
            return(USelect);
        }
Exemple #2
0
        public void createPoint()
        {
            Console.WriteLine("--> create point");

            catia = CATMain.catia;
            // How do I re-reference the CATIA object here?
        }
Exemple #3
0
 public void SetApplication(INFITF.Application APP, Document CatDoc, ProductDocument CatADoc, Documents CatDocs)
 {
     CatApplication = APP;
     CatActiveDoc   = CatADoc;
     CatDocument    = CatDoc;
     CatDocuments   = CatDocs;
 }
Exemple #4
0
        public bool GetOrCreateInstance()
        {
            try
            {
                object CATIAinst = Marshal.GetActiveObject(CATIAapp);
                myCATIA = CATIAinst as INFITF.Application;
                Console.WriteLine("CATIA instance activated !");
            }
            catch (Exception Ex)
            {
                Console.WriteLine(Ex.Message);
                try
                {
                    Type   CATIAType = Type.GetTypeFromProgID(CATIAapp);
                    object CATIAinst = Activator.CreateInstance(CATIAType);
                    myCATIA = CATIAinst as INFITF.Application;
                    Console.WriteLine("CATIA instance created !");
                }
                catch (Exception Ex1)
                {
                    Console.WriteLine("--- CATIA init ERROR:\n" + Ex1.Message);
                    return(false);
                }
            }

            myCATIA.Visible           = false;
            myCATIA.RefreshDisplay    = true;
            myCATIA.DisplayFileAlerts = false;

            return(true);
        }
        /// <summary>
        /// 初始化CATIA环境并获取信息到全局变量
        /// </summary>
        /// <returns></returns>
        private bool InitCatEnv()
        {
            try
            {
                CatApplication = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Catia.Application");
            }
            catch (Exception)
            {
                this.WindowState   = FormWindowState.Normal;
                this.StartPosition = FormStartPosition.CenterScreen;
                MessageBox.Show("未检测到打开的CATIA!,请重新运行CATIA!");
                return(false);
                //throw;
            }
            CatApplication.set_Caption("正在运行瑞祥快速建模工具!");
            // 获取当前活动ProductDocument
            try
            {
                CatDocument = (ProductDocument)CatApplication.ActiveDocument;
            }
            catch (Exception)
            {
                CatDocument = (ProductDocument)CatApplication.Documents.Add("Product");
                try
                {
                    CatDocument.Product.set_PartNumber("RxProduct");
                }
                catch (Exception)
                {
                    MessageBox.Show("未检测到活动Product,正在为您创建,请手动辅助完成!");
                    return(false);
                }
                //MessageBox.Show("未检测到活动Product,已自动为您创建对象!");
            }
            // 添加一个新零件
            string Name = "RXFastDesignTool";

            try
            {
                PartID = ((PartDocument)CatApplication.Documents.Item(Name + ".CATPart")).Part;
            }
            catch (Exception)
            {
                try
                {
                    CatDocument.Product.Products.AddNewComponent("Part", Name);
                }
                catch (Exception)
                {
                    return(false);
                    // throw;
                }
                PartID = ((PartDocument)CatApplication.Documents.Item(Name + ".CATPart")).Part;
            }
            return(true);
        }
 public ControladorCATIA()
 {
     try
     {
         CATIA = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application");
     }
     catch (Exception)
     {
     }
 }
 public CATInterop()
 {
     try {
         CATIA = (INFITF.Application)Microsoft.VisualBasic.Interaction.GetObject(null, "CATIA.Application");
     } catch (Exception) {
         if (System.Windows.Forms.MessageBox.Show("Não foi detectado nenhum CATIA aberto. Pretende Abrir?", "", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) {
             CATIA = (INFITF.Application)Microsoft.VisualBasic.Interaction.CreateObject("CATIA.Application");
         } else {
             Environment.Exit(0);
         }
     }
 }
Exemple #8
0
 /// <summary>
 /// 获取catia实例和激活的Part
 /// </summary>
 /// <returns></returns>
 public static void InitializeCatia()
 {
     try
     {
         catia      = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application");
         activePart = catia.ActiveEditor.ActiveObject as Part;
         //catiaGeometry = new CATGeometry(catia, activePart);
         sel = catia.ActiveEditor.Selection;
     }
     catch (Exception)
     {
     }
 }
 public bool CatiaLauft()
 {
     try
     {
         object co = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application");
         catiaAnwendung = (INFITF.Application)co;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #10
0
 private void buttonInitCatia_Click(object sender, EventArgs e)
 {
     try
     {
         //CATIA=(INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
         CATIA = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Catia.Application");
     }
     catch
     {
         Type oType = System.Type.GetTypeFromProgID("CATIA.Application");
         CATIA         = (INFITF.Application)Activator.CreateInstance(oType);
         CATIA.Visible = true;
     }
 }
Exemple #11
0
 public CATInterop()
 {
     try {
         CATIA = (INFITF.Application)Microsoft.VisualBasic.Interaction.GetObject(null, "CATIA.Application");
     } catch (Exception) {
         if (System.Windows.Forms.MessageBox.Show("Não foi detectado nenhum CATIA aberto. Pretende Abrir?", "", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
         {
             CATIA = (INFITF.Application)Microsoft.VisualBasic.Interaction.CreateObject("CATIA.Application");
         }
         else
         {
             Environment.Exit(0);
         }
     }
 }
 public bool CATIALaeuft()
 {
     try
     {
         object catiaObject = System.Runtime.InteropServices.Marshal.GetActiveObject(
             "CATIA.Application");
         hsp_catiaApp = (INFITF.Application)catiaObject;
         return(true);
     }
     catch (Exception)
     {
         MessageBox.Show("Um die Catia-Erweiterung zu starten, bitte CATIA V5 starten");
         return(false);
     }
 }
 public bool laeuftCatia()
 {
     try
     {
         object co =
             System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application");
         hsp_catiaApp = (INFITF.Application)co;
     }
     catch
     {
         MessageBox.Show("");
         return(false);
     }
     return(true);
 }
Exemple #14
0
        public bool CATIALaeuft()
        {
            try
            {
                //"Abfangen" der Laufenden CATIA
                object catiaObject = System.Runtime.InteropServices.Marshal.GetActiveObject(
                    "CATIA.Application");
                hsp_catiaApp = (INFITF.Application)catiaObject;

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #15
0
        public bool laeuftCatia()
        {
            try
            {
                object co =
                    System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application");
                hsp_catiaApp = (INFITF.Application)co;      // _____________________________________muss geändert werden wegen mehrdeutiger Verweis
                return(true);
            }
            catch
            {
                //MessageBox.Show("");
                return(false);

                //return true;
            }
        }
Exemple #16
0
        /// <summary>
        /// 创建一个工作用的Part 文件
        /// </summary>
        /// <param name="CatApplication">CATIA程序框架</param>
        /// <param name="CatDocument">CATIA 活动文档</param>
        /// <param name="PartID">待创建的CATIA 零件目标</param>
        public void CreatWorkPart(INFITF.Application CatApplication, ProductDocument CatDocument, ref Part PartID)
        {
            // 添加一个新零件
            string Name = "RXFastDesignTool";

            try
            {
                PartID = ((PartDocument)CatApplication.Documents.Item(Name + ".CATPart")).Part;
            }
            catch (Exception)
            {
                try
                {
                    CatDocument.Product.Products.AddNewComponent("Part", Name);
                    PartID = ((PartDocument)CatApplication.Documents.Item(Name + ".CATPart")).Part;
                }
                catch (Exception)
                {
                    return;
                    // throw;
                }
            }
            HybridBodies HBS = PartID.HybridBodies;

            if (HBS.Count < 1)
            {
                HybridBody HB = HBS.Add();
                HB.set_Name("Geometrical Set.1");
            }
            OriginElements Tpart   = PartID.OriginElements;
            AnyObject      dxy     = Tpart.PlaneXY;
            AnyObject      dyz     = Tpart.PlaneYZ;
            AnyObject      dzx     = Tpart.PlaneZX;
            Selection      SelectT = CatDocument.Selection;
            VisPropertySet VP      = SelectT.VisProperties;

            SelectT.Add(dxy);
            SelectT.Add(dyz);
            SelectT.Add(dzx);
            VP = (VisPropertySet)VP.Parent;
            VP.SetShow(CatVisPropertyShow.catVisPropertyNoShowAttr);
            SelectT.Clear();
        }
Exemple #17
0
 // statically defines one active CATIA session
 public static bool engageActiveCatiaSession()
 {
     if (Program.ENGAGE_CATIA_MODE)
     {
         try
         {
             catia = (INFITF.Application)Marshal.GetActiveObject("catia.Application");
             return(true);
         }
         catch (Exception ex)
         {
             Console.WriteLine("Ooops! Exception: " + ex.ToString());
             MessageBox.Show("Could not find an active session! Please launch 3DEXPERIENCE.",
                             "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return(false);
         }
     }
     return(true);
 }
        private bool GetSelect(bool InitFrame)
        {
            this.WindowState = FormWindowState.Minimized;
            try
            {
                CatApplication = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Catia.Application");
            }
            catch (Exception)
            {
                this.WindowState   = FormWindowState.Normal;
                this.StartPosition = FormStartPosition.CenterScreen;
                MessageBox.Show("未检测到打开的CATIA!,请重新运行CATIA!");
                return(false);
                //throw;
            }
            CatApplication.set_Caption("正在运行瑞祥快速建模工具!");
            // 获取当前活动ProductDocument
            try
            {
                CatDocument = (ProductDocument)CatApplication.ActiveDocument;
            }
            catch (Exception)
            {
                CatDocument = (ProductDocument)CatApplication.Documents.Add("Product");
                try
                {
                    CatDocument.Product.set_PartNumber("RxProduct");
                }
                catch (Exception)
                {
                    MessageBox.Show("未检测到活动Product,正在为您创建,请手动辅助完成!");
                    return(false);
                }
                //MessageBox.Show("未检测到活动Product,已自动为您创建对象!");
            }
            // 添加一个新零件
            string Name = "RXFastDesignTool";

            try
            {
                PartID = ((PartDocument)CatApplication.Documents.Item(Name + ".CATPart")).Part;
            }
            catch (Exception)
            {
                try
                {
                    CatDocument.Product.Products.AddNewComponent("Part", Name);
                }
                catch (Exception)
                {
                    return(false);
                    // throw;
                }
                PartID = ((PartDocument)CatApplication.Documents.Item(Name + ".CATPart")).Part;
                OriginElements Tpart   = PartID.OriginElements;
                AnyObject      dxy     = Tpart.PlaneXY;
                AnyObject      dyz     = Tpart.PlaneYZ;
                AnyObject      dzx     = Tpart.PlaneZX;
                Selection      SelectT = CatDocument.Selection;
                VisPropertySet VP      = SelectT.VisProperties;
                SelectT.Add(dxy);
                SelectT.Add(dyz);
                SelectT.Add(dzx);
                VP = (VisPropertySet)VP.Parent;
                VP.SetShow(CatVisPropertyShow.catVisPropertyNoShowAttr);
                SelectT.Clear();
            }
            try
            {
                CatDocument.Product.ApplyWorkMode(CatWorkModeType.DESIGN_MODE);
            }
            catch (Exception)
            {
                Console.WriteLine("Change Design Model Faild!");
            }
            this.WindowState   = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            return(true);
        }
Exemple #19
0
 /// <summary>
 /// 初始化CATIA环境并获取信息到全局变量
 /// </summary>
 /// <param name="CatApplication">CATIA程序框架</param>
 /// <param name="CatDocument">CATIA 活动文档</param>
 /// <param name="PartID">CATIA 零件目标</param>
 /// <param name="form">当前活动窗口</param>
 /// <returns></returns>
 public bool InitCatEnv(ref INFITF.Application CatApplication, ref ProductDocument CatDocument, ref Part PartID, Form form, bool isCatia = true, Label mymessage = null)
 {
     Process[] AllProcess = Process.GetProcessesByName("CNEXT"); //Only When Get CATIA Process
     form.TopMost = false;
     #region MyRegion
     // Process[] AllProcess = Process.GetProcessesByName("Delmia");
     //if (AllProcess.Length > 1)
     //{
     //    try
     //    {
     //        WAPI wAPI = new WAPI();
     //        AllProcess[0].WaitForInputIdle();
     //        string MainWintitle = AllProcess[0].MainWindowTitle;
     //        int MainPID = AllProcess[0].Id;
     //        IntPtr intPtr = AllProcess[0].MainWindowHandle;
     //        IntPtr intPtr2 = WAPI.FindWindow(null, MainWintitle);
     //        // CatApplication = (INFITF.Application)AllProcess[0].CreateObjRef(INFITF.Application);
     //        var application = Marshal.GetObjectForNativeVariant(intPtr);
     //        CatApplication = (INFITF.Application)application;
     //        string CapName1 = CatApplication.get_Caption();
     //        CatApplication.set_Caption("正在运行锐锋快速建模工具!锐锋快捷设计中心 BY_安徽锐锋科技【工厂仿真组】叶朝成");
     //        AllProcess[1].WaitForInputIdle();
     //        IntPtr ProgHandle = AllProcess[1].Handle;
     //        //CatApplication = (INFITF.Application)Marshal.GetObjectForNativeVariant(ProgId);
     //        string CapName2 = CatApplication.get_Caption();
     //        //MessageBox.Show("当前打开超过1个CATIA,可能操控的CATIA非您需要的对象,请核实!");
     //        //GetObj(1, "Catia.Application");
     //        //GetObj(2, "Delmia.Application");
     //        // IntPtr Ptr = AllProcess[2].MainWindowHandle;
     //        // string Pname = AllProcess[2].MainWindowTitle;
     //        //  int progid=  AllProcess[2].;
     //        // object Pobj = Marshal.GetActiveObject("Delmia.Application");
     //        //// object Tobj = Marshal.GetObjectForIUnknown(ptr2);
     //        // object Pobj0 = Marshal.GetActiveObject(progid.ToString());
     //        // DSApplication = (INFITF.Application)Pobj;
     //        // String tn = DSApplication.get_Caption();
     //    }
     //    catch (Exception)
     //    {
     //        throw;
     //    }
     //}
     #endregion
     try
     {
         if (isCatia)
         {
             CatApplication = (INFITF.Application)Marshal.GetActiveObject("Catia.Application");
             if (mymessage != null)
             {
                 mymessage.Text = "已建立CATIA通信!";
             }
         }
         else
         {
             CatApplication = (INFITF.Application)Marshal.GetActiveObject("Delmia.Application");
             if (mymessage != null)
             {
                 mymessage.Text = "已建立Delmia通信!";
             }
         }
     }
     catch (Exception)
     {
         form.WindowState   = FormWindowState.Normal;
         form.StartPosition = FormStartPosition.CenterScreen;
         //MessageBox.Show("未检测到打开的CATIA!,请重新运行CATIA!");
         if (mymessage != null)
         {
             mymessage.Text = "通信建立失败,所有功能将会失效请重新尝试或重新启动该软件!";
         }
         return(false);
         //throw;
     }
     try
     {
         CatApplication.set_Caption("正在运行锐锋快速建模工具!锐锋快捷设计中心 BY_安徽锐锋科技【工厂仿真组】叶朝成");
     }
     catch (Exception)
     {
         throw;
     }
     // 获取当前活动ProductDocument
     try
     {
         CatDocument = (ProductDocument)CatApplication.ActiveDocument;
     }
     catch (Exception)
     {
         CatDocument = (ProductDocument)CatApplication.Documents.Add("Product");
         try
         {
             CatDocument.Product.set_PartNumber("RxProduct");
         }
         catch (Exception)
         {
             MessageBox.Show("未检测到活动Product,正在为您创建,请手动辅助完成!");
             return(false);
         }
         //MessageBox.Show("未检测到活动Product,已自动为您创建对象!");
     }
     try
     {
         CatDocument.Product.ApplyWorkMode(CatWorkModeType.DESIGN_MODE);
     }
     catch (Exception)
     {
         Console.WriteLine("Change Design Model Faild!");
     }
     Selection selection = CatDocument.Selection;
     selection.Clear();
     CreatWorkPart(CatApplication, CatDocument, ref PartID); //Get New Part For Work
     return(true);
 }
        /// <summary>
        /// 连接CATIA COM 并获得选择集
        /// </summary>
        /// <returns></returns>
        private Selection GetSelect()
        {
            this.WindowState = FormWindowState.Minimized;
            try
            {
                CatApplication = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Catia.Application");
            }
            catch (Exception)
            {
                this.WindowState   = FormWindowState.Normal;
                this.StartPosition = FormStartPosition.CenterScreen;
                MessageBox.Show("未检测到打开的CATIA!,请重新运行CATIA!");
                return(null);
            }
            CatApplication.set_Caption("正在运行瑞祥快速建模工具!");
            // 获取当前活动ProductDocument
            try
            {
                CatDocument = (ProductDocument)CatApplication.ActiveDocument;
            }
            catch (Exception)
            {
                CatDocument = (ProductDocument)CatApplication.Documents.Add("Product");
                try
                {
                    CatDocument.Product.set_PartNumber("RxProduct");
                }
                catch (Exception)
                {
                    MessageBox.Show("未检测到活动Product,正在为您创建,请手动辅助完成!");
                    return(null);
                }
                //MessageBox.Show("未检测到活动Product,已自动为您创建对象!");
            }
            // 添加一个新零件
            string Name = "RXFastDesignTool";

            try
            {
                //PartID = ((PartDocument)CatApplication.Documents.Item(Name + ".CATPart")).Part;
                //PartID = ((PartDocument)CatApplication.Documents.Item(Name)).Part;
                Selection FindPart = CatApplication.ActiveDocument.Selection;
                FindPart.Search("Name=RXFastDesignTool,all");
                if (FindPart.Count2 > 0)
                {
                    PartID = (Part)FindPart.Item2(1).Value; //仅拾取带个并对第一个进行操作
                }
                else
                {
                    try
                    {
                        CatDocument.Product.Products.AddNewComponent("Part", Name);
                    }
                    catch (Exception)
                    {
                        return(null);
                        // throw;
                    }
                    PartID = ((PartDocument)CatApplication.Documents.Item(Name + ".CATPart")).Part;
                    OriginElements Tpart   = PartID.OriginElements;
                    AnyObject      dxy     = Tpart.PlaneXY;
                    AnyObject      dyz     = Tpart.PlaneYZ;
                    AnyObject      dzx     = Tpart.PlaneZX;
                    Selection      SelectT = CatDocument.Selection;
                    VisPropertySet VP      = SelectT.VisProperties;
                    SelectT.Add(dxy);
                    SelectT.Add(dyz);
                    SelectT.Add(dzx);
                    VP = (VisPropertySet)VP.Parent;
                    VP.SetShow(CatVisPropertyShow.catVisPropertyNoShowAttr);
                    SelectT.Clear();
                }
            }
            catch (Exception)
            {
                return(null);
            }
            try
            {
                CatDocument.Product.ApplyWorkMode(CatWorkModeType.DESIGN_MODE);
            }
            catch (Exception)
            {
                Console.WriteLine("Change Design Model Faild!");
            }
            Selection SelectArc = CatDocument.Selection;

            SelectArc.Clear();
            var Result = SelectArc.SelectElement3(InputObjectType(), "请选择曲面", true, CATMultiSelectionMode.CATMultiSelTriggWhenSelPerf, false);

            if (Result == "Cancel")
            {
                return(null);
            }
            if (SelectArc.Count < 1)
            {
                MessageBox.Show("请先选择对象后再点此命令!");
                return(null);
            }
            this.WindowState   = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            return(SelectArc);
        }