Пример #1
0
        static void Main(string[] args)
        {
            /*
             * StreamReader sr = new StreamReader("point.txt");
             * String line = "";
             * List<Pt> ptlist = new List<Pt>();
             *
             * while ((line = sr.ReadLine()) != null)
             * {
             *  string[] token = line.Split(',');
             *  int x = int.Parse(token[0]);
             *  int y = int.Parse(token[1]);
             *  int z = int.Parse(token[2]);
             *  ptlist.Add(new Pt(x,y,z));
             * }
             */
            INFITF.Application catia;
            try
            {
                catia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
            }
            catch (Exception)
            {
                catia = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application"));
            }
            catia.Visible = true;

            PartDocument prtdoc = (PartDocument)catia.Documents.Add("Part");
            Part         prt    = prtdoc.Part;

            HybridBodies       hbdys = prt.HybridBodies;
            HybridBody         hbdy  = hbdys.Add();
            HybridShapeFactory hsFac = (HybridShapeFactory)prt.HybridShapeFactory;

            try
            {
                StreamReader sr = new StreamReader("C:/Users/517-11/Desktop/saori/Automation/Catia-v5-Automation/RecapEx/point.txt");

                String line = "";
                //List<Pt> ptlist = new List<Pt>();
                while ((line = sr.ReadLine()) != null)
                {
                    string[] token = line.Split(',');
                    int      x     = int.Parse(token[0]);
                    int      y     = int.Parse(token[1]);
                    int      z     = int.Parse(token[2]);
                    // ptlist.Add(new Pt(x, y, z));
                    Point p = hsFac.AddNewPointCoord(x, y, z);
                    hbdy.AppendHybridShape(p);
                }
                //Point p1 = hsFac.AddNewPointCoord(10, 60, 30);
                sr.Close();

                prt.Update();
            }
            catch (Exception e)
            {
                Console.WriteLine("파일io오류:" + e.Message);
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //List<Pnt> pList = new List<Pnt>();
            List <HybridShapeTypeLib.Point> pList = new List <HybridShapeTypeLib.Point>();

            //prtDoc = (PartDocument)catia.Documents.Item(1);
            prtDoc = (PartDocument)catia.Documents.Add("Part");

            Part         prt   = prtDoc.Part;
            HybridBodies hbdys = prt.HybridBodies;
            HybridBody   hbdy  = hbdys.Add();

            hbdy.set_Name("saori");
            HybridShapeFactory hsFac = (HybridShapeFactory)prt.HybridShapeFactory;

            //string Line = textBox1.Text;
            string lin = "";

            if (textBox1.Text == "")
            {
                MessageBox.Show("좌표를 입력해주새요");
                return;
            }

            for (int i = 0; i < textBox1.Lines.Length; i++)
            {
                lin = textBox1.Lines[i];
                string[] token = lin.Split(',');
                int      x     = int.Parse(token[0]);
                int      y     = int.Parse(token[1]);
                int      z     = int.Parse(token[2]);
                // pList.Add(new Pnt(x, y, z));
                pList.Add(hsFac.AddNewPointCoord(x, y, z));
                HybridShapeTypeLib.Point p = hsFac.AddNewPointCoord(x, y, z); //create a point
                hbdy.AppendHybridShape(p);
            }
            //create points and spline
            HybridShapeSpline splin = hsFac.AddNewSpline();

            foreach (HybridShapeTypeLib.Point p in pList)
            {
                INFITF.Reference r = prt.CreateReferenceFromGeometry(p);
                // hsFac.AddNewPointDatum(r);
                //hbdy.AppendHybridShape(p);
                splin.AddPoint(r);
            }
            hbdy.AppendHybridShape(splin);
            prt.Update();
        }
Пример #3
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();
        }
        static void Main(string[] args)
        {
            INFITF.Application catia; //add the reference - catia v5 infiit interface...

            try
            {
                //열려 있는 catia가져오기
                catia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
            }
            catch (Exception)
            {
                //catia 실행하기
                catia         = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application"));
                catia.Visible = true;
            }

            MECMOD.PartDocument prtDoc = (MECMOD.PartDocument)catia.Documents.Add("Part");
            MECMOD.Part         prt    = prtDoc.Part;

            HybridBodies hybdys = prt.HybridBodies;
            HybridBody   hybdy  = hybdys.Add();
            HybridShapes hyshps = hybdy.HybridShapes;

            HybridShapeFactory hyshfac = (HybridShapeFactory)prt.HybridShapeFactory;

            Point p1 = hyshfac.AddNewPointCoord(10, 60, 30);
            Point p2 = hyshfac.AddNewPointCoord(70, 75, 35);
            Point p3 = hyshfac.AddNewPointCoord(100, 80, 30);

            Point p4 = hyshfac.AddNewPointCoord(100, 80, 40);
            Point p5 = hyshfac.AddNewPointCoord(95, 20, 45);
            Point p6 = hyshfac.AddNewPointCoord(100, 10, 50);

            INFITF.Reference r1 = prt.CreateReferenceFromGeometry(p1);
            INFITF.Reference r2 = prt.CreateReferenceFromGeometry(p2);
            INFITF.Reference r3 = prt.CreateReferenceFromGeometry(p3);
            INFITF.Reference r4 = prt.CreateReferenceFromGeometry(p4);
            INFITF.Reference r5 = prt.CreateReferenceFromGeometry(p5);
            INFITF.Reference r6 = prt.CreateReferenceFromGeometry(p6);

            HybridShapeSpline hyspl1 = hyshfac.AddNewSpline();
            HybridShapeSpline hyspl2 = hyshfac.AddNewSpline();


            hyspl1.AddPoint(r1);
            hyspl1.AddPoint(r2);
            hyspl1.AddPoint(r3);

            hyspl2.AddPoint(r4);
            hyspl2.AddPoint(r5);
            hyspl2.AddPoint(r6);

            hybdy.AppendHybridShape(hyspl1);
            hybdy.AppendHybridShape(hyspl2); //AppendHybridShape 만들고 바로 해야 된다

            INFITF.Reference rspl1 = prt.CreateReferenceFromGeometry(hyspl1);
            INFITF.Reference rspl2 = prt.CreateReferenceFromGeometry(hyspl2);

            HybridShapeSweepExplicit swp = hyshfac.AddNewSweepExplicit(rspl1, rspl2);

            hybdy.AppendHybridShape(swp);

            Point p = hyshfac.AddNewPointCoord(50, 30, 100);

            hybdy.AppendHybridShape(p);

            HybridShapeProject hsprjct = hyshfac.AddNewProject((INFITF.Reference)p, (INFITF.Reference)swp);



            prt.Update();
        }
Пример #5
0
        private void Creat3dPoint_Click(object sender, EventArgs e)//Creat3dBall_Click
        {
            DataGrid.AllowUserToAddRows = false;
            Creat3dPoint.BackColor      = SystemColors.ActiveCaption;
            ReadType = 2;
            if (PartID == null)
            {
                MessageBox.Show("仿真环境未初始化!请先用工具栏初始化命令初始化运行环境!");
                return;
            }
            int ERR = 0;

            if (DataGrid.RowCount < 1)
            {
                MessageBox.Show("数据为空,无法建立3D模型!");
                return;
            }
            HybridBodies Hybs = PartID.HybridBodies;
            //HybridBody Hyb = Hybs.Item(1);
            HybridBody Hyb = Hybs.Add();

            for (int i = 0; i < DataGrid.RowCount; i++)
            {
                HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory;
                //SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench");
                //Reference referenceObject = SelectArc.Item(i).Reference;
                //Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject);
                //TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标
                string TName;
                try
                {
                    TName = DataGrid.Rows[i].Cells[1].Value.ToString(); //读取选择的曲面名称
                }
                catch (Exception)
                {
                    continue;
                }
                HybridShapePointCoord NewPoint = PartHyb.AddNewPointCoord(Convert.ToDouble(DataGrid.Rows[i].Cells[2].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[3].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[4].Value.ToString()));
                if (KeepName.Checked)
                {
                    NewPoint.set_Name(TName);
                }
                else
                {
                    NewPoint.set_Name("Rx_" + (i + 1));
                }
                Hyb.AppendHybridShape(NewPoint);
                PartID.InWorkObject = NewPoint;
                try
                {
                    PartID.Update();
                }
                catch (Exception)
                {
                    ERR += 1;
                }
            }
            if (ERR > 0)
            {
                MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!");
            }
            Creat3dPoint.BackColor = Color.Green;
            ShowCenter();
        }
Пример #6
0
        //子线程中
        private void Creat3dBall_Click(object sender, EventArgs e)//Creat3dPoint_Click
        {
            progressBar.Value           = 0;
            DataGrid.AllowUserToAddRows = false;
            if (PartID == null)
            {
                MessageBox.Show("仿真环境未初始化!请先用工具栏初始化命令初始化运行环境!");
                return;
            }
            Creat3dBall.BackColor = SystemColors.ActiveCaption;
            ReadType = 2;
            int ERR = 0;

            if (DataGrid.RowCount < 1)
            {
                MessageBox.Show("数据为空,无法建立3D模型!");
                return;
            }
            HybridBodies Hybs = PartID.HybridBodies;
            HybridBody   Hyb  = null;

            //try
            //{
            //    Hyb = Hybs.Item("几何图形集.1");
            //}
            //catch (Exception)
            //{
            //    Hyb = Hybs.Item("Geometrical Set.1");
            //}
            progressBar.Maximum = DataGrid.RowCount;
            progressBar.Step    = 1;
            Hyb = Hybs.Add();
            for (int i = 0; i < DataGrid.RowCount; i++)
            {
                progressBar.PerformStep();
                HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory;
                //SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench");
                //Reference referenceObject = SelectArc.Item(i).Reference;
                //Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject);
                //TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标
                string TName;
                try
                {
                    TName = DataGrid.Rows[i].Cells[1].Value.ToString(); //读取选择的曲面名称
                }
                catch (Exception)
                {
                    continue;
                }
                HybridShapePointCoord NewPoint = PartHyb.AddNewPointCoord(Convert.ToDouble(DataGrid.Rows[i].Cells[2].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[3].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[4].Value.ToString()));
                Reference             ShapeRef = PartID.CreateReferenceFromObject(NewPoint);
                HybridShapeSphere     NewShape = PartHyb.AddNewSphere(ShapeRef, null, Convert.ToDouble(BallRadio.Text), -45.000000, 45.000000, 0.000000, 180.000000);
                NewShape.Limitation = 1;
                if (KeepName.Checked)
                {
                    NewPoint.set_Name(TName);
                    NewShape.set_Name(TName);
                }
                else
                {
                    NewPoint.set_Name("Rx_" + (i + 1));
                    NewShape.set_Name("Rx_" + (i + 1));
                }
                // Hyb.AppendHybridShape(NewPoint);
                Hyb.AppendHybridShape(NewShape);
                //  PartID.InWorkObject = NewPoint;
                PartID.InWorkObject = NewShape;
                try
                {
                    PartID.Update();
                }
                catch (Exception)
                {
                    ERR += 1;
                }
                Selection      SetColor = CatDocument.Selection;
                VisPropertySet VSet     = SetColor.VisProperties;
                SetColor.Add(NewShape);
                VSet.SetRealColor(128, 255, 0, 0);
                SetColor.Clear();
            }
            if (ERR > 0)
            {
                MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!");
            }
            Creat3dBall.BackColor = Color.Green;
            ShowCenter();
            progressBar.Value = DataGrid.RowCount;
        }
Пример #7
0
        static void Main(string[] args)
        {
            INFITF.Application catia;
            try
            {
                catia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
            }
            catch (Exception)
            {
                catia = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application"));
            }
            catia.Visible = true;

            PartDocument prtdoc = (PartDocument)catia.Documents.Add("Part");
            Part         prt    = prtdoc.Part;

            HybridBodies       hbdys = prt.HybridBodies;
            HybridBody         hbdy  = hbdys.Add();
            HybridShapeFactory hsFac = (HybridShapeFactory)prt.HybridShapeFactory;

            Point p1 = hsFac.AddNewPointCoord(10, 60, 30);
            Point p2 = hsFac.AddNewPointCoord(70, 75, 35);
            Point p3 = hsFac.AddNewPointCoord(100, 80, 30);
            Point p4 = hsFac.AddNewPointCoord(100, 80, 40);
            Point p5 = hsFac.AddNewPointCoord(95, 20, 45);
            Point p6 = hsFac.AddNewPointCoord(100, 10, 50);

            INFITF.Reference r1 = prt.CreateReferenceFromGeometry(p1);
            INFITF.Reference r2 = prt.CreateReferenceFromGeometry(p2);
            INFITF.Reference r3 = prt.CreateReferenceFromGeometry(p3);
            INFITF.Reference r4 = prt.CreateReferenceFromGeometry(p4);
            INFITF.Reference r5 = prt.CreateReferenceFromGeometry(p5);
            INFITF.Reference r6 = prt.CreateReferenceFromGeometry(p6);

            HybridShapeSpline hspln1 = hsFac.AddNewSpline();
            HybridShapeSpline hspln2 = hsFac.AddNewSpline();

            hspln1.AddPoint(r1);
            hspln1.AddPoint(r2);
            hspln1.AddPoint(r3);

            hspln2.AddPoint(r4);
            hspln2.AddPoint(r5);
            hspln2.AddPoint(r6);

            hbdy.AppendHybridShape(hspln1);
            hbdy.AppendHybridShape(hspln2);

            INFITF.Reference rspl1 = prt.CreateReferenceFromGeometry(hspln1);
            INFITF.Reference rspl2 = prt.CreateReferenceFromGeometry(hspln2);

            HybridShapeSweepExplicit swp = hsFac.AddNewSweepExplicit(rspl1, rspl2);

            hbdy.AppendHybridShape(swp);

            Point p = hsFac.AddNewPointCoord(50, 30, 100);

            hbdy.AppendHybridShape(p);
            HybridShapeProject prjct = hsFac.AddNewProject((INFITF.Reference)p, (INFITF.Reference)swp);

            hbdy.AppendHybridShape(prjct);

            prt.Update();
        }