private void button3_Click(object sender, EventArgs e) { if (PtStart == null) { return; } if (PtEnd == null) { return; } MECMOD.PartDocument PrtDoc = (MECMOD.PartDocument)Catia.ActiveDocument; MECMOD.Part prt = PrtDoc.Part; MECMOD.HybridBodies HBs = prt.HybridBodies; MECMOD.HybridBody HyBody = HBs.Add(); HybridShapeTypeLib.HybridShapeFactory HSFac = (HybridShapeTypeLib.HybridShapeFactory)prt.HybridShapeFactory; HybridShapeTypeLib.HybridShapeLinePtPt Lineptpt = null; Lineptpt = HSFac.AddNewLinePtPt((INFITF.Reference)PtStart, (INFITF.Reference)PtEnd); HyBody.AppendHybridShape(Lineptpt); prt.Update(); }
private void button1_Click(object sender, EventArgs e) { //1. open the file if (textBox1.Text == "") { MessageBox.Show("파일 주소를 입력해주세요."); return; } prtDoc = (MECMOD.PartDocument)catia.Documents.Open(textBox1.Text); }
/// <param name="type">accepting params: {Cross, ZigZag}</param> public static void mainAction(grooveType type, double width, double depth, double edges, bool isolateKeyAuto, bool debugRastr, bool debugInflated) { //all try try { MainAction.isolateKeyAuto = isolateKeyAuto; MainAction.debugRastr = debugRastr; MainAction.debugInflated = debugInflated; MainAction.width = width; MainAction.depth = depth; MainAction.edges = edges; MainAction.type = type; try { catiaInstance = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Catia.Application"); } catch { return; } oPartDocument = (MECMOD.PartDocument)catiaInstance.ActiveDocument; MECMOD.PlanarFace oPlanarFace = null; INFITF.Reference oReference = null; List <PlanarfaceWithReference> selectedPlanarfaces = new List <PlanarfaceWithReference>(); int selectionCount = Int32.Parse(oPartDocument.Selection.Count2.ToString()); if (selectionCount >= 1) { for (int i = 1; i <= selectionCount; i++) { try { oPlanarFace = (MECMOD.PlanarFace)oPartDocument.Selection.Item2(i).Value; oReference = (INFITF.Reference)oPartDocument.Selection.Item2(i).Value; selectedPlanarfaces.Add(new PlanarfaceWithReference(oPlanarFace, oReference)); } catch { } } } if (selectedPlanarfaces.Count >= 1) { foreach (PlanarfaceWithReference cpl in selectedPlanarfaces) { action(cpl); } } else { MainForm.myForm.Activate(); MessageBox.Show("First select one or more planar faces!"); return; } //all catch } catch {} }
private void button1_Click(object sender, EventArgs e) { // 카티아가 실행중? if (Catia == null) { MessageBox.Show("Please run CATIA"); return; } /* * // 활성 문서가 있는가? * if (Catia.ActiveDocument == null) * { * //MessageBox.Show("활성 문서가 없습니다"); * label1.Text = "활성 문서가 없습니다"; * } */ try { doc = (MECMOD.PartDocument)Catia.ActiveDocument; } catch (Exception) { doc = (MECMOD.PartDocument)Catia.Documents.Add("Part"); } try { Sel = Catia.ActiveDocument.Selection; } catch (Exception) { MessageBox.Show("copy할 요소를 선택해주세요"); return; } // MessageBox.Show(Sel.Count +" , " + Sel.Count2 +" , " + Sel.Item(1).get_Name() + " , " + Sel.Item(3).get_Name() + " , " + Sel.Item(3).get_Name()/* + " , " + Sel.Item(4).get_Name()*/); try { Sel.Copy(); MessageBox.Show(Sel.Count + "개 복사 되엇습니다."); } catch (Exception) { MessageBox.Show("copy할 요소를 선택해주세요"); return; } }
//// 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) { cPartDoc = (MECMOD.PartDocument)cDocs.Read(filePath); } else if (mode == 1) { cPartDoc = (MECMOD.PartDocument)cDocs.Add("Part"); } cApp.Visible = true; cPart = cPartDoc.Part; cBodies = cPart.Bodies; cFactory = cPart.ShapeFactory; cShapeFactory = (PARTITF.ShapeFactory)cFactory; cHybridShapeFactory = (HybridShapeTypeLib.HybridShapeFactory)cPart.HybridShapeFactory; cCurrentBody = cBodies.Item(1); cShapes = cCurrentBody.Shapes; cSketches = cCurrentBody.Sketches; cOriginalElements = cPart.OriginElements; if (ReferenceManager == null) { ReferenceManager = new Reference(this); } return(true); }
private void Form1_Load(object sender, EventArgs e) { try { Catia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application"); } catch { Catia = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application")); Catia.Visible = true; } try { doc = (MECMOD.PartDocument)Catia.ActiveDocument; } catch (Exception) { MessageBox.Show("활성 문서가 없습니다"); } }
private void button2_Click(object sender, EventArgs e) { if (catia == null) { MessageBox.Show("Please run CATIA"); return; } try { prtDoc = (MECMOD.PartDocument)catia.ActiveDocument; } catch (Exception) { MessageBox.Show("please open a document."); return; } //2.Gs 생성 MECMOD.HybridBody hbdy = prtDoc.Part.HybridBodies.Add(); hbdy.set_Name("PointForDraeingGS"); //3.add points HybridShapeTypeLib.HybridShapeFactory hfac = (HybridShapeTypeLib.HybridShapeFactory)prtDoc.Part.HybridShapeFactory; pt1 = hfac.AddNewPointCoord(0, 0, 0); pt2 = hfac.AddNewPointCoord(-250, 100, -300); pt3 = hfac.AddNewPointCoord(90, -250, 60); pt1.set_Name("PT-1"); pt2.set_Name("PT-2"); pt3.set_Name("PT-3"); hbdy.AppendHybridShape(pt1); hbdy.AppendHybridShape(pt2); hbdy.AppendHybridShape(pt3); prtDoc.Part.Update(); }
/// <param name="type">accepting params: {Cross, ZigZag}</param> public static void mainAction(grooveType type, double width, double depth, double edges, bool isolateKeyAuto, bool debugRastr, bool debugInflated ) { //all try try { MainAction.isolateKeyAuto = isolateKeyAuto; MainAction.debugRastr = debugRastr; MainAction.debugInflated = debugInflated; MainAction.width = width; MainAction.depth = depth; MainAction.edges = edges; MainAction.type = type; try { catiaInstance = (INFITF.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Catia.Application"); } catch {return;} oPartDocument = (MECMOD.PartDocument)catiaInstance.ActiveDocument; MECMOD.PlanarFace oPlanarFace = null; INFITF.Reference oReference = null; List<PlanarfaceWithReference> selectedPlanarfaces = new List<PlanarfaceWithReference>(); int selectionCount = Int32.Parse( oPartDocument.Selection.Count2.ToString()); if (selectionCount>=1) { for (int i = 1; i <= selectionCount; i++) { try { oPlanarFace = (MECMOD.PlanarFace )oPartDocument.Selection.Item2(i).Value; oReference = (INFITF.Reference)oPartDocument.Selection.Item2(i).Value; selectedPlanarfaces.Add(new PlanarfaceWithReference( oPlanarFace,oReference)); } catch{ } } } if (selectedPlanarfaces.Count>=1) { foreach (PlanarfaceWithReference cpl in selectedPlanarfaces) { action(cpl); } } else { MainForm.myForm.Activate(); MessageBox.Show("First select one or more planar faces!"); return; } //all catch } catch {} }
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(); }