Example #1
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();
        }
Example #2
0
        /// <summary>
        /// 隐藏孔创建的草图并修改孔颜色
        /// </summary>
        /// <param name="Thole">目标孔</param>
        private void ChangeHoleColor(Hole Thole, RxHoleType HoleType)
        {
            //隐藏孔创建的草图并修改孔颜色
            Selection HoleSelection = CatActiveDoc.Selection;

            HoleSelection.Clear();
            VisPropertySet HoleSet    = HoleSelection.VisProperties;
            Sketch         HoleSketch = Thole.Sketch;

            HoleSelection.Add(HoleSketch);
            HoleSet.SetShow(CatVisPropertyShow.catVisPropertyNoShowAttr);
            HoleSelection.Clear();
            HoleSelection.Add(Thole);
            switch (HoleType)
            {
            case RxHoleType.PinHole:     //销孔
                HoleSet.SetVisibleColor(251, 146, 248, 0);
                break;

            case RxHoleType.NSmoothHole:     //光孔
                HoleSet.SetVisibleColor(167, 230, 182, 0);
                break;

            case RxHoleType.ISmoothHole:     //沉头孔
                HoleSet.SetVisibleColor(167, 230, 182, 0);
                break;

            case RxHoleType.ThreadHole:     //螺纹孔
                HoleSet.SetVisibleColor(128, 0, 255, 0);
                break;

            default:
                break;
            }
            HoleSelection.Clear();
        }
Example #3
0
        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);
        }
Example #4
0
        /// <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);
        }