Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
        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();
        }