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