static void Main(string[] args) { INFITF.Application catia; try { catia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Appication"); } catch (Exception) { catia = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application")); } catia.Visible = true; //open the file PartDocument prtDoc = (PartDocument)catia.Documents.Open(@"C:\Users\517-11\Desktop\saori\Automation\Catia-v5-Automation\DraftingAABoltUsingScript\7_Drafting_the_bolt\Bolt.CATPart"); DrawingDocument drwDoc = (DrawingDocument)catia.Documents.Open(@"C:\Users\517-11\Desktop\saori\Automation\Catia-v5-Automation\DraftingAABoltUsingScript\7_Drafting_the_bolt\TitleBlock.CATDrawing"); //3.get the active sheet DrawingSheet drwSheet = drwDoc.DrawingRoot.ActiveSheet; ////4. add a new view------------------------------------------------ DrawingView FrntView = drwSheet.Views.Add("Front View"); //5.Translate the view x;400 y;150 FrntView.x = 400; FrntView.y = 150; //6.get the generativeBehavior DrawingViewGenerativeBehavior FrntVwGB = FrntView.GenerativeBehavior; // define a front view with the xy plan 1,0,0,0,1,0 FrntVwGB.DefineFrontView(1, 0, 0, 0, 1, 0); //7.assouciated the 3d docuemnt(bolt) with this view. //ref; DrawingViewGenerativeBehavior (Object) //PartDocument prtToDoc = (PartDocument)catia.Documents.Item("CATPart1"); //FrntView.GenerativeBehavior.Document = prtToDoc; FrntView.GenerativeBehavior.Document = prtDoc; //8.Add a top view x;400 y;600------------------------------------ DrawingView Topvw = drwSheet.Views.Add("TopView"); Topvw.x = 400; Topvw.y = 600; DrawingViewGenerativeBehavior TopVwGB = Topvw.GenerativeBehavior; TopVwGB.DefineProjectionView(TopVwGB, CatProjViewType.catTopView); //9. assouciated the 3d docuemnt(bolt) with this view. Topvw.GenerativeBehavior.Document = prtDoc; //10. Activate the view ----------------------------------- //& get its Factory2D to create a circle int each view. //C1(30,30,10) c2(30,,) FrntView.Activate(); Factory2D facF = FrntView.Factory2D; Circle2D c1 = facF.CreateClosedCircle(30, 30, 10); Topvw.Activate(); Factory2D facT = Topvw.Factory2D; Circle2D c2 = facT.CreateClosedCircle(30, 30, 20); //text 추가하기--------------- FrntView.Activate(); DrawingText Ftxt = FrntView.Texts.Add("Front View", 100, 100); Ftxt.SetFontSize(0, 0, 12); DrawingLeader FDleadr = Ftxt.Leaders.Add(0, 0); //txt cnrk-------------------- Topvw.Activate(); DrawingText Ttxt = Topvw.Texts.Add("Top View", -45, 130); Ttxt.SetFontSize(0, 0, 12); DrawingLeader TDleadr = Ttxt.Leaders.Add(0, 0); //table추가하기 DrawingTable table = FrntView.Tables.Add(100, 80, 2, 3, 14, 40); //table. //11. update the drawing document. drwDoc.Update(); }
internal void Zeichnungsableitung(Schraube arr, int bestellnummer, string[] kundendaten) { #region Erste Ansicht einfügen //Neues Dokument aus Vorlage erstellen Documents dokuments1 = hsp_catiaApp.Documents; string pfad = System.IO.Path.GetFullPath("Vorlage_HSP_Drawing.CATDrawing"); //DrawingDocument drawingDokument1 = (DrawingDocument)dokuments1.NewFrom(@"C:\Users\jonat\Documents\GitHub\Schraubengott\3. Sprint\Schraubengott\Catia\Vorlage_HSP_Drawing.CATDrawing"); //DrawingDocument drawingDokument1 = (DrawingDocument)dokuments1.NewFrom(pfad); DrawingDocument drawingDokument1 = (DrawingDocument)dokuments1.NewFrom(pfad); //Neues Zeichenblatt DrawingSheets drawingSheets1 = drawingDokument1.Sheets; DrawingSheet drawingSheet1 = drawingSheets1.Item("A4_Zeichnungsrahmen"); //Neue Zeichenansicht (Frontansicht) DrawingViews drawingViews1 = drawingSheet1.Views; DrawingView drawingView1 = drawingViews1.Add("AutomaticNaming"); DrawingViewGenerativeLinks drawingViewGenerativeLinks1 = drawingView1.GenerativeLinks; DrawingViewGenerativeBehavior drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior; //Verbinden der Schraube mit der Zeichnung PartDocument partDocument1 = (PartDocument)dokuments1.Item("Part1.CATPart"); ProductStructureTypeLib.Product product1 = (ProductStructureTypeLib.Product)partDocument1.GetItem("Part1"); drawingViewGenerativeBehavior1.Document = product1; drawingViewGenerativeBehavior1.DefineFrontView(0, 0, 1, 1, 0, 0); // Positionierung der Ansicht auf Zeichenblatt drawingView1.x = 105; drawingView1.y = 190; drawingView1.Scale = 1; drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior; drawingViewGenerativeBehavior1.Update(); drawingView1.Activate(); #endregion // 2. Zeichenansicht erstellen (Draufsicht) DrawingView drawingView2 = drawingViews1.Add("AutomaticNaming"); DrawingViewGenerativeBehavior drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior; //Projektion der ersten Ansicht in Ansicht einfügen drawingViewGenerativeBehavior2.DefineProjectionView(drawingViewGenerativeBehavior1, CatProjViewType.catTopView); DrawingViewGenerativeLinks drawingViewGenerativeLinks2 = (DrawingViewGenerativeLinks)drawingView2.GenerativeLinks; drawingViewGenerativeLinks1.CopyLinksTo(drawingViewGenerativeLinks2); //Position der 2. Ansicht drawingView2.x = 108; drawingView2.y = 90; drawingView2.Scale = 1; drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior; drawingViewGenerativeBehavior2.Update(); //2. Skizze fest an erster Skizze ausrichten drawingView2.ReferenceView = drawingView1; drawingView2.AlignedWithReferenceView(); #region Textfelder DrawingView drawingView3 = drawingViews1.Add("Textfeld"); DrawingViewGenerativeLinks drawingViewGenerativeLinks4 = drawingView3.GenerativeLinks; DrawingViewGenerativeBehavior drawingViewGenerativeBehavior3 = drawingView3.GenerativeBehavior; // Positionierung der Ansicht auf Zeichenblatt drawingView3.x = 0; drawingView3.y = 0; drawingView1.Scale = 1; drawingViewGenerativeBehavior3 = drawingView3.GenerativeBehavior; drawingViewGenerativeBehavior3.Update(); DrawingTexts texts1 = drawingView3.Texts; DrawingText text1 = texts1.Add(kundendaten[0], 44, 46.5); text1.SetFontSize(0, 0, 2.2); DrawingTexts texts2 = drawingView3.Texts; DrawingText text2 = texts2.Add(arr.typ, 141, 40.5); text2.SetFontSize(0, 0, 2.2); DrawingTexts texts3 = drawingView3.Texts; DrawingText text3 = texts2.Add(arr.material, 141, 36); text3.SetFontSize(0, 0, 2.2); DrawingTexts texts4 = drawingView3.Texts; DrawingText text4 = texts4.Add(bestellnummer.ToString(), 162, 26); text4.SetFontSize(0, 0, 3.5); string anschrift = kundendaten[2] + "\n" + kundendaten[3] + "\n" + kundendaten[4]; DrawingTexts texts5 = drawingView3.Texts; DrawingText text5 = texts5.Add(anschrift, 21.5, 43); text5.SetFontSize(0, 0, 2.2); #endregion }