示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            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;
            MECMOD.Bodies       bdys   = prt.Bodies;
            MECMOD.Body         bdy    = bdys.Add();
            MECMOD.Sketches     skts   = bdy.Sketches;

            INFITF.Reference xypln = (INFITF.Reference)prt.OriginElements.PlaneXY;
            MECMOD.Sketch    skt   = skts.Add(xypln);

            MECMOD.Factory2D fac2d = skt.OpenEdition();

            Point2D p1 = fac2d.CreatePoint(10, 10);
            Point2D p2 = fac2d.CreatePoint(10, 40);
            Point2D p3 = fac2d.CreatePoint(40, 40);
            Point2D p4 = fac2d.CreatePoint(40, 10);
            Point2D p5 = fac2d.CreatePoint(30, 20);
            Point2D p6 = fac2d.CreatePoint(20, 5);

            Line2D linLft = fac2d.CreateLine(10, 10, 10, 40);
            Line2D linTop = fac2d.CreateLine(10, 40, 40, 40);
            Line2D linRgt = fac2d.CreateLine(40, 40, 40, 10);

            object[] parry = { p1, p6, p5, p4 };
            Spline2D spl   = fac2d.CreateSpline(parry);

            linLft.StartPoint = p1;
            linLft.EndPoint   = p2;
            linRgt.StartPoint = p3;
            linRgt.EndPoint   = p4;
            linTop.StartPoint = p2;
            linTop.EndPoint   = p3;

            MECMOD.Constraint cnst = skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeAxisPerpendicularity, (INFITF.Reference)linLft, (INFITF.Reference)linTop);

            /*
             * INFITF.Reference r1 = prt.CreateReferenceFromGeometry(linLft);
             * INFITF.Reference r2 = prt.CreateReferenceFromGeometry(linTop);
             * MECMOD.Constraint cnst1 = skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeAxisPerpendicularity, r1, r2);
             */
            skt.CloseEdition();

            prt.Update();
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            INFITF.Application Catia;


            try
            {
                Catia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application");
            }


            catch
            {
                Catia         = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application"));
                Catia.Visible = true;
            }
            INFITF.Documents Docts = Catia.Documents;

            MECMOD.PartDocument PrtDoc = (MECMOD.PartDocument)Docts.Add("Part");

            MECMOD.Part Prt = PrtDoc.Part;

            MECMOD.Bodies Bodis = Prt.Bodies;

            MECMOD.Body PartBody = Bodis.Item(1);

            MECMOD.Body Body = Bodis.Add();

            MECMOD.Sketches Skts = Body.Sketches;


            INFITF.Reference plane = (INFITF.Reference)Prt.OriginElements.PlaneXY;

            MECMOD.Sketch Skt = Skts.Add(plane);

            MECMOD.Factory2D Fac2D = Skt.OpenEdition();



            Point2D Pt1 = Fac2D.CreatePoint(50, 50);
            Point2D Pt2 = Fac2D.CreatePoint(50, 100);
            Point2D Pt3 = Fac2D.CreatePoint(100, 100);
            Point2D Pt4 = Fac2D.CreatePoint(100, 50);


            //  <<  Create Line >>
            Line2D Lin1 = Fac2D.CreateLine(50, 50, 50, 100);

            Line2D Lin2 = Fac2D.CreateLine(50, 100, 100, 100);

            Line2D Lin3 = Fac2D.CreateLine(100, 100, 100, 50);

            Line2D Lin4 = Fac2D.CreateLine(100, 50, 50, 50);

            //     Line2D Lin22 = MCreateLine(Fac2d, Pt1, Pt2);



            //라인의 시작점부터 마지막점을 결정

            Lin1.StartPoint = Pt1;
            Lin1.EndPoint   = Pt2;
            Lin2.StartPoint = Pt2;
            Lin2.EndPoint   = Pt3;
            Lin3.StartPoint = Pt3;
            Lin3.EndPoint   = Pt4;
            Lin4.StartPoint = Pt4;
            Lin4.EndPoint   = Pt1;

            INFITF.Reference rline1 = Prt.CreateReferenceFromGeometry(Lin1);
            INFITF.Reference rline2 = Prt.CreateReferenceFromGeometry(Lin2);
            INFITF.Reference rline3 = Prt.CreateReferenceFromGeometry(Lin3);
            INFITF.Reference rline4 = Prt.CreateReferenceFromGeometry(Lin4);
            INFITF.Reference rlineH = Prt.CreateReferenceFromGeometry(Skt.AbsoluteAxis.HorizontalReference);
            INFITF.Reference rlineV = Prt.CreateReferenceFromGeometry(Skt.AbsoluteAxis.VerticalReference);

            MECMOD.Constraint d1 = Skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rline1, rline3);
            MECMOD.Constraint d2 = Skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rline2, rline4);
            MECMOD.Constraint d3 = Skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rlineH, rline4);
            MECMOD.Constraint d4 = Skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rlineV, rline1);

            Skt.CloseEdition();//Skech조건 끝 //

            //PAD를 하기 위해서 조건문을 만든다.//
            PARTITF.ShapeFactory ShpFac = (PARTITF.ShapeFactory)Prt.ShapeFactory;
            //그 shapeFactory를 돌출하기 위해서 AddNewPad를 사용해서 50만큼 돌출한다.//
            ShpFac.AddNewPad(Skt, 50);



            //새로운 Body2를 만들기 //
            MECMOD.Body Body2 = Bodis.Add();
            //planed을 기준으로 Skt2를 만든다.//
            MECMOD.Sketch Skt2 = (MECMOD.Sketch)Body2.Sketches.Add(plane);
            //스켓이 시작 //
            Fac2D = Skt2.OpenEdition();
            //  X=75,Y=75 를 중심으로 D=20의  원을  만들기//
            Circle2D Cir2D = Fac2D.CreateClosedCircle(75, 75, 20);

            //스켓을 끝내기//
            Skt2.CloseEdition();
            //PAD  80만큼 //
            ShpFac.AddNewPad(Skt2, 80);

            //Body3 만들기 //
            Body Body3 = Prt.Bodies.Add();
            //Skt3를 Body2 안에 plane면을 기준으로  Sketche를 한다.
            Sketch Skt3 = Body2.Sketches.Add(plane);

            //스킷을 시작//
            Fac2D = Skt3.OpenEdition();
            //  X=75,Y=75 를 중심으로 D=5의  원을  만들기//
            Fac2D.CreateClosedCircle(75, 75, 5);
            //스켓3을 끝내기//
            Skt3.CloseEdition();
            //스켓3을 80만큼 PAD를 한다.
            ShpFac.AddNewPad(Skt3, 80);
            /////////////////
            //PartBody에 Prat In Work Object를 사용해서 조건을 만든다.
            Prt.InWorkObject = PartBody;

            ShpFac.AddNewAdd(Body);     //PartBody에 Body를추가
            ShpFac.AddNewAdd(Body2);    //PartBody에 Body2를추가
            ShpFac.AddNewRemove(Body3); //PartBody에 Body3를 제거한다


            Prt.Update();
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            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;
            MECMOD.Bodies       bdys   = prt.Bodies;
            MECMOD.Body         bdy    = bdys.Add();
            MECMOD.Sketches     skts   = bdy.Sketches;

            INFITF.Reference xypln = (INFITF.Reference)prt.OriginElements.PlaneXY;
            Sketch           skt1  = skts.Add(xypln);

            Factory2D fac2d = skt1.OpenEdition();   //fac2d안에서 sketch가 이루어진다. fac2d cketch의 기능을 쓸수있다

            Point2D p1 = fac2d.CreatePoint(10, 10);
            Point2D p2 = fac2d.CreatePoint(10, 30);
            Point2D p3 = fac2d.CreatePoint(40, 30);
            Point2D p4 = fac2d.CreatePoint(40, 10);

            //method를 만들고 line생성
            Line2D lin1 = CreateLine(fac2d, p1, p2);
            Line2D lin2 = CreateLine(fac2d, p2, p3);
            Line2D lin3 = CreateLine(fac2d, p3, p4);
            Line2D lin4 = CreateLine(fac2d, p4, p1);

            CatConstraintType cnstDis = CatConstraintType.catCstTypeDistance;


            MECMOD.Constraint d1 = createCnst(prt, skt1, cnstDis, lin1, lin3);
            MECMOD.Constraint d2 = createCnst(prt, skt1, cnstDis, lin2, lin4);
            MECMOD.Constraint d3 = createCnst(prt, skt1, cnstDis, skt1.AbsoluteAxis.HorizontalReference, lin4);
            MECMOD.Constraint d4 = createCnst(prt, skt1, cnstDis, skt1.AbsoluteAxis.VerticalReference, lin1);

            /*
             * INFITF.Reference rline1 = prt.CreateReferenceFromGeometry(lin1);
             * INFITF.Reference rline2 = prt.CreateReferenceFromGeometry(lin2);
             * INFITF.Reference rline3 = prt.CreateReferenceFromGeometry(lin3);
             * INFITF.Reference rline4 = prt.CreateReferenceFromGeometry(lin4);
             * INFITF.Reference rlineH = prt.CreateReferenceFromGeometry(skt1.AbsoluteAxis.HorizontalReference);
             * INFITF.Reference rlineV = prt.CreateReferenceFromGeometry(skt1.AbsoluteAxis.VerticalReference);
             *
             * MECMOD.Constraint d1 = skt1.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rline1, rline3);
             * MECMOD.Constraint d2 = skt1.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rline2, rline4);
             * MECMOD.Constraint d3 = skt1.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rlineH, rline4);
             * MECMOD.Constraint d4 = skt1.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rlineV, rline1);
             */
            skt1.CloseEdition();

            //create a circlr
            Sketch    skt2   = skts.Add(xypln);
            Factory2D fac2d1 = skt2.OpenEdition();

            //fac2d = skt2.OpenEdition();   //이렇게 함녀 된다.

            INFITF.Reference H = prt.CreateReferenceFromGeometry(skt2.AbsoluteAxis.HorizontalReference);
            INFITF.Reference V = prt.CreateReferenceFromGeometry(skt2.AbsoluteAxis.VerticalReference);

            Circle2D c = fac2d1.CreateClosedCircle(40, 30, 10);

            c.CenterPoint = p3;
            // MECMOD.Constraint orPtH = skt2.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance,H,(INFITF.Reference)c);
            //MECMOD.Constraint orPtV = skt2.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, V, (INFITF.Reference)c);
            MECMOD.Constraint r = skt2.Constraints.AddMonoEltCst(CatConstraintType.catCstTypeRadius, (INFITF.Reference)c);

            skt2.CloseEdition();

            ShapeFactory ShpFac = (ShapeFactory)prt.ShapeFactory;
            //pad
            Pad pad = ShpFac.AddNewPad(skt1, 20);

            //poket
            Pocket pock = ShpFac.AddNewPocket(skt2, 20);

            pock.DirectionOrientation = CatPrismOrientation.catRegularOrientation;

            prt.Update();
        }
示例#4
0
        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;
            MECMOD.Bodies       bdys   = prt.Bodies;
            MECMOD.Body         bdy    = bdys.Add();
            MECMOD.Sketches     skts   = bdy.Sketches;

            INFITF.Reference xypln = (INFITF.Reference)prt.OriginElements.PlaneXY;
            MECMOD.Sketch    skt   = skts.Add(xypln);

            MECMOD.Factory2D fac2d = skt.OpenEdition();

            Point2D p1 = fac2d.CreatePoint(50, 50);
            Point2D p2 = fac2d.CreatePoint(50, 100);
            Point2D p3 = fac2d.CreatePoint(100, 100);
            Point2D p4 = fac2d.CreatePoint(100, 50);

            //method를 만들고 line생성
            Line2D lin1 = CreateLine(fac2d, p1, p2);
            Line2D lin2 = CreateLine(fac2d, p2, p3);
            Line2D lin3 = CreateLine(fac2d, p3, p4);
            Line2D lin4 = CreateLine(fac2d, p4, p1);

            /*
             * Line2D lin1 = fac2d.CreateLine(50,50,50,100);
             * Line2D lin2 = fac2d.CreateLine(50, 100, 100, 100);
             * Line2D lin3 = fac2d.CreateLine(100, 100, 100, 50);
             * Line2D lin4 = fac2d.CreateLine(100, 50, 50, 50);
             *
             * lin1.StartPoint = p1;
             * lin1.EndPoint = p2;
             *
             * lin2.StartPoint = p2;
             * lin2.EndPoint = p3;
             *
             * lin3.StartPoint = p3;
             * lin3.EndPoint = p4;
             *
             * lin4.StartPoint = p4;
             * lin4.EndPoint = p1;
             */

            INFITF.Reference rline1 = prt.CreateReferenceFromGeometry(lin1);
            INFITF.Reference rline2 = prt.CreateReferenceFromGeometry(lin2);
            INFITF.Reference rline3 = prt.CreateReferenceFromGeometry(lin3);
            INFITF.Reference rline4 = prt.CreateReferenceFromGeometry(lin4);
            INFITF.Reference rlineH = prt.CreateReferenceFromGeometry(skt.AbsoluteAxis.HorizontalReference);
            INFITF.Reference rlineV = prt.CreateReferenceFromGeometry(skt.AbsoluteAxis.VerticalReference);

            Constraint d1 = skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rline1, rline3);
            Constraint d2 = skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rline2, rline4);
            Constraint d3 = skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rlineH, rline4);
            Constraint d4 = skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeDistance, rlineV, rline1);

            skt.CloseEdition();
        }
示例#5
0
        private void button1_Click(object sender, EventArgs e)
        {
            INFITF.Application catia;        //INFITF.Application; returntype, catia; 변수명

            try
            {
                catia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application"); //실행되 있는 카티아 가져오기
            }
            catch (Exception ex)
            {
                //MessageBox.Show("카티아가 실행돼 있지 않습니다.");
                //MessageBox.Show("카티아 가져오기 오류: "+ex.Message);
                //catia 열기
                catia         = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application"));
                catia.Visible = true;
            }
            //creat a part

            /*
             * catia.Documents.Add("Part1");
             * //catia.Documents.Open();
             * MECMOD.PartDocument part1;
             */
            MECMOD.PartDocument partDoc;
            partDoc = (MECMOD.PartDocument)catia.Documents.Add("Part");

            MECMOD.Part prt = partDoc.Part; //partDoc에 part를 담은 것

            MECMOD.Bodies bodies = prt.Bodies;

            MECMOD.Body body = bodies.Add();    //다름 body만들기
            //MECMOD.Body body0 = bodies.Item(1); //생성되 있는 partbody가져오기
            //MECMOD.Body body2 = bodies.Item("PartBody"); //해당되는 것에 이름
            //MECMOD.Body body1 = prt.MainBody;   //partbody가져오기

            MECMOD.Sketches skts = body.Sketches;

            INFITF.Reference xyPln = (INFITF.Reference)prt.OriginElements.PlaneXY; //creat a plan

            MECMOD.Sketch skt = skts.Add(xyPln);                                   //plane에 skt를 작성한다.
                                                                                   //open the skt
            MECMOD.Factory2D fac2d = skt.OpenEdition();

            //6.create the points
            MECMOD.GeometricElements gme = prt.GeometricElements;
            MECMOD.Point2D           p1  = fac2d.CreatePoint(10, 10);
            MECMOD.Point2D           p2  = fac2d.CreatePoint(10, 40);
            MECMOD.Point2D           p3  = fac2d.CreatePoint(40, 40);
            MECMOD.Point2D           p4  = fac2d.CreatePoint(40, 10);
            MECMOD.Point2D           p5  = fac2d.CreatePoint(30, 20);
            MECMOD.Point2D           p6  = fac2d.CreatePoint(20, 5);

            //7.create the lines
            MECMOD.Line2D line1 = fac2d.CreateLine(10, 10, 10, 40);
            MECMOD.Line2D line2 = fac2d.CreateLine(10, 40, 40, 40);
            MECMOD.Line2D line3 = fac2d.CreateLine(40, 40, 40, 10);

            //8.9 create  the spline
            Object[]        pa     = { p1, p6, p5, p4 };
            MECMOD.Spline2D spline = fac2d.CreateSpline(pa);

            //구속조건 추가
            //10
            line1.StartPoint = p1;
            line1.EndPoint   = p2;

            line2.StartPoint = p2;
            line2.EndPoint   = p3;

            line3.StartPoint = p3;
            line3.EndPoint   = p4;

            //11.create references
            INFITF.Reference rline1 = prt.CreateReferenceFromGeometry(line1);
            INFITF.Reference rline2 = prt.CreateReferenceFromGeometry(line2);

            INFITF.Reference rline3 = prt.CreateReferenceFromGeometry(line3);

            //12.
            MECMOD.Constraint cns = skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeAxisPerpendicularity, rline1, rline2);

            MECMOD.Constraint cns1 = skt.Constraints.AddBiEltCst(CatConstraintType.catCstTypeAxisPerpendicularity, rline3, rline2);

            //13.
            skt.CloseEdition();

            //catia.Visible = true;
        }