private void GetSubPrd(ProductStructureTypeLib.Product Prd)
        {
            string PrtNum = Prd.get_PartNumber();

            INFITF.Document Doc      = (INFITF.Document)Prd.ReferenceProduct.Parent;
            string          FullPath = Doc.FullName;

            SPATypeLib.SPAWorkbench SPAWB;
            SPAWB = (SPATypeLib.SPAWorkbench)Doc.GetWorkbench("SPAWorkbench");
            SPATypeLib.Measurable Mea = SPAWB.GetMeasurable((INFITF.Reference)Prd);
            double Vol;

            try
            {
                Vol = Mea.Volume;
            }
            catch
            {
                Vol = 0;
            }


            textBox1.Text += Level.ToString() + "." + PrtNum + "." + FullPath + "\r\n";


            for (int i = 1; i <= Prd.Products.Count; i++)
            {
                ProductStructureTypeLib.Product tPrd = Prd.Products.Item(i);
                Level++;
                GetSubPrd(tPrd);
                Level--;
            }
        }
Exemple #2
0
 public void UninitializeCATIA()
 {
     /*
      *  어셈블리 특화 함수 구현
      */
     cProduct    = null;
     cProducts   = null;
     cProductDoc = null;
 }
Exemple #3
0
        //// CATIA 관련 함수
        public bool InitializeCATIA(string filePath, int mode)
        {
            /*
             *  어셈블리 특화 함수 구현
             */

            try
            {
                cApp = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
            }
            catch
            {
                cApp = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application"));
            }

            if (cApp == null)
            {
                return(false);
            }

            cDocs = cApp.Documents;

            if (mode == 0)
            {
                cProductDoc = (ProductStructureTypeLib.ProductDocument)cDocs.Read(filePath); //CATProduct read
            }
            //cProductDoc = null;
            else if (mode == 1)
            {
                cProductDoc = (ProductStructureTypeLib.ProductDocument)cDocs.Add("Product"); //new CATProduct 생성
            }
            cApp.Visible = true;

            cProduct  = cProductDoc.Product;
            cProducts = cProduct.Products;

            cConstraints = (MECMOD.Constraints)cProduct.Connections("CATIAConstraints");

            return(true);
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            DRAFTINGITF.DrawingDocument DrwDoc  = null;
            DRAFTINGITF.DrawingView     DrwView = null;

            try
            {
                DrwDoc = (DRAFTINGITF.DrawingDocument)catia.ActiveDocument;
            }
            catch (Exception)
            {
                MessageBox.Show("please open a DrawingDocument");
                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;

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

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

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

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

            PARTITF.Hole tHole = (PARTITF.Hole)Shps.GetItem("Hole.1");
            object[]     opt   = new object[3];
            tHole.GetOrigin(opt);
            //radiuse
            //tHole.

            //3D 위치 값
            // double X = -37.935, Y = 96.8, Z = 104.207;
            double X = (double)opt[0];
            double Y = (double)opt[1];
            double Z = (double)opt[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;

            //create the point
            MECMOD.Factory2D fac = DrwView.Factory2D;
            fac.CreatePoint(VW_H, VW_V);

            //add a text (20정도 뛰어보자)

            DRAFTINGITF.DrawingText txt = DrwView.Texts.Add("Hole( " + (int)X + " , " + (int)Y + " , " + (int)Z + " )", VW_H + 20, VW_V - 20);
            // DRAFTINGITF.DrawingText txt = DrwView.Texts.Add(("( {0} , {1} , {2} )"X,Y,Z), VW_H + 20, VW_V - 20);
            txt.SetFontSize(0, 0, 12);

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

            //update the drawing document.
            DrwDoc.Update();
        }
        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();
        }
Exemple #6
0
        internal void Zeichnungsableitung(Schraube arr, int bestellnummer, string[] kundendaten)
        {
            #region Erste Ansicht einfügen
            //Neues Dokument aus Vorlage erstellen
            Documents dokuments1 = hsp_catiaApp.Documents;
            string    pfad       = System.IO.Path.GetFullPath("Vorlage_HSP_Drawing.CATDrawing");
            //DrawingDocument drawingDokument1 = (DrawingDocument)dokuments1.NewFrom(@"C:\Users\jonat\Documents\GitHub\Schraubengott\3. Sprint\Schraubengott\Catia\Vorlage_HSP_Drawing.CATDrawing");

            //DrawingDocument drawingDokument1 = (DrawingDocument)dokuments1.NewFrom(pfad);
            DrawingDocument drawingDokument1 = (DrawingDocument)dokuments1.NewFrom(pfad);

            //Neues Zeichenblatt
            DrawingSheets drawingSheets1 = drawingDokument1.Sheets;
            DrawingSheet  drawingSheet1  = drawingSheets1.Item("A4_Zeichnungsrahmen");
            //Neue Zeichenansicht (Frontansicht)
            DrawingViews drawingViews1 = drawingSheet1.Views;
            DrawingView  drawingView1  = drawingViews1.Add("AutomaticNaming");
            DrawingViewGenerativeLinks    drawingViewGenerativeLinks1    = drawingView1.GenerativeLinks;
            DrawingViewGenerativeBehavior drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior;

            //Verbinden der Schraube mit der Zeichnung
            PartDocument partDocument1 = (PartDocument)dokuments1.Item("Part1.CATPart");
            ProductStructureTypeLib.Product product1 = (ProductStructureTypeLib.Product)partDocument1.GetItem("Part1");
            drawingViewGenerativeBehavior1.Document = product1;
            drawingViewGenerativeBehavior1.DefineFrontView(0, 0, 1, 1, 0, 0);
            // Positionierung der Ansicht auf Zeichenblatt
            drawingView1.x     = 105;
            drawingView1.y     = 190;
            drawingView1.Scale = 1;

            drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior;
            drawingViewGenerativeBehavior1.Update();
            drawingView1.Activate();
            #endregion

            // 2. Zeichenansicht erstellen (Draufsicht)
            DrawingView drawingView2 = drawingViews1.Add("AutomaticNaming");
            DrawingViewGenerativeBehavior drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior;

            //Projektion der ersten Ansicht in Ansicht einfügen
            drawingViewGenerativeBehavior2.DefineProjectionView(drawingViewGenerativeBehavior1, CatProjViewType.catTopView);
            DrawingViewGenerativeLinks drawingViewGenerativeLinks2 = (DrawingViewGenerativeLinks)drawingView2.GenerativeLinks;
            drawingViewGenerativeLinks1.CopyLinksTo(drawingViewGenerativeLinks2);

            //Position der 2. Ansicht
            drawingView2.x     = 108;
            drawingView2.y     = 90;
            drawingView2.Scale = 1;

            drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior;
            drawingViewGenerativeBehavior2.Update();

            //2. Skizze fest an erster Skizze ausrichten
            drawingView2.ReferenceView = drawingView1;
            drawingView2.AlignedWithReferenceView();

            #region Textfelder
            DrawingView drawingView3 = drawingViews1.Add("Textfeld");
            DrawingViewGenerativeLinks    drawingViewGenerativeLinks4    = drawingView3.GenerativeLinks;
            DrawingViewGenerativeBehavior drawingViewGenerativeBehavior3 = drawingView3.GenerativeBehavior;


            // Positionierung der Ansicht auf Zeichenblatt
            drawingView3.x     = 0;
            drawingView3.y     = 0;
            drawingView1.Scale = 1;

            drawingViewGenerativeBehavior3 = drawingView3.GenerativeBehavior;
            drawingViewGenerativeBehavior3.Update();

            DrawingTexts texts1 = drawingView3.Texts;
            DrawingText  text1  = texts1.Add(kundendaten[0], 44, 46.5);
            text1.SetFontSize(0, 0, 2.2);

            DrawingTexts texts2 = drawingView3.Texts;
            DrawingText  text2  = texts2.Add(arr.typ, 141, 40.5);
            text2.SetFontSize(0, 0, 2.2);

            DrawingTexts texts3 = drawingView3.Texts;
            DrawingText  text3  = texts2.Add(arr.material, 141, 36);
            text3.SetFontSize(0, 0, 2.2);

            DrawingTexts texts4 = drawingView3.Texts;
            DrawingText  text4  = texts4.Add(bestellnummer.ToString(), 162, 26);
            text4.SetFontSize(0, 0, 3.5);

            string anschrift = kundendaten[2] + "\n" + kundendaten[3] + "\n" + kundendaten[4];

            DrawingTexts texts5 = drawingView3.Texts;
            DrawingText  text5  = texts5.Add(anschrift, 21.5, 43);
            text5.SetFontSize(0, 0, 2.2);
            #endregion
        }