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(); }
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(); }
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; }