Пример #1
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;
            Bodies       bdys     = prt.Bodies;
            Body         PartBody = bdys.Item(1);

            INFITF.Reference xypln  = (INFITF.Reference)prt.OriginElements.PlaneXY; //다른 body에서 사용가능
            ShapeFactory     shpfac = (ShapeFactory)prt.ShapeFactory;

            //1 body1생성-----------------------
            Body      bdy1  = bdys.Add();
            Sketches  skts  = bdy1.Sketches;
            Sketch    skt   = skts.Add(xypln);
            Factory2D fac2d = skt.OpenEdition();

            CreateRectangle(fac2d, prt, skt, 50, 50, 100, 100); //사각형을 만든 method를 작성했다

            skt.CloseEdition();

            Pad p1 = shpfac.AddNewPad(skt, 80);

            //2--------------------------------
            Body   bdy2 = bdys.Add();
            Sketch skt2 = bdy2.Sketches.Add(xypln);

            fac2d = skt2.OpenEdition();

            Circle2D c = fac2d.CreateClosedCircle(75, 75, 20);

            skt2.CloseEdition();
            Pad p2 = shpfac.AddNewPad(skt2, 100);

            //3----------------------------------
            Body   bdy3 = bdys.Add();
            Sketch skt3 = bdy3.Sketches.Add(xypln);

            fac2d = skt3.OpenEdition();

            Point2D pt1 = fac2d.CreatePoint(75, 80);
            Point2D pt2 = fac2d.CreatePoint(70, 70);
            Point2D pt3 = fac2d.CreatePoint(80, 70);

            CreateTriangle(fac2d, prt, skt3, pt1, pt2, pt3);        //삼각형을 만든 method를 작성했다

            skt3.CloseEdition();
            Pad p3 = shpfac.AddNewPad(skt3, 100);

            //----------------------------------------------
            prt.InWorkObject = PartBody;        //workobject 지정한다

            shpfac.AddNewAdd(bdy1);
            shpfac.AddNewAdd(bdy2);
            shpfac.AddNewRemove(bdy3);

            prt.Update();
        }