コード例 #1
0
        // create lines
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                prtDoc = (PartDocument)catia.ActiveDocument;
                Part prt = prtDoc.Part;
                hbdy = prt.HybridBodies.Item(1);
                HybridShapeFactory hfac = (HybridShapeFactory)prt.HybridShapeFactory;
                //SelGS = (HybridBody)Sel.Item(1).Value;

                //INFITF.AnyObject aaa = Pts[0];
                for (int i = 0; i <= (Pts.Count - 1); i++)
                {
                    for (int j = i + 1; j < Pts.Count; j++)
                    {
                        HybridShapeTypeLib.Point pt1 = (HybridShapeTypeLib.Point)Pts.ElementAt(i);
                        HybridShapeTypeLib.Point pt2 = (HybridShapeTypeLib.Point)Pts.ElementAt(j);

                        INFITF.Reference ref1 = prt.CreateReferenceFromGeometry(pt1);
                        INFITF.Reference ref2 = prt.CreateReferenceFromGeometry(pt2);

                        HybridShapeTypeLib.Line lin = hfac.AddNewLinePtPt(ref1, ref2);
                        hbdy.AppendHybridShape(lin);
                    }
                }
                prt.Update();
            }
            catch (Exception)
            {
                MessageBox.Show("선택된 정보가 없습니다.");
                return;
            }
        }
コード例 #2
0
        //create3Dline--------------------------------------------
        private void button5_Click(object sender, EventArgs e)
        {
            // object[] HpCrd1 = new object[3];
            // object[] HpCrd2 = new object[3];

            try
            {
                sel           = catia.ActiveDocument.Selection;
                HyShpPtCoord1 = (HybridShapeTypeLib.Point)sel.FindObject("CATIAHybridShapePoint");
                //sel = catia.ActiveDocument.Selection;
                HyShpPtCoord2 = (HybridShapeTypeLib.Point)sel.FindObject("CATIAHybridShapePoint");

                //HyShpPtCoord1.GetCoordinates(HpCrd1);
                //HyShpPtCoord1.GetCoordinates(HpCrd2);

                PartDocument       prtDoc = (PartDocument)catia.ActiveDocument;
                Part               prt    = prtDoc.Part;
                HybridBody         hbdy   = prt.HybridBodies.Item(1);
                HybridShapeFactory hfac   = (HybridShapeFactory)prt.HybridShapeFactory;

                INFITF.Reference ref1 = prt.CreateReferenceFromGeometry(HyShpPtCoord1);
                INFITF.Reference ref2 = prt.CreateReferenceFromGeometry(HyShpPtCoord2);

                HybridShapeTypeLib.Line lin = hfac.AddNewLinePtPt(ref1, ref2);
                hbdy.AppendHybridShape(lin);

                prt.Update();
            }
            catch (Exception)
            {
                MessageBox.Show("선택된 정보가 없습니다.");
                return;
            }
        }
コード例 #3
0
 public NodePoint(string name, double Xpos, double Ypos, double Zpos, HybridShapeTypeLib.Point LinkToPoint)
 {
     Name = name;
     X    = Xpos;
     Y    = Ypos;
     Z    = Zpos;
     link = LinkToPoint;
 }
コード例 #4
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();
        }
コード例 #5
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (catia == null)
            {
                MessageBox.Show("Please run CATIA");
                return;
            }

            try
            {
                drwDoc = (DRAFTINGITF.DrawingDocument)catia.ActiveDocument;
            }
            catch (Exception)
            {
                MessageBox.Show("please open a document.");
                return;
            }

            DRAFTINGITF.DrawingRoot DrwRoot = drwDoc.DrawingRoot;

            try
            {
                DrwView = DrwRoot.ActiveSheet.Views.Item(DrwRoot.ActiveSheet.Views.Count);
            }
            catch (Exception)
            {
                MessageBox.Show("sheet가 없습니다.");
                return;
            }
            DRAFTINGITF.DrawingViewGenerativeBehavior DrwGenBeh = DrwView.GenerativeBehavior;

            ////7.point txt, leader생성
            //CreateTxt(DrwGenBeh, pt1, DrwView);
            //CreateTxt(DrwGenBeh, pt2, DrwView);
            //CreateTxt(DrwGenBeh, pt3, DrwView);

            double X1, Y1, Z1, X2, Y2, Z2;

            DrwGenBeh.GetProjectionPlane(out X1, out Y1, out Z1, out X2, out Y2, out Z2);


            //MECMOD.Body Bdy = Prt.MainBody;
            //MECMOD.Shapes Shps = Bdy.Shapes;

            //7.point txt, leader생성
            // CreateTxt(DrwGenBeh, X1, Y1, Z1, X2, Y2, Z2, pt1, DrwView);
            // CreateTxt(X1, Y1, Z1, X2, Y2, Z2, pt2, DrwView);
            // CreateTxt(X1, Y1, Z1, X2, Y2, Z2, pt3, DrwView);

            object[] ap1 = new object[3];
            object[] ap2 = new object[3];
            object[] ap3 = new object[3];

            pt1.GetCoordinates(ap1);
            pt2.GetCoordinates(ap2);
            pt3.GetCoordinates(ap3);

            //pt1---
            double X = (double)ap1[0];
            double Y = (double)ap1[1];
            double Z = (double)ap1[2];

            double COS_ALPHA = 0, VW_H = 0, VW_V = 0;

            /*
             * COS_ALPHA = (X * X1 + Y * Y1 + Z * Z1) / ((Math.Pow(X1, 2) + Math.Pow(Y1, 2) + Math.Pow(Z1, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
             * VW_H = Math.Sqrt(X * X + Y * Y + Z * Z) * COS_ALPHA;
             *
             * COS_ALPHA = (X * X2 + Y * Y2 + Z * Z2) / ((Math.Pow(X2, 2) + Math.Pow(Y2, 2) + Math.Pow(Z2, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
             * VW_V = Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)) * COS_ALPHA;
             */
            MECMOD.Factory2D fac = DrwView.Factory2D;
            VW_H = 0;
            VW_V = 0;

            fac.CreatePoint(VW_H, VW_V);

            DRAFTINGITF.DrawingText txt = DrwView.Texts.Add(pt1.get_Name() + "( " + (int)X + " , " + (int)Y + " , " + (int)Z + " )", VW_H + 20, VW_V - 20);
            txt.SetFontSize(0, 0, 12);

            DRAFTINGITF.DrawingLeader FDleadr = txt.Leaders.Add(VW_H, VW_V);

            //pt2---
            X = (double)ap2[0];
            Y = (double)ap2[1];
            Z = (double)ap2[2];

            COS_ALPHA = (X * X1 + Y * Y1 + Z * Z1) / ((Math.Pow(X1, 2) + Math.Pow(Y1, 2) + Math.Pow(Z1, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_H      = Math.Sqrt(X * X + Y * Y + Z * Z) * COS_ALPHA;

            COS_ALPHA = (X * X2 + Y * Y2 + Z * Z2) / ((Math.Pow(X2, 2) + Math.Pow(Y2, 2) + Math.Pow(Z2, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_V      = Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)) * COS_ALPHA;

            fac = DrwView.Factory2D;
            fac.CreatePoint(VW_H, VW_V);

            txt = DrwView.Texts.Add(pt2.get_Name() + "( " + (int)X + " , " + (int)Y + " , " + (int)Z + " )", VW_H + 20, VW_V - 20);
            txt.SetFontSize(0, 0, 12);

            FDleadr = txt.Leaders.Add(VW_H, VW_V);

            //pt3---
            X = (double)ap3[0];
            Y = (double)ap3[1];
            Z = (double)ap3[2];

            COS_ALPHA = (X * X1 + Y * Y1 + Z * Z1) / ((Math.Pow(X1, 2) + Math.Pow(Y1, 2) + Math.Pow(Z1, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_H      = Math.Sqrt(X * X + Y * Y + Z * Z) * COS_ALPHA;

            COS_ALPHA = (X * X2 + Y * Y2 + Z * Z2) / ((Math.Pow(X2, 2) + Math.Pow(Y2, 2) + Math.Pow(Z2, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_V      = Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)) * COS_ALPHA;

            fac = DrwView.Factory2D;
            fac.CreatePoint(VW_H, VW_V);

            txt = DrwView.Texts.Add(pt3.get_Name() + "( " + (int)X + " , " + (int)Y + " , " + (int)Z + " )", VW_H + 20, VW_V - 20);
            txt.SetFontSize(0, 0, 12);

            FDleadr = txt.Leaders.Add(VW_H, VW_V);

            //pt_A----
            ProductStructureTypeLib.Product Prd    = (ProductStructureTypeLib.Product)DrwGenBeh.Document;
            MECMOD.PartDocument             PrtDoc = (MECMOD.PartDocument)Prd.ReferenceProduct.Parent;
            MECMOD.Part Prt = PrtDoc.Part;

            MECMOD.HybridBody bs = Prt.HybridBodies.Item("forTestGS").HybridBodies.Item("Base");

            HybridShapeTypeLib.Point ptA = (HybridShapeTypeLib.Point)bs.HybridShapes.GetItem("PT-A");
            object[] aa = new object[3];
            ptA.GetCoordinates(aa);
            X = (double)aa[0];
            Y = (double)aa[1];
            Z = (double)aa[2];

            COS_ALPHA = (X * X1 + Y * Y1 + Z * Z1) / ((Math.Pow(X1, 2) + Math.Pow(Y1, 2) + Math.Pow(Z1, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_H      = Math.Sqrt(X * X + Y * Y + Z * Z) * COS_ALPHA;

            COS_ALPHA = (X * X2 + Y * Y2 + Z * Z2) / ((Math.Pow(X2, 2) + Math.Pow(Y2, 2) + Math.Pow(Z2, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_V      = Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)) * COS_ALPHA;

            fac = DrwView.Factory2D;
            fac.CreatePoint(VW_H, VW_V);

            txt = DrwView.Texts.Add(ptA.get_Name() + "( " + (int)X + " , " + (int)Y + " , " + (int)Z + " )", VW_H - 20, VW_V + 40);
            txt.SetFontSize(0, 0, 12);

            FDleadr = txt.Leaders.Add(VW_H, VW_V);
            //------
            //table 생성

            List <HybridShapeTypeLib.Point> list = new List <HybridShapeTypeLib.Point>();

            list.Add(pt1);
            list.Add(pt2);
            list.Add(pt3);

            int col = 4;
            int row = 5;

            DRAFTINGITF.DrawingTable table = DrwView.Tables.Add(200, 200, row, col, 36, 80);

            table.SetCellString(1, 1, "Name");
            table.SetCellString(1, 2, "X");
            table.SetCellString(1, 3, "Y");
            table.SetCellString(1, 4, "Z");

            int ii = 2;

            foreach (HybridShapeTypeLib.Point p in list)
            {
                object[] ap = new object[3];
                p.GetCoordinates(ap);

                table.SetCellString(ii, 1, p.get_Name());
                table.SetCellString(ii, 2, ap[0] + "");
                table.SetCellString(ii, 3, ap[1] + "");
                table.SetCellString(ii, 4, ap[2] + "");
                ii++;
            }

            table.SetCellString(5, 1, ptA.get_Name());
            table.SetCellString(5, 2, aa[0] + "");
            table.SetCellString(5, 3, aa[1] + "");
            table.SetCellString(5, 4, aa[2] + "");

            //table txt stayle 변경---
            for (int i = 1; i <= row; i++)
            {
                for (int j = 1; j <= col; j++)
                {
                    table.GetCellObject(i, j).SetFontSize(0, 0, 14);
                    table.GetCellObject(i, j).TextProperties.Justification = CatJustification.catCenter;
                }
            }


            drwDoc.Update();

            //8.save the 도면 파일
            drwDoc.Save();
        }