//create3Dline-------------------------------------------- private void button5_Click(object sender, EventArgs e) { // object[] HpCrd1 = new object[3]; // object[] HpCrd2 = new object[3]; try { sel = catia.ActiveDocument.Selection; HyShpPtCoord1 = (HybridShapeTypeLib.Point)sel.FindObject("CATIAHybridShapePoint"); //sel = catia.ActiveDocument.Selection; HyShpPtCoord2 = (HybridShapeTypeLib.Point)sel.FindObject("CATIAHybridShapePoint"); //HyShpPtCoord1.GetCoordinates(HpCrd1); //HyShpPtCoord1.GetCoordinates(HpCrd2); PartDocument prtDoc = (PartDocument)catia.ActiveDocument; Part prt = prtDoc.Part; HybridBody hbdy = prt.HybridBodies.Item(1); HybridShapeFactory hfac = (HybridShapeFactory)prt.HybridShapeFactory; INFITF.Reference ref1 = prt.CreateReferenceFromGeometry(HyShpPtCoord1); INFITF.Reference ref2 = prt.CreateReferenceFromGeometry(HyShpPtCoord2); HybridShapeTypeLib.Line lin = hfac.AddNewLinePtPt(ref1, ref2); hbdy.AppendHybridShape(lin); prt.Update(); } catch (Exception) { MessageBox.Show("선택된 정보가 없습니다."); return; } }
static void Main(string[] args) { /* * StreamReader sr = new StreamReader("point.txt"); * String line = ""; * List<Pt> ptlist = new List<Pt>(); * * while ((line = sr.ReadLine()) != null) * { * string[] token = line.Split(','); * int x = int.Parse(token[0]); * int y = int.Parse(token[1]); * int z = int.Parse(token[2]); * ptlist.Add(new Pt(x,y,z)); * } */ INFITF.Application catia; try { catia = (INFITF.Application)Marshal.GetActiveObject("CATIA.Application"); } catch (Exception) { catia = (INFITF.Application)Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application")); } catia.Visible = true; PartDocument prtdoc = (PartDocument)catia.Documents.Add("Part"); Part prt = prtdoc.Part; HybridBodies hbdys = prt.HybridBodies; HybridBody hbdy = hbdys.Add(); HybridShapeFactory hsFac = (HybridShapeFactory)prt.HybridShapeFactory; try { StreamReader sr = new StreamReader("C:/Users/517-11/Desktop/saori/Automation/Catia-v5-Automation/RecapEx/point.txt"); String line = ""; //List<Pt> ptlist = new List<Pt>(); while ((line = sr.ReadLine()) != null) { string[] token = line.Split(','); int x = int.Parse(token[0]); int y = int.Parse(token[1]); int z = int.Parse(token[2]); // ptlist.Add(new Pt(x, y, z)); Point p = hsFac.AddNewPointCoord(x, y, z); hbdy.AppendHybridShape(p); } //Point p1 = hsFac.AddNewPointCoord(10, 60, 30); sr.Close(); prt.Update(); } catch (Exception e) { Console.WriteLine("파일io오류:" + e.Message); } }
// create lines private void button1_Click(object sender, EventArgs e) { try { prtDoc = (PartDocument)catia.ActiveDocument; Part prt = prtDoc.Part; hbdy = prt.HybridBodies.Item(1); HybridShapeFactory hfac = (HybridShapeFactory)prt.HybridShapeFactory; //SelGS = (HybridBody)Sel.Item(1).Value; //INFITF.AnyObject aaa = Pts[0]; for (int i = 0; i <= (Pts.Count - 1); i++) { for (int j = i + 1; j < Pts.Count; j++) { HybridShapeTypeLib.Point pt1 = (HybridShapeTypeLib.Point)Pts.ElementAt(i); HybridShapeTypeLib.Point pt2 = (HybridShapeTypeLib.Point)Pts.ElementAt(j); INFITF.Reference ref1 = prt.CreateReferenceFromGeometry(pt1); INFITF.Reference ref2 = prt.CreateReferenceFromGeometry(pt2); HybridShapeTypeLib.Line lin = hfac.AddNewLinePtPt(ref1, ref2); hbdy.AppendHybridShape(lin); } } prt.Update(); } catch (Exception) { MessageBox.Show("선택된 정보가 없습니다."); return; } }
private void BollToPoint_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; ReadType = 2; Selection SelectArc = null; CATIA_Class.GetSelect(CatDocument, ref SelectArc, this); if (SelectArc == null || SelectArc.Count2 == 0) { return; } int ERR = 0; object[] PointCoord = new object[] { -99, -99, -99 }; for (int i = 1; i <= SelectArc.Count2; i++) { HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory; SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench"); Reference referenceObject = SelectArc.Item(i).Reference; Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject); TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标 var TName = referenceObject.get_Name(); //读取选择的曲面名称 HybridShapePointCoord NewPoint = PartHyb.AddNewPointCoord(Convert.ToDouble(PointCoord[0]), Convert.ToDouble(PointCoord[1]), Convert.ToDouble(PointCoord[2])); if (KeepName.Checked) { NewPoint.set_Name(TName); } else { NewPoint.set_Name("Rx_" + i); } HybridBodies Hybs = PartID.HybridBodies; HybridBody Hyb = null; try { Hyb = Hybs.Item("几何图形集.1"); } catch (Exception) { Hyb = Hybs.Item("Geometrical Set.1"); } Hyb.AppendHybridShape(NewPoint); PartID.InWorkObject = NewPoint; try { PartID.Update(); } catch (Exception) { ERR += 1; } } if (ERR > 0) { MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!"); } }
public void ErzeugeKreismusterAußenverzahnung(Data dat) { ShapeFactory SF = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory HSF = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; //Skizze und Referenzen Factory2D Factory2D1 = hsp_catiaProfil.Factory2D; HybridShapePointCoord Ursprung = HSF.AddNewPointCoord(0, 0, 0); Reference RefUrsprung = hsp_catiaPart.Part.CreateReferenceFromObject(Ursprung); HybridShapeDirection XDir = HSF.AddNewDirectionByCoord(1, 0, 0); Reference RefXDir = hsp_catiaPart.Part.CreateReferenceFromObject(XDir); //Kreismuster mit Daten füllen CircPattern Kreismuster = SF.AddNewSurfacicCircPattern(Factory2D1, 1, 2, 0, 0, 1, 1, RefUrsprung, RefXDir, false, 0, true, false); Kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = Kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / dat.getZaehnezahlZahnrad1()); AngularRepartition angularRepartition2 = Kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(dat.getZaehnezahlZahnrad1()) + 1; //geschlossene Kontur Reference Ref_Kreismuster = hsp_catiaPart.Part.CreateReferenceFromObject(Kreismuster); HybridShapeAssemble Verbindung = HSF.AddNewJoin(Ref_Kreismuster, Ref_Kreismuster); Reference Ref_Verbindung = hsp_catiaPart.Part.CreateReferenceFromObject(Verbindung); HSF.GSMVisibility(Ref_Verbindung, 0); hsp_catiaPart.Part.Update(); Bodies bodies = hsp_catiaPart.Part.Bodies; Body myBody = bodies.Add(); myBody.set_Name("Zahnrad"); myBody.InsertHybridShape(Verbindung); hsp_catiaPart.Part.Update(); //Erzeuge Block aus Skizze hsp_catiaPart.Part.InWorkObject = myBody; Pad myPad = SF.AddNewPadFromRef(Ref_Verbindung, dat.getBreiteZahnrad1()); hsp_catiaPart.Part.Update(); }
private void button1_Click(object sender, EventArgs e) { //List<Pnt> pList = new List<Pnt>(); List <HybridShapeTypeLib.Point> pList = new List <HybridShapeTypeLib.Point>(); //prtDoc = (PartDocument)catia.Documents.Item(1); prtDoc = (PartDocument)catia.Documents.Add("Part"); Part prt = prtDoc.Part; HybridBodies hbdys = prt.HybridBodies; HybridBody hbdy = hbdys.Add(); hbdy.set_Name("saori"); HybridShapeFactory hsFac = (HybridShapeFactory)prt.HybridShapeFactory; //string Line = textBox1.Text; string lin = ""; if (textBox1.Text == "") { MessageBox.Show("좌표를 입력해주새요"); return; } for (int i = 0; i < textBox1.Lines.Length; i++) { lin = textBox1.Lines[i]; string[] token = lin.Split(','); int x = int.Parse(token[0]); int y = int.Parse(token[1]); int z = int.Parse(token[2]); // pList.Add(new Pnt(x, y, z)); pList.Add(hsFac.AddNewPointCoord(x, y, z)); HybridShapeTypeLib.Point p = hsFac.AddNewPointCoord(x, y, z); //create a point hbdy.AppendHybridShape(p); } //create points and spline HybridShapeSpline splin = hsFac.AddNewSpline(); foreach (HybridShapeTypeLib.Point p in pList) { INFITF.Reference r = prt.CreateReferenceFromGeometry(p); // hsFac.AddNewPointDatum(r); //hbdy.AppendHybridShape(p); splin.AddPoint(r); } hbdy.AppendHybridShape(splin); prt.Update(); }
/// <summary> /// 提取边到新Part /// </summary> /// <param name="Spart">新Part</param> /// <param name="UserSelected">用户选择的参考边</param> /// <returns>创建的新边</returns> public HybridShapeExtract NwExtraEdge(Part Spart, Reference UserSelected) { HybridShapeFactory PartShape = (HybridShapeFactory)Spart.ShapeFactory; HybridShapeExtract extractWeightEdge = PartShape.AddNewExtract(UserSelected); extractWeightEdge.PropagationType = 3; extractWeightEdge.ComplementaryExtract = false; //补充模式 extractWeightEdge.IsFederated = false; HybridBodies PartHybodies = Spart.HybridBodies; HybridBody PartHyBody = PartHybodies.Item(1); PartHyBody.AppendHybridShape(extractWeightEdge); Spart.InWorkObject = extractWeightEdge; Spart.Update(); return(extractWeightEdge); }
public void ErstelleLeereSkizze() { // Factories für das Erzeugen von Modellelementen (Std und Hybrid) SF = (ShapeFactory)myPart.ShapeFactory; HSF = (HybridShapeFactory)myPart.HybridShapeFactory; // geometrisches Set auswaehlen und umbenennen HybridBodies catHybridBodies1 = myPart.HybridBodies; HybridBody catHybridBody1; try { catHybridBody1 = catHybridBodies1.Item("Geometrisches Set.1"); } catch (Exception) { MessageBox.Show("Kein geometrisches Set gefunden! " + Environment.NewLine + "Ein PART manuell erzeugen und ein darauf achten, dass 'Geometisches Set' aktiviert ist.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Information); return; } catHybridBody1.set_Name("Profile"); // neue Skizze im ausgewaehlten geometrischen Set auf eine Offset Ebene legen mySketches = catHybridBody1.HybridSketches; OriginElements catOriginElements = myPart.OriginElements; HybridShapePlaneOffset hybridShapePlaneOffset1 = HSF.AddNewPlaneOffset( (Reference)catOriginElements.PlaneYZ, 90.000000, false); hybridShapePlaneOffset1.set_Name("OffsetEbene"); catHybridBody1.AppendHybridShape(hybridShapePlaneOffset1); myPart.InWorkObject = hybridShapePlaneOffset1; myPart.Update(); HybridShapes hybridShapes1 = catHybridBody1.HybridShapes; Reference catReference1 = (Reference)hybridShapes1.Item("OffsetEbene"); hsp_catiaSkizze = mySketches.Add(catReference1); // Achsensystem in Skizze erstellen ErzeugeAchsensystem(); // Part aktualisieren myPart.Update(); }
public bool InitCATIAPart() { try { oPartDoc = (MECMOD.PartDocument)CATIA.ActiveDocument; oPart = oPartDoc.Part; oBodies = oPart.Bodies; oBody = oPart.MainBody; oHBodies = oPart.HybridBodies; oSF = (ShapeFactory)oPart.ShapeFactory; oHSF = (HybridShapeFactory)oPart.HybridShapeFactory; } catch { } return(true); }
public void ErzeugeZahnrad(int Zaehnezahl, double Dicke, double Modul) { ShapeFactory SF = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory HSF = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; Part myPart = hsp_catiaPart.Part; Factory2D Factory2D1 = hsp_catiaProfil.Factory2D; HybridShapePointCoord Ursprung = HSF.AddNewPointCoord(0, 0, 0); Reference RefUrsprung = myPart.CreateReferenceFromObject(Ursprung); HybridShapeDirection XDir = HSF.AddNewDirectionByCoord(1, 0, 0); Reference RefXDir = myPart.CreateReferenceFromObject(XDir); CircPattern Kreismuster = SF.AddNewSurfacicCircPattern(Factory2D1, 1, 2, 0, 0, 1, 1, RefUrsprung, RefXDir, false, 0, true, false); Kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = Kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / Convert.ToDouble(Zaehnezahl)); AngularRepartition angularRepartition2 = Kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(Zaehnezahl) + 1; Reference Ref_Kreismuster = myPart.CreateReferenceFromObject(Kreismuster); HybridShapeAssemble Verbindung = HSF.AddNewJoin(Ref_Kreismuster, Ref_Kreismuster); Reference Ref_Verbindung = myPart.CreateReferenceFromObject(Verbindung); HSF.GSMVisibility(Ref_Verbindung, 0); myPart.Update(); Bodies bodies = myPart.Bodies; Body myBody = bodies.Add(); myBody.set_Name("Zahnrad"); myBody.InsertHybridShape(Verbindung); myPart.Update(); myPart.InWorkObject = myBody; Pad myPad = SF.AddNewPadFromRef(Ref_Verbindung, Dicke); myPart.Update(); }
//create a line private void button3_Click(object sender, EventArgs e) { try { prtDoc = (PartDocument)catia.ActiveDocument; HybridBody hbdy = (HybridBody)ptStrt.Parent; HybridShapeFactory hfac = (HybridShapeFactory)prtDoc.Part.HybridShapeFactory; Line lin = hfac.AddNewLinePtPt(ptStrt, ptEnd); hbdy.AppendHybridShape(lin); prtDoc.Part.Update(); } catch (Exception) { MessageBox.Show("error"); return; } }
private void PointToCoord_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; RepeatNum = 0; Array.Clear(GetRepeatRef, 0, GetRepeatRef.Length); ReadType = 1; Selection SelectArc = null; CATIA_Class.GetSelect(CatDocument, ref SelectArc, this); if (SelectArc == null || SelectArc.Count2 == 0) { this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; this.TopMost = true; return; } int ERR = 0; object[] PointCoord = new object[] { -99, -99, -99, -99, -99, -99 }; for (int i = 1; i <= SelectArc.Count2; i++) { HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory; SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench"); Reference referenceObject = SelectArc.Item(i).Reference; Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject); TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标 var TName = referenceObject.get_Name(); //读取选择的曲面名称 if (!KeepName.Checked) { TName = "Rx_" + (datatable.Rows.Count + 1); } WriteObjectToDataGrid(TName, PointCoord, referenceObject, IgRepeat.Checked); } SetDataGrid(); if (ERR > 0) { MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!"); } if (RepeatCheck.Checked) { CheckRepeat(SelectArc); } }
public void ErzeugeDasNeueKreismuster(Data dat) { ShapeFactory shapeFactory1 = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory hybridShapeFactory1 = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; Factory2D factory2D1 = hsp_catiaProfil.Factory2D; HybridShapePointCoord ursprung = hybridShapeFactory1.AddNewPointCoord(0, 0, 0); Reference refUrsprung = hsp_catiaPart.Part.CreateReferenceFromObject(ursprung); HybridShapeDirection xRichtung = hybridShapeFactory1.AddNewDirectionByCoord(1, 0, 0); Reference refxRichtung = hsp_catiaPart.Part.CreateReferenceFromObject(xRichtung); CircPattern kreismuster = shapeFactory1.AddNewSurfacicCircPattern(factory2D1, 1, 2, 0, 0, 1, 1, refUrsprung, refxRichtung, false, 0, true, false); kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / dat.getZähnezahl()); AngularRepartition angularRepartition2 = kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(dat.getZähnezahl()) + 1; //Kreismusterenden verbinden Reference refKreismuster = hsp_catiaPart.Part.CreateReferenceFromObject(kreismuster); HybridShapeAssemble verbindung = hybridShapeFactory1.AddNewJoin(refKreismuster, refKreismuster); Reference refVerbindung = hsp_catiaPart.Part.CreateReferenceFromObject(verbindung); hybridShapeFactory1.GSMVisibility(refVerbindung, 0); hsp_catiaPart.Part.MainBody.InsertHybridShape(verbindung); hsp_catiaPart.Part.Update(); ErzeugedenNeuenBlock(refVerbindung, shapeFactory1, dat); }
public bool InitCATIAPart(bool bNewPart, string strPart) { if (bNewPart) { //初始化 docCATIA = CATIA.Documents; oPartDoc = (MECMOD.PartDocument)docCATIA.Add("Part"); } else { if (strPart.Trim() == "") { oPartDoc = (MECMOD.PartDocument)CATIA.ActiveDocument; if (oPartDoc == null) { docCATIA = CATIA.Documents; oPartDoc = (MECMOD.PartDocument)docCATIA.Add("Part"); } } else { if (System.IO.File.Exists(strPart)) //有文件 { oPartDoc = (MECMOD.PartDocument)CATIA.Documents.Open(strPart); } else { return(false); } } } oPart = oPartDoc.Part; oBodies = oPart.Bodies; oBody = oPart.MainBody; oHBodies = oPart.HybridBodies; oSF = (ShapeFactory)oPart.ShapeFactory; oHSF = (HybridShapeFactory)oPart.HybridShapeFactory; return(true); }
internal void ErzeugeGewindehelix(Schraube arr) { hybridshapefac = (HybridShapeFactory)part_Schraube.HybridShapeFactory; // Skizze für Gewindeprofiel Sketch gewinde = Gewindeskizze(arr); // "Rotationsachse" festlegen HybridShapeDirection HelixDir = hybridshapefac.AddNewDirectionByCoord(1, 0, 0); Reference RefHelxDir = part_Schraube.CreateReferenceFromObject(HelixDir); //Startpunkt festlegen HybridShapePointCoord Helixstartpunkt = hybridshapefac.AddNewPointCoord(0, 0, 0.5 * arr.durchmesser); Reference RefHelixstartpunkt = part_Schraube.CreateReferenceFromObject(Helixstartpunkt); //Helix Erstellen HybridShapeHelix Helix = hybridshapefac.AddNewHelix(RefHelxDir, false, RefHelixstartpunkt, arr.gewindesteigung, arr.gewindelaenge - 1, false, 0, 0, false); // Drehrichtung, Startpunkt Steigung Höhe Drehrichtung Anfangswinkel ... Reference RefHelix = part_Schraube.CreateReferenceFromObject(Helix); Reference RefGewinde = part_Schraube.CreateReferenceFromObject(gewinde); part_Schraube.Update(); part_Schraube.InWorkObject = body_Schraube; OriginElements catoriginElements = this.part_Schraube.OriginElements; Reference RefPlanezx = (Reference)catoriginElements.PlaneZX; //Rille erzeugen Slot GewindeRille = shapefac.AddNewSlotFromRef(RefGewinde, RefHelix); Reference RefmyPad = part_Schraube.CreateReferenceFromObject(schaft); HybridShapeSurfaceExplicit GewindestangenSurface = hybridshapefac.AddNewSurfaceDatum(RefmyPad); Reference RefGewindestangenSurface = part_Schraube.CreateReferenceFromObject(GewindestangenSurface); GewindeRille.ReferenceSurfaceElement = RefGewindestangenSurface; Reference RefGewindeRille = part_Schraube.CreateReferenceFromObject(GewindeRille); part_Schraube.Update(); }
private void buttonCreatePoint_Click(object sender, EventArgs e) { Document doc = CATIA.ActiveDocument; PartDocument partDoc = (PartDocument)doc; Part part = partDoc.Part; HybridShapeFactory factory = (HybridShapeFactory)part.HybridShapeFactory; HybridBodies hybridBodiesCur = part.HybridBodies; HybridBody hybridBodyCur = hybridBodiesCur.Item("Geometrical Set.1"); for (int i = 1; i <= 100000; i++) { HybridShapePointCoord pointCur = factory.AddNewPointCoord(100, 200, 300); hybridBodyCur.AppendHybridShape(pointCur); Reference refPoint = part.CreateReferenceFromObject(pointCur); string sSuffix = i.ToString(); string sName = textBoxSelect.Text + sSuffix; factory.ChangeFeatureName(refPoint, sName); part.Update(); } }
//Außenverzahntes Stirnrad public void ErzeugeProfilAußen(Data dat) { //ERZEUGE SKIZZE //Geometrisches Set auswählen und umbennen HybridBodies catHybridBodies1 = hsp_catiaPart.Part.HybridBodies; HybridBody catHybridBody1; try { catHybridBody1 = catHybridBodies1.Item("Geometrisches Set.1"); } catch (Exception) { MessageBox.Show("Kein geometrisches Set gefunden! " + Environment.NewLine + "Ein PART manuell erzeugen und ein darauf achten, dass 'Geometisches Set' aktiviert ist.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Information); return; } catHybridBody1.set_Name("Profile"); Sketches catSketches1 = catHybridBody1.HybridSketches; OriginElements catOriginElements = hsp_catiaPart.Part.OriginElements; Reference catReference1 = (Reference)catOriginElements.PlaneYZ; hsp_catiaProfil = catSketches1.Add(catReference1); //Erstelle Achsensystem ErzeugeAchsensystem(); //Update hsp_catiaPart.Part.Update(); //KOORDINATEN ANLEGEN //Nullpunkt double x0 = 0; double y0 = 0; //Radien und Winkel double teilkreisradius = dat.getTeilkreisdurchmesser() / 2; double hilfskreisradius = teilkreisradius * 0.94; double fußkreisradius = teilkreisradius - (1.25 * dat.getModul()); double kopfkreisradius = teilkreisradius + dat.getModul(); double verrundungsradius = 0.35 * dat.getModul(); double alpha = 20; double beta = 90 / dat.getZähnezahl(); double betarad = Math.PI * beta / 180; double gamma = 90 - (alpha - beta); double gammarad = Math.PI * gamma / 180; double totalangle = 360.0 / dat.getZähnezahl(); double totalanglerad = Math.PI * totalangle / 180; //Schnittpunkte und Koordinaten //Evolventenkreis Center Koordinaten double mittelpunktEvol_x = hilfskreisradius * Math.Cos(gammarad); double mittelpunktEvol_y = hilfskreisradius * Math.Sin(gammarad); //Schnittpkt. der Evolvente und dem Teilkreisradius double punktEvol_x = -teilkreisradius *Math.Sin(betarad); double punktEvol_y = teilkreisradius * Math.Cos(betarad); //Evolvente Radius double EvolventenkreisRadius = Math.Sqrt(Math.Pow((mittelpunktEvol_x - punktEvol_x), 2) + Math.Pow((mittelpunktEvol_y - punktEvol_y), 2)); //Schnittpunkt Kopfkreis und Evolventenkreis double evolventenKopfk_x = Schnittpunkt_X(x0, y0, kopfkreisradius, mittelpunktEvol_x, mittelpunktEvol_y, EvolventenkreisRadius); double evolventenKopfk_y = Schnittpunkt_Y(x0, y0, kopfkreisradius, mittelpunktEvol_x, mittelpunktEvol_y, EvolventenkreisRadius); //Center Verrundung double mittelpunktVer_x = Schnittpunkt_X(x0, y0, fußkreisradius + verrundungsradius, mittelpunktEvol_x, mittelpunktEvol_y, EvolventenkreisRadius + verrundungsradius); double mittelpunktVer_y = Schnittpunkt_Y(x0, y0, fußkreisradius + verrundungsradius, mittelpunktEvol_x, mittelpunktEvol_y, EvolventenkreisRadius + verrundungsradius); //Schnittpunkt Verrundung Evolventenkreis double evolventenVer_x = Schnittpunkt_X(mittelpunktEvol_x, mittelpunktEvol_y, EvolventenkreisRadius, mittelpunktVer_x, mittelpunktVer_y, verrundungsradius); double evolventenVer_y = Schnittpunkt_Y(mittelpunktEvol_x, mittelpunktEvol_y, EvolventenkreisRadius, mittelpunktVer_x, mittelpunktVer_y, verrundungsradius); //Schnittpunkt Verrundung Fußkreis double fußkreisVer_x = Schnittpunkt_X(x0, y0, fußkreisradius, mittelpunktVer_x, mittelpunktVer_y, verrundungsradius); double fußkreisVer_y = Schnittpunkt_Y(x0, y0, fußkreisradius, mittelpunktVer_x, mittelpunktVer_y, verrundungsradius); //Anfangspunkt Fußkreis double hilfswinkel = totalanglerad - Math.Atan(Math.Abs(fußkreisVer_x) / Math.Abs(fußkreisVer_y)); double anfangspunktFußk_x = -fußkreisradius *Math.Sin(hilfswinkel); double anfangspunktFußk_y = fußkreisradius * Math.Cos(hilfswinkel); //Skizze umbenennen und öffnen hsp_catiaProfil.set_Name("Außenverzahntes Stirnrad"); Factory2D catfactory2D1 = hsp_catiaProfil.OpenEdition(); //Punkte in Skizze einzeichnen Point2D point_Ursprung = catfactory2D1.CreatePoint(x0, y0); Point2D pointAnfangFußkreis = catfactory2D1.CreatePoint(anfangspunktFußk_x, anfangspunktFußk_y); Point2D pointFußkreisVer_l = catfactory2D1.CreatePoint(fußkreisVer_x, fußkreisVer_y); Point2D pointFußkreisVer_r = catfactory2D1.CreatePoint(-fußkreisVer_x, fußkreisVer_y); Point2D pointMittelpunktVer_l = catfactory2D1.CreatePoint(mittelpunktVer_x, mittelpunktVer_y); Point2D pointMittelpunktVer_r = catfactory2D1.CreatePoint(-mittelpunktVer_x, mittelpunktVer_y); Point2D pointVerrundungEvol_l = catfactory2D1.CreatePoint(evolventenVer_x, evolventenVer_y); Point2D pointVerrundungEvol_r = catfactory2D1.CreatePoint(-evolventenVer_x, evolventenVer_y); Point2D pointMittelpunktevol_l = catfactory2D1.CreatePoint(mittelpunktEvol_x, mittelpunktEvol_y); Point2D pointMittelpunktevol_r = catfactory2D1.CreatePoint(-mittelpunktEvol_x, mittelpunktEvol_y); Point2D pointEvolventenKopfkreis_l = catfactory2D1.CreatePoint(evolventenKopfk_x, evolventenKopfk_y); Point2D pointEvolventenKopfkreis_r = catfactory2D1.CreatePoint(-evolventenKopfk_x, evolventenKopfk_y); //Kreise in Skizze einzeichnen Circle2D kreisFußkreis = catfactory2D1.CreateCircle(x0, y0, fußkreisradius, 0, Math.PI * 2); kreisFußkreis.CenterPoint = point_Ursprung; kreisFußkreis.StartPoint = pointFußkreisVer_l; kreisFußkreis.EndPoint = pointAnfangFußkreis; Circle2D kreisVerrundung_l = catfactory2D1.CreateCircle(mittelpunktVer_x, mittelpunktVer_y, verrundungsradius, 0, Math.PI * 2); kreisVerrundung_l.CenterPoint = pointMittelpunktVer_l; kreisVerrundung_l.StartPoint = pointFußkreisVer_l; kreisVerrundung_l.EndPoint = pointVerrundungEvol_l; Circle2D kreisEvolventenkreis_l = catfactory2D1.CreateCircle(mittelpunktEvol_x, mittelpunktEvol_y, EvolventenkreisRadius, 0, Math.PI * 2); kreisEvolventenkreis_l.CenterPoint = pointMittelpunktevol_l; kreisEvolventenkreis_l.StartPoint = pointEvolventenKopfkreis_l; kreisEvolventenkreis_l.EndPoint = pointVerrundungEvol_l; Circle2D kreisKopfkreis = catfactory2D1.CreateCircle(x0, y0, kopfkreisradius, 0, Math.PI * 2); kreisKopfkreis.CenterPoint = point_Ursprung; kreisKopfkreis.StartPoint = pointEvolventenKopfkreis_r; kreisKopfkreis.EndPoint = pointEvolventenKopfkreis_l; Circle2D kreisEvolventenkreis_r = catfactory2D1.CreateCircle(-mittelpunktEvol_x, mittelpunktEvol_y, EvolventenkreisRadius, 0, Math.PI * 2); kreisEvolventenkreis_r.CenterPoint = pointMittelpunktevol_r; kreisEvolventenkreis_r.StartPoint = pointVerrundungEvol_r; kreisEvolventenkreis_r.EndPoint = pointEvolventenKopfkreis_r; Circle2D kreisVerrundung_r = catfactory2D1.CreateCircle(-mittelpunktVer_x, mittelpunktVer_y, verrundungsradius, 0, Math.PI * 2); kreisVerrundung_r.CenterPoint = pointMittelpunktVer_r; kreisVerrundung_r.StartPoint = pointVerrundungEvol_r; kreisVerrundung_r.EndPoint = pointFußkreisVer_r; //Skizze schließen hsp_catiaProfil.CloseEdition(); //Update hsp_catiaPart.Part.Update(); //ERSTELLE KREISMUSTER ShapeFactory shapeFactory1 = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory hybridShapeFactory1 = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; Factory2D factory2D1 = hsp_catiaProfil.Factory2D; HybridShapePointCoord ursprung = hybridShapeFactory1.AddNewPointCoord(0, 0, 0); Reference refUrsprung = hsp_catiaPart.Part.CreateReferenceFromObject(ursprung); HybridShapeDirection xRichtung = hybridShapeFactory1.AddNewDirectionByCoord(1, 0, 0); Reference refxRichtung = hsp_catiaPart.Part.CreateReferenceFromObject(xRichtung); CircPattern kreismuster = shapeFactory1.AddNewSurfacicCircPattern(factory2D1, 1, 2, 0, 0, 1, 1, refUrsprung, refxRichtung, false, 0, true, false); kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / dat.getZähnezahl()); AngularRepartition angularRepartition2 = kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(dat.getZähnezahl()) + 1; //Kreismusterenden verbinden Reference refKreismuster = hsp_catiaPart.Part.CreateReferenceFromObject(kreismuster); HybridShapeAssemble verbindung = hybridShapeFactory1.AddNewJoin(refKreismuster, refKreismuster); Reference refVerbindung = hsp_catiaPart.Part.CreateReferenceFromObject(verbindung); hybridShapeFactory1.GSMVisibility(refVerbindung, 0); hsp_catiaPart.Part.MainBody.InsertHybridShape(verbindung); //Update hsp_catiaPart.Part.Update(); //ERSTELLE BLOCK ErzeugeBlock(refVerbindung, shapeFactory1, dat); if (dat.Bohrungsauswahl == 1) { //Skizze Sketches sketchesBohrung = catHybridBody1.HybridSketches; OriginElements catoriginelements = hsp_catiaPart.Part.OriginElements; Reference refmxPlaneX = (Reference)catoriginelements.PlaneYZ; hsp_catiaProfil = catSketches1.Add(refmxPlaneX); //Achsensystem ErzeugeAchsensystem(); //Update hsp_catiaPart.Part.Update(); //Skizze Umbennen hsp_catiaProfil.set_Name("Bohrung"); //Öffnen Factory2D catfactory2D2 = hsp_catiaProfil.OpenEdition(); //Kreis Circle2D KreisFürBohrungsskizze = catfactory2D2.CreateClosedCircle(x0, y0, dat.getBohrung()); //Schließen hsp_catiaProfil.CloseEdition(); //Update hsp_catiaPart.Part.Update(); //Tasche hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part.MainBody; Pocket Tasche = shapeFactory1.AddNewPocket(hsp_catiaProfil, dat.getBreite()); hsp_catiaPart.Part.Update(); } if (dat.Bohrungsauswahl == 2) { //Schnittpunkte und Koordinaten //LH Schnittpunkt Passfederhöhe mit Bohrung double x_AnfangkreisZuPassfeder = -dat.getPassfederbreite() / 2; double y_AnfangkreisZuPassfeder = Math.Sqrt(Math.Pow(dat.getBohrung(), 2) - Math.Pow((dat.getPassfederbreite() / 2), 2)); //LH Schnittpunkt Breite und Höhe double x_Passfederecke = -dat.getPassfederbreite() / 2; double y_Passfederecke = dat.getPassfederhöhe(); //Skizze Sketches sketchesBohrung = catHybridBody1.HybridSketches; OriginElements catoriginelements = hsp_catiaPart.Part.OriginElements; Reference refmxPlaneX = (Reference)catoriginelements.PlaneYZ; hsp_catiaProfil = catSketches1.Add(refmxPlaneX); //Achsensystem ErzeugeAchsensystem(); //Update hsp_catiaPart.Part.Update(); //Umbennen und öffnen hsp_catiaProfil.set_Name("Bohrung mit Passfedernut"); Factory2D catfactory2D2 = hsp_catiaProfil.OpenEdition(); //Punkte in Skizze einzeichnen Point2D POINTLinksAnfangKreisZuPassfeder = catfactory2D2.CreatePoint(x_AnfangkreisZuPassfeder, y_AnfangkreisZuPassfeder); Point2D POINTLinksPassfederEcke = catfactory2D2.CreatePoint(x_Passfederecke, y_Passfederecke); Point2D POINTRechtsPassfederEcke = catfactory2D2.CreatePoint(-x_Passfederecke, y_Passfederecke); Point2D POINTRechtsAnfangKreisZuPassfeder = catfactory2D2.CreatePoint(-x_AnfangkreisZuPassfeder, y_AnfangkreisZuPassfeder); //Linien einzeichnen Line2D PassfederKanteLinks = catfactory2D2.CreateLine(x_AnfangkreisZuPassfeder, y_AnfangkreisZuPassfeder, x_Passfederecke, y_Passfederecke); PassfederKanteLinks.StartPoint = POINTLinksAnfangKreisZuPassfeder; PassfederKanteLinks.EndPoint = POINTLinksPassfederEcke; Line2D PassfederHöhenkante = catfactory2D2.CreateLine(x_Passfederecke, y_Passfederecke, -x_Passfederecke, y_Passfederecke); PassfederHöhenkante.StartPoint = POINTLinksPassfederEcke; PassfederHöhenkante.EndPoint = POINTRechtsPassfederEcke; Line2D PassfederKanteRechts = catfactory2D2.CreateLine(-x_Passfederecke, y_Passfederecke, -x_AnfangkreisZuPassfeder, y_AnfangkreisZuPassfeder); PassfederKanteRechts.StartPoint = POINTRechtsPassfederEcke; PassfederKanteRechts.EndPoint = POINTRechtsAnfangKreisZuPassfeder; Circle2D KreisFürPassfeder = catfactory2D2.CreateCircle(x0, y0, dat.getBohrung(), 0, Math.PI * 2); KreisFürPassfeder.CenterPoint = point_Ursprung; KreisFürPassfeder.EndPoint = POINTRechtsAnfangKreisZuPassfeder; KreisFürPassfeder.StartPoint = POINTLinksAnfangKreisZuPassfeder; //Skizze schließen hsp_catiaProfil.CloseEdition(); //Update hsp_catiaPart.Part.Update(); //Tasche hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part.MainBody; Pocket Tasche = shapeFactory1.AddNewPocket(hsp_catiaProfil, dat.getBreite()); hsp_catiaPart.Part.Update(); } }
public void ErzeugeProfil(Zahnrad Zahnrad1) { // geometrisches Set auswaehlen und umbenennen HybridBodies catHybridBodies1 = hsp_catiaPart.Part.HybridBodies; HybridBody catHybridBody1; try { catHybridBody1 = catHybridBodies1.Item("Geometrisches Set.1"); } catch (Exception) { MessageBox.Show("Kein geometrisches Set gefunden! " + Environment.NewLine + "Ein PART manuell erzeugen und ein darauf achten, dass 'Geometisches Set' aktiviert ist.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Information); return; } catHybridBody1.set_Name("Profile"); // neue Skizze im ausgewaehlten geometrischen Set anlegen Sketches catSketches1 = catHybridBody1.HybridSketches; OriginElements catOriginElements = hsp_catiaPart.Part.OriginElements; Reference catReference1 = (Reference)catOriginElements.PlaneYZ; hsp_catiaProfil = catSketches1.Add(catReference1); // Achsensystem in Skizze erstellen ErzeugeAchsensystem(); // Part aktualisieren hsp_catiaPart.Part.Update(); //Nullpunkt double x0 = 0; double y0 = 0; //Hilfsgrößen von Wilkos PDF double Teilkreisradius = Zahnrad1.d / 2; double Hilfskreisradius = Teilkreisradius * 0.94; double Fußkreisradius = Teilkreisradius - (1.25 * Zahnrad1.m); double Kopfkreisradius = Teilkreisradius + Zahnrad1.m; double Verrundungsradius = 0.35 * Zahnrad1.m; double Alpha = 20; double Beta = 90 / Zahnrad1.z; double Betarad = Math.PI * Beta / 180; double Gamma = 90 - (Alpha - Beta); double Gammarad = Math.PI * Gamma / 180; double Totalangel = 360.0 / Zahnrad1.z; double Totalangelrad = Math.PI * Totalangel / 180; //Punkte //LinkerEvolKreis Mittelp. Koordinaten double xMPEvo_links = Hilfskreisradius * Math.Cos(Gammarad); double yMPEvo_links = Hilfskreisradius * Math.Sin(Gammarad); //Schnittpkt. auf Evolvente und Teilkreisradius double xPunktAufEvolvente = -Teilkreisradius *Math.Sin(Betarad); double yPunktAufEvolvente = Teilkreisradius * Math.Cos(Betarad); //Evolventenkreis Radius double EvolventenkreisRadius = Math.Sqrt(Math.Pow((xMPEvo_links - xPunktAufEvolvente), 2) + Math.Pow((yMPEvo_links - yPunktAufEvolvente), 2)); //Koordinaten Schnittpunkt Kopfkreis und Evolventenkreis double xEvolventenkopfkreis_links = Schnittpunkt_X(x0, y0, Kopfkreisradius, xMPEvo_links, yMPEvo_links, EvolventenkreisRadius); double yEvolventenkopfkreis_links = Schnittpunkt_Y(x0, y0, Kopfkreisradius, xMPEvo_links, yMPEvo_links, EvolventenkreisRadius); //Mittelpunktkoordinaten Verrundung double xMittelpunktVerrundung_links = Schnittpunkt_X(x0, y0, Fußkreisradius + Verrundungsradius, xMPEvo_links, yMPEvo_links, EvolventenkreisRadius + Verrundungsradius); double yMittelpunktVerrundung_links = Schnittpunkt_Y(x0, y0, Fußkreisradius + Verrundungsradius, xMPEvo_links, yMPEvo_links, EvolventenkreisRadius + Verrundungsradius); //Schnittpubktkoordinaten Verrundung - Evolventenkreis double x_SP_EvolventeVerrundung_links = Schnittpunkt_X(xMPEvo_links, yMPEvo_links, EvolventenkreisRadius, xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius); double y_SP_EvolventeVerrundung_links = Schnittpunkt_Y(xMPEvo_links, yMPEvo_links, EvolventenkreisRadius, xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius); //Schnittpunktkoordinaten Verrundung - Fußkreis double x_SP_FußkreisradiusVerrundung_links = Schnittpunkt_X(x0, y0, Fußkreisradius, xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius); double y_SP_FußkreisradiusVerrundung_links = Schnittpunkt_Y(x0, y0, Fußkreisradius, xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius); //Koordinaten Anfangspunkt Fußkreis double Hilfswinkel = Totalangelrad - Math.Atan(Math.Abs(x_SP_FußkreisradiusVerrundung_links) / Math.Abs(y_SP_FußkreisradiusVerrundung_links)); double x_AnfangspunktFußkreis = Fußkreisradius * Math.Sin(Hilfswinkel); double y_AnfangspunktFußkreis = Fußkreisradius * Math.Cos(Hilfswinkel); //Skizze umbenennen und öffnen hsp_catiaProfil.set_Name("Zahnradskizze"); Factory2D catfactory2D1 = hsp_catiaProfil.OpenEdition(); //Nun die Punkte in die Skizze Point2D Ursprung = catfactory2D1.CreatePoint(x0, y0); Point2D EndpunktEvolventenkreis = catfactory2D1.CreatePoint(x_AnfangspunktFußkreis, y_AnfangspunktFußkreis); Point2D VerrundungLinksAnfang = catfactory2D1.CreatePoint(x_SP_FußkreisradiusVerrundung_links, y_SP_FußkreisradiusVerrundung_links); Point2D VerrundungRechtsEnde = catfactory2D1.CreatePoint(-x_SP_FußkreisradiusVerrundung_links, y_SP_FußkreisradiusVerrundung_links); Point2D MPVerrundungLinks = catfactory2D1.CreatePoint(xMittelpunktVerrundung_links, yMittelpunktVerrundung_links); Point2D MPVerrundungRechts = catfactory2D1.CreatePoint(-xMittelpunktVerrundung_links, yMittelpunktVerrundung_links); Point2D VerrundungEndeLinks = catfactory2D1.CreatePoint(x_SP_EvolventeVerrundung_links, y_SP_EvolventeVerrundung_links); Point2D VerrundungAnfangRechts = catfactory2D1.CreatePoint(-x_SP_EvolventeVerrundung_links, y_SP_EvolventeVerrundung_links); Point2D MPEvolventeLinks = catfactory2D1.CreatePoint(xMPEvo_links, yMPEvo_links); Point2D MPEvolventeRechts = catfactory2D1.CreatePoint(-xMPEvo_links, yMPEvo_links); Point2D EvolventenEndeLinks = catfactory2D1.CreatePoint(xEvolventenkopfkreis_links, yEvolventenkopfkreis_links); Point2D EvolventenEndeRechts = catfactory2D1.CreatePoint(-xEvolventenkopfkreis_links, yEvolventenkopfkreis_links); //Kreise Circle2D Fußkreis = catfactory2D1.CreateCircle(x0, y0, Fußkreisradius, 0, Math.PI * 2); Fußkreis.CenterPoint = Ursprung; Fußkreis.StartPoint = EndpunktEvolventenkreis; Fußkreis.EndPoint = VerrundungRechtsEnde; Circle2D VerrundungLinks = catfactory2D1.CreateCircle(xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius, 0, Math.PI * 2); VerrundungLinks.CenterPoint = MPVerrundungLinks; VerrundungLinks.StartPoint = VerrundungLinksAnfang; VerrundungLinks.EndPoint = VerrundungEndeLinks; Circle2D EvolventenkreisLinks = catfactory2D1.CreateCircle(xMPEvo_links, yMPEvo_links, EvolventenkreisRadius, 0, Math.PI * 2); EvolventenkreisLinks.CenterPoint = MPEvolventeLinks; EvolventenkreisLinks.StartPoint = EvolventenEndeLinks; EvolventenkreisLinks.EndPoint = VerrundungEndeLinks; Circle2D Kopfkreis = catfactory2D1.CreateCircle(x0, y0, Kopfkreisradius, 0, Math.PI * 2); Kopfkreis.CenterPoint = Ursprung; Kopfkreis.StartPoint = EvolventenEndeRechts; Kopfkreis.EndPoint = EvolventenEndeLinks; Circle2D EvolventenkreisRechts = catfactory2D1.CreateCircle(-xMPEvo_links, yMPEvo_links, EvolventenkreisRadius, 0, Math.PI * 2); EvolventenkreisRechts.CenterPoint = MPEvolventeRechts; EvolventenkreisRechts.StartPoint = VerrundungAnfangRechts; EvolventenkreisRechts.EndPoint = EvolventenEndeRechts; Circle2D VerrundungRechts = catfactory2D1.CreateCircle(-xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius, 0, Math.PI * 2); VerrundungRechts.CenterPoint = MPVerrundungRechts; VerrundungRechts.StartPoint = VerrundungAnfangRechts; VerrundungRechts.EndPoint = VerrundungRechtsEnde; // Skizzierer verlassen hsp_catiaProfil.CloseEdition(); // Part aktualisieren hsp_catiaPart.Part.Update(); ShapeFactory shapeFactory1 = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory hybridShapeFactory1 = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; Factory2D factory2D1 = hsp_catiaProfil.Factory2D; HybridShapePointCoord ursprung = hybridShapeFactory1.AddNewPointCoord(0, 0, 0); Reference refUrsprung = hsp_catiaPart.Part.CreateReferenceFromObject(ursprung); HybridShapeDirection xRichtung = hybridShapeFactory1.AddNewDirectionByCoord(1, 0, 0); Reference refxRichtung = hsp_catiaPart.Part.CreateReferenceFromObject(xRichtung); CircPattern kreismuster = shapeFactory1.AddNewSurfacicCircPattern(factory2D1, 1, 2, 0, 0, 1, 1, refUrsprung, refxRichtung, false, 0, true, false); kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / Zahnrad1.z); AngularRepartition angularRepartition2 = kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(Zahnrad1.z) + 1; //Kreismusterenden verbinden Reference refKreismuster = hsp_catiaPart.Part.CreateReferenceFromObject(kreismuster); HybridShapeAssemble verbindung = hybridShapeFactory1.AddNewJoin(refKreismuster, refKreismuster); Reference refVerbindung = hsp_catiaPart.Part.CreateReferenceFromObject(verbindung); hybridShapeFactory1.GSMVisibility(refVerbindung, 0); hsp_catiaPart.Part.MainBody.InsertHybridShape(verbindung); hsp_catiaPart.Part.Update(); ErzeugeBlock(Zahnrad1, refVerbindung, shapeFactory1); Sketches sketchesBohrung = catHybridBody1.HybridSketches; OriginElements catoriginelements = hsp_catiaPart.Part.OriginElements; Reference refmxPlaneX = (Reference)catoriginelements.PlaneYZ; hsp_catiaProfil = catSketches1.Add(refmxPlaneX); ErzeugeAchsensystem(); hsp_catiaPart.Part.Update(); hsp_catiaProfil.set_Name("Bohrung"); Factory2D catfactory2D2 = hsp_catiaProfil.OpenEdition(); Circle2D KreisFürBohrungsskizze = catfactory2D2.CreateClosedCircle(x0, y0, Zahnrad1.bd / 2); hsp_catiaProfil.CloseEdition(); hsp_catiaPart.Part.Update(); hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part.MainBody; Pocket Tasche = shapeFactory1.AddNewPocket(hsp_catiaProfil, Zahnrad1.b); hsp_catiaPart.Part.Update(); }
private void ReadCoord_Click(object sender, EventArgs e) { if (datatable.Columns.Count < 1) { InitDataTable(); } this.WindowState = FormWindowState.Minimized; RepeatNum = 0; Array.Clear(GetRepeatRef, 0, GetRepeatRef.Length); ReadType = 2; Selection SelectArc = GetSelect(); if (SelectArc == null || SelectArc.Count2 == 0) { this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; this.TopMost = true; return; } int ERR = 0; for (int i = 1; i <= SelectArc.Count2; i++) { object[] PointCoord = new object[] { -99, -99, -99, -99, -99, -99 }; HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory; SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench"); Reference referenceObject; try { //Temp = PartID.CreateReferenceFromGeometry((AnyObject)SelectArc.Item(i).Value); referenceObject = SelectArc.Item(i).Reference;//!=null? SelectArc.Item(i).Reference: Temp; } catch (Exception) { Boolean LeafProductProcessed; AnyObject Feature = (AnyObject)SelectArc.Item(i).Value; try { String Name = string.Empty; Shape GE = (Shape)SelectArc.Item(i).Value; //Name = GE.get_Name(); //Pad Spad = (Pad)GE.GetItem("Face1"); //Name = Spad.get_Name(); referenceObject = PartID.CreateReferenceFromObject(Feature); PartHyb.AddNewPointCenter(referenceObject); } catch (Exception) { ERR += 1; var LeafProduct = SelectArc.Item(i).LeafProduct; LeafProductProcessed = true; if (LeafProduct.get_Name() == "InvalidLeafProduct") { LeafProductProcessed = false; } if (LeafProductProcessed) { String ShapeName = Feature.get_Name(); VisPropertySet VPS = SelectArc.VisProperties; VPS.SetVisibleColor(255, 0, 0, 0); continue; } else { String ShapeName = Feature.get_Name(); VisPropertySet VPS = SelectArc.VisProperties; VPS.SetVisibleColor(255, 0, 0, 0); continue; } } } Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject); var TName = referenceObject.get_Name(); //读取选择的曲面名称 try { TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标 } catch (Exception) { try { TheMeasurable.GetCOG(PointCoord); } catch (Exception) { ERR += 1; } } if (!KeepName.Checked) { TName = "Rx_" + (datatable.Rows.Count + 1); } WriteObjectToDataGrid(TName, PointCoord, referenceObject, IgRepeat.Checked); //记录数据到DataGridView } SetDataGrid(); if (ERR > 0) { MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!"); } if (RepeatCheck.Checked) { CheckRepeat(SelectArc); } }
private void Creat3dPoint_Click(object sender, EventArgs e)//Creat3dBall_Click { DataGrid.AllowUserToAddRows = false; Creat3dPoint.BackColor = SystemColors.ActiveCaption; ReadType = 2; if (PartID == null) { MessageBox.Show("仿真环境未初始化!请先用工具栏初始化命令初始化运行环境!"); return; } int ERR = 0; if (DataGrid.RowCount < 1) { MessageBox.Show("数据为空,无法建立3D模型!"); return; } HybridBodies Hybs = PartID.HybridBodies; //HybridBody Hyb = Hybs.Item(1); HybridBody Hyb = Hybs.Add(); for (int i = 0; i < DataGrid.RowCount; i++) { HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory; //SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench"); //Reference referenceObject = SelectArc.Item(i).Reference; //Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject); //TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标 string TName; try { TName = DataGrid.Rows[i].Cells[1].Value.ToString(); //读取选择的曲面名称 } catch (Exception) { continue; } HybridShapePointCoord NewPoint = PartHyb.AddNewPointCoord(Convert.ToDouble(DataGrid.Rows[i].Cells[2].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[3].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[4].Value.ToString())); if (KeepName.Checked) { NewPoint.set_Name(TName); } else { NewPoint.set_Name("Rx_" + (i + 1)); } Hyb.AppendHybridShape(NewPoint); PartID.InWorkObject = NewPoint; try { PartID.Update(); } catch (Exception) { ERR += 1; } } if (ERR > 0) { MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!"); } Creat3dPoint.BackColor = Color.Green; ShowCenter(); }
//子线程中 private void Creat3dBall_Click(object sender, EventArgs e)//Creat3dPoint_Click { progressBar.Value = 0; DataGrid.AllowUserToAddRows = false; if (PartID == null) { MessageBox.Show("仿真环境未初始化!请先用工具栏初始化命令初始化运行环境!"); return; } Creat3dBall.BackColor = SystemColors.ActiveCaption; ReadType = 2; int ERR = 0; if (DataGrid.RowCount < 1) { MessageBox.Show("数据为空,无法建立3D模型!"); return; } HybridBodies Hybs = PartID.HybridBodies; HybridBody Hyb = null; //try //{ // Hyb = Hybs.Item("几何图形集.1"); //} //catch (Exception) //{ // Hyb = Hybs.Item("Geometrical Set.1"); //} progressBar.Maximum = DataGrid.RowCount; progressBar.Step = 1; Hyb = Hybs.Add(); for (int i = 0; i < DataGrid.RowCount; i++) { progressBar.PerformStep(); HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory; //SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench"); //Reference referenceObject = SelectArc.Item(i).Reference; //Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject); //TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标 string TName; try { TName = DataGrid.Rows[i].Cells[1].Value.ToString(); //读取选择的曲面名称 } catch (Exception) { continue; } HybridShapePointCoord NewPoint = PartHyb.AddNewPointCoord(Convert.ToDouble(DataGrid.Rows[i].Cells[2].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[3].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[4].Value.ToString())); Reference ShapeRef = PartID.CreateReferenceFromObject(NewPoint); HybridShapeSphere NewShape = PartHyb.AddNewSphere(ShapeRef, null, Convert.ToDouble(BallRadio.Text), -45.000000, 45.000000, 0.000000, 180.000000); NewShape.Limitation = 1; if (KeepName.Checked) { NewPoint.set_Name(TName); NewShape.set_Name(TName); } else { NewPoint.set_Name("Rx_" + (i + 1)); NewShape.set_Name("Rx_" + (i + 1)); } // Hyb.AppendHybridShape(NewPoint); Hyb.AppendHybridShape(NewShape); // PartID.InWorkObject = NewPoint; PartID.InWorkObject = NewShape; try { PartID.Update(); } catch (Exception) { ERR += 1; } Selection SetColor = CatDocument.Selection; VisPropertySet VSet = SetColor.VisProperties; SetColor.Add(NewShape); VSet.SetRealColor(128, 255, 0, 0); SetColor.Clear(); } if (ERR > 0) { MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!"); } Creat3dBall.BackColor = Color.Green; ShowCenter(); progressBar.Value = DataGrid.RowCount; }
public void Stirnzahnrad(Außenverzahnung av) { //Profil erstellen //Nullpunkt double x0 = 0; double y0 = 0; //Hilfsgrößen double Teilkreisradius = av.d / 2; double Hilfskreisradius = Teilkreisradius * 0.94; double Fußkreisradius = Teilkreisradius - (1.25 * av.m); double Kopfkreisradius = Teilkreisradius + av.m; double Verrundungsradius = 0.35 * av.m; double Alpha = 20; double Beta = 90 / av.z; double Betarad = Math.PI * Beta / 180; double Gamma = 90 - (Alpha - Beta); double Gammarad = Math.PI * Gamma / 180; double Totalangel = 360.0 / av.z; double Totalangelrad = Math.PI + Totalangel / 180; //Punkte erzeugen //Kleiner Kreis double xMittelpunktaufEvol_links = Hilfskreisradius * Math.Cos(Gammarad); double yMittelpunktaufEvol_links = Hilfskreisradius * Math.Sin(Gammarad); //Schnittpunkt auf Evolvente und Teilkreisradius double xPunktaufEvolvente = -Teilkreisradius *Math.Sin(Betarad); double yPunktaufEvolvente = Teilkreisradius * Math.Cos(Betarad); //Evolventenkreis Radius double EvolventenkreisRadius = Math.Sqrt(Math.Pow((xMittelpunktaufEvol_links - xPunktaufEvolvente), 2) + Math.Pow((yMittelpunktaufEvol_links - yPunktaufEvolvente), 2)); //Koordinaten Schnittpunkt Kopfkreis und Evolventenkreis double xEvolventenkopfkreis_links = Schnittpunkt_X(x0, y0, Kopfkreisradius, xMittelpunktaufEvol_links, yMittelpunktaufEvol_links, EvolventenkreisRadius); double yEvolventenkopfkreis_links = Schnittpunkt_Y(x0, y0, Kopfkreisradius, xMittelpunktaufEvol_links, yMittelpunktaufEvol_links, EvolventenkreisRadius); //Mittelpunktkoordinaten Verrundung double xMittelpunktVerrundung_links = Schnittpunkt_X(x0, y0, Fußkreisradius + Verrundungsradius, xMittelpunktaufEvol_links, yMittelpunktaufEvol_links, EvolventenkreisRadius + Verrundungsradius); double yMittelpunktVerrundung_links = Schnittpunkt_Y(x0, y0, Fußkreisradius + Verrundungsradius, xMittelpunktaufEvol_links, yMittelpunktaufEvol_links, EvolventenkreisRadius + Verrundungsradius); //Schnittpunktkoordinaten Verrundung - Evolventenkreis double x_SP_EvolventeVerrundung_links = Schnittpunkt_X(xMittelpunktaufEvol_links, yMittelpunktaufEvol_links, EvolventenkreisRadius, xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius); double y_SP_EvolventeVerrundung_links = Schnittpunkt_Y(xMittelpunktaufEvol_links, yMittelpunktaufEvol_links, EvolventenkreisRadius, xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius); //Schnittpunktkoordinaten Verrundung - Fußkreis double x_SP_FußkreisradiusVerrundung_links = Schnittpunkt_X(x0, y0, Fußkreisradius, xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius); double y_SP_FußkreisradiusVerrundung_links = Schnittpunkt_Y(x0, y0, Fußkreisradius, xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius); //Koordinaten Anfangspunkt Fußkreis double Hilfswinkel = Totalangelrad - Math.Atan(Math.Abs(x_SP_FußkreisradiusVerrundung_links) / Math.Abs(y_SP_FußkreisradiusVerrundung_links)); double x_AnfangspunktFußkreis = -Fußkreisradius *Math.Sin(Hilfswinkel); double y_AnfangspunktFußkreis = Fußkreisradius * Math.Cos(Hilfswinkel); //Ende //Skizze umbenennen hsp_catiaProfil.set_Name("Zahnrad-Test"); Factory2D catfactory2D1 = hsp_catiaProfil.OpenEdition(); //Punkte in Skizze Point2D point_Ursprung = catfactory2D1.CreatePoint(x0, y0); Point2D pointAnfangFußkreisLinks = catfactory2D1.CreatePoint(x_AnfangspunktFußkreis, y_AnfangspunktFußkreis); Point2D pointFußkreisVerrundungLinks = catfactory2D1.CreatePoint(x_SP_FußkreisradiusVerrundung_links, y_SP_FußkreisradiusVerrundung_links); Point2D pointFußkreisVerrundungRechts = catfactory2D1.CreatePoint(-x_SP_FußkreisradiusVerrundung_links, y_SP_FußkreisradiusVerrundung_links); Point2D pointMittelpunktVerrundungLinks = catfactory2D1.CreatePoint(xMittelpunktVerrundung_links, yMittelpunktVerrundung_links); Point2D pointMittelpunktVerrundungRechts = catfactory2D1.CreatePoint(-xMittelpunktVerrundung_links, yMittelpunktVerrundung_links); Point2D pointVerrundungEvolventeLinks = catfactory2D1.CreatePoint(x_SP_EvolventeVerrundung_links, y_SP_EvolventeVerrundung_links); Point2D pointVerrundungEvolventeRechts = catfactory2D1.CreatePoint(-x_SP_EvolventeVerrundung_links, y_SP_EvolventeVerrundung_links); Point2D pointMittelpunktevolventeLinks = catfactory2D1.CreatePoint(xMittelpunktaufEvol_links, xMittelpunktaufEvol_links); Point2D pointMittelpunktevolventeRechts = catfactory2D1.CreatePoint(-xMittelpunktaufEvol_links, yMittelpunktaufEvol_links); Point2D pointEvolventenKopfkreisLinks = catfactory2D1.CreatePoint(xEvolventenkopfkreis_links, yEvolventenkopfkreis_links); Point2D pointEvolventenKopfkreisRechts = catfactory2D1.CreatePoint(-xEvolventenkopfkreis_links, yEvolventenkopfkreis_links); //Kreise Circle2D KreisFußkreis = catfactory2D1.CreateCircle(x0, y0, Fußkreisradius, 0, Math.PI * 2); KreisFußkreis.CenterPoint = point_Ursprung; KreisFußkreis.StartPoint = pointFußkreisVerrundungLinks; KreisFußkreis.EndPoint = pointAnfangFußkreisLinks; Circle2D KreisVerrundungLinks = catfactory2D1.CreateCircle(xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius, 0, Math.PI * 2); KreisVerrundungLinks.CenterPoint = pointMittelpunktVerrundungLinks; KreisVerrundungLinks.StartPoint = pointFußkreisVerrundungLinks; KreisVerrundungLinks.EndPoint = pointVerrundungEvolventeLinks; Circle2D KreisEvolventenkreisLinks = catfactory2D1.CreateCircle(xMittelpunktaufEvol_links, yMittelpunktaufEvol_links, EvolventenkreisRadius, 0, Math.PI * 2); KreisEvolventenkreisLinks.CenterPoint = pointMittelpunktevolventeLinks; KreisEvolventenkreisLinks.StartPoint = pointEvolventenKopfkreisLinks; KreisEvolventenkreisLinks.EndPoint = pointVerrundungEvolventeLinks; Circle2D KreisKopfkreis = catfactory2D1.CreateCircle(x0, y0, Kopfkreisradius, 0, Math.PI * 2); KreisKopfkreis.CenterPoint = point_Ursprung; KreisKopfkreis.StartPoint = pointEvolventenKopfkreisRechts; KreisKopfkreis.EndPoint = pointEvolventenKopfkreisLinks; Circle2D KreisEvolventenkreisRechts = catfactory2D1.CreateCircle(-xMittelpunktaufEvol_links, yMittelpunktaufEvol_links, EvolventenkreisRadius, 0, Math.PI * 2); KreisEvolventenkreisRechts.CenterPoint = pointMittelpunktVerrundungRechts; KreisEvolventenkreisRechts.StartPoint = pointVerrundungEvolventeRechts; KreisEvolventenkreisRechts.EndPoint = pointEvolventenKopfkreisRechts; Circle2D KreisVerrundungRechts = catfactory2D1.CreateCircle(-xMittelpunktVerrundung_links, yMittelpunktVerrundung_links, Verrundungsradius, 0, Math.PI * 2); KreisVerrundungRechts.CenterPoint = pointMittelpunktVerrundungRechts; KreisVerrundungRechts.StartPoint = pointVerrundungEvolventeRechts; KreisVerrundungRechts.EndPoint = pointFußkreisVerrundungRechts; //Skizzierer schließen hsp_catiaProfil.CloseEdition(); //Aktualisieren hsp_catiaPart.Part.Update(); //Kreismuster erstellen //Deklarierung ShapeFactory SF = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory HSF = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; Part myPart = hsp_catiaPart.Part; Factory2D Factory2D1 = hsp_catiaProfil.Factory2D; HybridShapePointCoord Ursprung = HSF.AddNewPointCoord(0, 0, 0); Reference RefUrsprung = myPart.CreateReferenceFromObject(Ursprung); HybridShapeDirection XDir = HSF.AddNewDirectionByCoord(1, 0, 0); Reference RefXDir = myPart.CreateReferenceFromObject(XDir); //Kreismuster Daten ausfüllen CircPattern Kreismuster = SF.AddNewSurfacicCircPattern(Factory2D1, 1, 2, 0, 0, 1, 1, RefUrsprung, RefXDir, false, 0, true, false); Kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = Kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / Convert.ToDouble(av.z)); AngularRepartition angularRepartition2 = Kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(av.z) + 1; //geschlossene Kontur herstellen Reference Ref_Kreismuster = myPart.CreateReferenceFromObject(Kreismuster); HybridShapeAssemble Verbindung = HSF.AddNewJoin(Ref_Kreismuster, Ref_Kreismuster); Reference Ref_Verbindung = myPart.CreateReferenceFromObject(Verbindung); HSF.GSMVisibility(Ref_Verbindung, 0); myPart.Update(); Bodies bodies = myPart.Bodies; Body myBody = bodies.Add(); myBody.set_Name("Zahnrad"); myBody.InsertHybridShape(Verbindung); myPart.Update(); }
internal void ErzeugeGewindeHelix(object[] ParameterListe) { // Listen Werte wieder in richtige Datentypen umwandeln int Kopf = Convert.ToInt32(ParameterListe[0]); double Durchmesser = Convert.ToDouble(ParameterListe[1]); double Gewindelänge = Convert.ToDouble(ParameterListe[2]); double Schaftlänge = Convert.ToDouble(ParameterListe[3]); double Steigung = Convert.ToDouble(ParameterListe[4]); int Gewindeart = Convert.ToInt32(ParameterListe[5]); double Schlüsselweite = Convert.ToDouble(ParameterListe[6]); double Kopfhöhe = Convert.ToDouble(ParameterListe[7]); double Kopfdurchmesser = Convert.ToDouble(ParameterListe[8]); int SchraubenrichtungInt = Convert.ToInt32(ParameterListe[9]); double helixAchseStart = Gewindelänge + Schaftlänge + Kopfhöhe; Double P = Steigung; Double Ri = Durchmesser / 2; myPart = hsp_catiaPart.Part; myBody = myPart.MainBody; HSF = (HybridShapeFactory)myPart.HybridShapeFactory; myGewinde = makeGewindeSkizze(ParameterListe); HybridShapeDirection HelixDir = HSF.AddNewDirectionByCoord(1, 0, 0); Reference RefHelixDir = myPart.CreateReferenceFromObject(HelixDir); HybridShapePointCoord HelixStartpunkt = HSF.AddNewPointCoord(helixAchseStart, 0, Ri); Reference RefHelixStartpunkt = myPart.CreateReferenceFromObject(HelixStartpunkt); if (SchraubenrichtungInt == 0) { Helix = HSF.AddNewHelix(RefHelixDir, true, RefHelixStartpunkt, P, Gewindelänge, false, 0, 0, true); } if (SchraubenrichtungInt == 1) { Helix = HSF.AddNewHelix(RefHelixDir, true, RefHelixStartpunkt, P, Gewindelänge, true, 0, 0, true); } Reference RefHelix = myPart.CreateReferenceFromObject(Helix); Reference RefmyGewinde = myPart.CreateReferenceFromObject(myGewinde); hsp_catiaPart.Part.Update(); myPart.InWorkObject = myBody; OriginElements catOriginElements = this.hsp_catiaPart.Part.OriginElements; Reference RefmyPlaneZX = (Reference)catOriginElements.PlaneZX; Slot GewindeRille = SF.AddNewSlotFromRef(RefmyGewinde, RefHelix); Reference RefmyPad = myPart.CreateReferenceFromBRepName( "RSur:(Face:(Brp:(Pad.2;0:(Brp:(Sketch.2;1)));None:();Cf11:());WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", Schaft); if (Kopf == 1 || Kopf == 2) { HybridShapeSurfaceExplicit GewindestangenSurface = HSF.AddNewSurfaceDatum(RefmyPad); Reference RefGewindestangenSurface = myPart.CreateReferenceFromBRepName( "FSur:(Face:(Brp:(Pad.2;0:(Brp:(Sketch.2;1)));None:();Cf12:());WithTemporaryBody;WithoutBuildError;WithInitialFeatureSupport;MFBRepVersion_CXR29)", Schaft); GewindeRille.ReferenceSurfaceElement = RefGewindestangenSurface; } if (Kopf == 3) { //HybridShapeSurfaceExplicit GewindestangenSurface = HSF.AddNewSurfaceDatum(RefmyPad); Reference RefGewindestangenSurface = myPart.CreateReferenceFromBRepName( "FSur:(Face:(Brp:(Pad.1;0:(Brp:(Sketch.2;1)));None:();Cf12:());WithTemporaryBody;WithoutBuildError;WithInitialFeatureSupport;MFBRepVersion_CXR29)", Schaft); GewindeRille.ReferenceSurfaceElement = RefGewindestangenSurface; } myPart.Update(); Reference RefGewindeRille = myPart.CreateReferenceFromObject(GewindeRille); myPart.Update(); }
public void ErzeugeKreismusterMitBohrung(Data dat) { //Erzeuge Kreismuster ShapeFactory SF = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory HSF = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; //Skizze und Referenzen Factory2D Factory2D1 = hsp_catiaProfil.Factory2D; HybridShapePointCoord Ursprung = HSF.AddNewPointCoord(0, 0, 0); Reference RefUrsprung = hsp_catiaPart.Part.CreateReferenceFromObject(Ursprung); HybridShapeDirection XDir = HSF.AddNewDirectionByCoord(1, 0, 0); Reference RefXDir = hsp_catiaPart.Part.CreateReferenceFromObject(XDir); //Kreismuster mit Daten füllen CircPattern Kreismuster = SF.AddNewSurfacicCircPattern(Factory2D1, 1, 2, 0, 0, 1, 1, RefUrsprung, RefXDir, false, 0, true, false); Kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = Kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / dat.getZaehnezahlZahnrad1()); AngularRepartition angularRepartition2 = Kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(dat.getZaehnezahlZahnrad1()) + 1; //geschlossene Kontur Reference Ref_Kreismuster = hsp_catiaPart.Part.CreateReferenceFromObject(Kreismuster); HybridShapeAssemble Verbindung = HSF.AddNewJoin(Ref_Kreismuster, Ref_Kreismuster); Reference Ref_Verbindung = hsp_catiaPart.Part.CreateReferenceFromObject(Verbindung); HSF.GSMVisibility(Ref_Verbindung, 0); hsp_catiaPart.Part.Update(); Bodies bodies = hsp_catiaPart.Part.Bodies; Body myBody = bodies.Add(); myBody.set_Name("Zahnrad"); myBody.InsertHybridShape(Verbindung); hsp_catiaPart.Part.Update(); //Erzeuge Block aus Skizze hsp_catiaPart.Part.InWorkObject = myBody; Pad myPad = SF.AddNewPadFromRef(Ref_Verbindung, dat.getBreiteZahnrad1()); hsp_catiaPart.Part.Update(); //Erzeuge Skizze für Bohrung Reference RefBohrung1 = hsp_catiaPart.Part.CreateReferenceFromBRepName("FSur:(Face:(Brp:(Pad.1;2);None:();Cf11:());WithTemporaryBody;WithoutBuildError;WithInitialFeatureSupport;MonoFond;MFBRepVersion_CXR15)", myPad); Hole catBohrung1 = SF.AddNewHoleFromPoint(0, 0, 0, RefBohrung1, dat.getBreiteZahnrad1()); Length catLengthBohrung1 = catBohrung1.Diameter; catLengthBohrung1.Value = Convert.ToDouble(dat.getTeilkreisdurchmesserZahnrad1() / 2); hsp_catiaPart.Part.Update(); }
//InnenVerzahnung public void ErstelleProfilInnen(Data dat) { //geometrisches set auswählen und umbenennen HybridBodies catHybridBodies_I = hsp_catiaPart.Part.HybridBodies; HybridBody catHybridBody_I; try { catHybridBody_I = catHybridBodies_I.Item("Geometrisches Set.1"); } catch (Exception) { MessageBox.Show("Kein geometrisches Set gefunden!\nEin PART manuell erzeugen und darauf achten, dass ein 'Geometisches Set' aktiviert ist.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error); return; } catHybridBody_I.set_Name("Profile"); //Neue Skizze im ausgewählten geometrischen Set anlegen Sketches catSketches_I = catHybridBody_I.HybridSketches; OriginElements catOriginElements_I = hsp_catiaPart.Part.OriginElements; Reference catReference_I = (Reference)catOriginElements_I.PlaneYZ; hsp_catiaProfil = catSketches_I.Add(catReference_I); //Achsensystem in Skizze erzeugen ErzeugeAchsensystem(); //Part aktualisieren hsp_catiaPart.Part.Update(); hsp_catiaProfil.set_Name("InnenverzahnungBlock"); Factory2D catFactory_I = hsp_catiaProfil.OpenEdition(); Circle2D catC2D_I = catFactory_I.CreateClosedCircle(0, 0, dat.getFußkreisdurchmesser_iZahnrad1()); hsp_catiaProfil.CloseEdition(); hsp_catiaPart.Part.Update(); ShapeFactory SF_I = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory HSF_I = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; //Erzeuge Block aus Skizze hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part.MainBody; Pad myPad = SF_I.AddNewPad(hsp_catiaProfil, dat.getBreiteZahnrad1()); hsp_catiaPart.Part.Update(); //Neue Skizze im ausgewählten geometrischen Set anlegen Sketches catSketches1 = catHybridBody_I.HybridSketches; OriginElements catOriginElements = hsp_catiaPart.Part.OriginElements; Reference catReference1 = (Reference)catOriginElements.PlaneYZ; hsp_catiaProfil = catSketches1.Add(catReference1); //Achsensystem in Skizze erzeugen ErzeugeAchsensystem(); //Part aktualisieren hsp_catiaPart.Part.Update(); //HilfsRadien double d_r = (dat.getModulZahnrad1() * dat.getZaehnezahlZahnrad1()) / 2; double hk_r = d_r * 1.06; double da_r = d_r - (1.25 * dat.getModulZahnrad1()); double df_r = d_r + dat.getModulZahnrad1(); double vd_r = 0.35 * dat.getModulZahnrad1(); //HilfsWinkel double alpha = 20; double beta = 90 / dat.getZaehnezahlZahnrad1(); double beta_r = Math.PI * beta / 180; double gamma = 90 - (alpha - beta); double gamma_r = Math.PI * gamma / 180; double ta = 360.0 / dat.getZaehnezahlZahnrad1(); double ta_r = Math.PI * ta / 180; //Nullpunkte double x0 = 0; double y0 = 0; //MittelPunkt EvolventenKreis double MP_EvolventenKreis_x = hk_r * Math.Cos(gamma_r); double MP_EvolventenKreis_y = hk_r * Math.Sin(gamma_r); // SchnittPunkt Evolventenkreis & Teilkreisradius double SP_EvolventenTeilKreis_x = -d_r *Math.Sin(beta_r); double SP_EvolventenTeilKreis_y = d_r * Math.Cos(beta_r); //Evolventenkreis Radius double Evolventenkreis_r = Math.Sqrt(Math.Pow((MP_EvolventenKreis_x - SP_EvolventenTeilKreis_x), 2) + Math.Pow((MP_EvolventenKreis_y - SP_EvolventenTeilKreis_y), 2)); //SchnittPunkt Evolventenkreis & Kopfkreisradius double SP_EvolventenKopfKreis_x = Schnittpunkt_x(x0, y0, da_r, MP_EvolventenKreis_x, MP_EvolventenKreis_y, Evolventenkreis_r); double SP_EvolventenKopfKreis_y = Schnittpunkt_y(x0, y0, da_r, MP_EvolventenKreis_x, MP_EvolventenKreis_y, Evolventenkreis_r); //MittelPunkt VerrundungsRadius double MP_Verrundung_x = Schnittpunkt_x(x0, y0, df_r + vd_r, MP_EvolventenKreis_x, MP_EvolventenKreis_y, Evolventenkreis_r + vd_r); double MP_Verrundung_y = Schnittpunkt_y(x0, y0, df_r + vd_r, MP_EvolventenKreis_x, MP_EvolventenKreis_y, Evolventenkreis_r + vd_r); //SchnittPunkt Evolventenkreis & Verrundungsradius double SP_EvolventeVerrundung_x = Schnittpunkt_x(MP_EvolventenKreis_x, MP_EvolventenKreis_y, Evolventenkreis_r, MP_Verrundung_x, MP_Verrundung_y, vd_r); double SP_EvolventeVerrundung_y = Schnittpunkt_y(MP_EvolventenKreis_x, MP_EvolventenKreis_y, Evolventenkreis_r, MP_Verrundung_x, MP_Verrundung_y, vd_r); //SchnittPunkt Fußkreis & Verrundungs Radius double SP_FußkreisVerrundungsRadius_x = Schnittpunkt_x(x0, y0, df_r, MP_Verrundung_x, MP_Verrundung_y, vd_r); double SP_FußkreisVerrundungsRadius_y = Schnittpunkt_y(x0, y0, df_r, MP_Verrundung_x, MP_Verrundung_y, vd_r); //StartPunkt Fußkreis Radius double phi = ta_r - Math.Atan(Math.Abs(SP_FußkreisVerrundungsRadius_x) / Math.Abs(SP_FußkreisVerrundungsRadius_y)); double StartPkt_Fußkreis_x = -df_r *Math.Sin(phi); double StartPkt_Fußkreis_y = df_r * Math.Cos(phi); //Skizze umbenennen und öffnen hsp_catiaProfil.set_Name("InnenverzahnungEinzel"); Factory2D catFactory2D1 = hsp_catiaProfil.OpenEdition(); //Punkte Point2D catP2D_Ursprung = catFactory2D1.CreatePoint(x0, y0); Point2D catP2D_StartPkt_Fußkreis = catFactory2D1.CreatePoint(StartPkt_Fußkreis_x, StartPkt_Fußkreis_y); Point2D catP2D_SP_FußkreisVerrundungsRadius1 = catFactory2D1.CreatePoint(SP_FußkreisVerrundungsRadius_x, SP_FußkreisVerrundungsRadius_y); Point2D catP2D_SP_FußkreisVerrundungsRadius2 = catFactory2D1.CreatePoint(-SP_FußkreisVerrundungsRadius_x, SP_FußkreisVerrundungsRadius_y); Point2D catP2D_MP_EvolventenKreis1 = catFactory2D1.CreatePoint(MP_EvolventenKreis_x, MP_EvolventenKreis_y); Point2D catP2D_MP_EvolventenKreis2 = catFactory2D1.CreatePoint(-MP_EvolventenKreis_x, MP_EvolventenKreis_y); Point2D catP2D_SP_EvolventenKopfKreis1 = catFactory2D1.CreatePoint(SP_EvolventenKopfKreis_x, SP_EvolventenKopfKreis_y); Point2D catP2D_SP_EvolventenKopfKreis2 = catFactory2D1.CreatePoint(-SP_EvolventenKopfKreis_x, SP_EvolventenKopfKreis_y); Point2D catP2D_MP_Verrundung1 = catFactory2D1.CreatePoint(MP_Verrundung_x, MP_Verrundung_y); Point2D catP2D_MP_Verrundung2 = catFactory2D1.CreatePoint(-MP_Verrundung_x, MP_Verrundung_y); Point2D catP2D_SP_EvolventeVerrundung1 = catFactory2D1.CreatePoint(SP_EvolventeVerrundung_x, SP_EvolventeVerrundung_y); Point2D catP2D_SP_EvolventeVerrundung2 = catFactory2D1.CreatePoint(-SP_EvolventeVerrundung_x, SP_EvolventeVerrundung_y); //Kreise Circle2D catC2D_Frußkreis = catFactory2D1.CreateCircle(x0, y0, df_r, 0, 0); catC2D_Frußkreis.CenterPoint = catP2D_Ursprung; catC2D_Frußkreis.StartPoint = catP2D_SP_FußkreisVerrundungsRadius1; catC2D_Frußkreis.EndPoint = catP2D_StartPkt_Fußkreis; Circle2D catC2D_Kopfkreis = catFactory2D1.CreateCircle(x0, y0, da_r, 0, 0); catC2D_Kopfkreis.CenterPoint = catP2D_Ursprung; catC2D_Kopfkreis.StartPoint = catP2D_SP_EvolventenKopfKreis2; catC2D_Kopfkreis.EndPoint = catP2D_SP_EvolventenKopfKreis1; Circle2D catC2D_EvolventenKreis1 = catFactory2D1.CreateCircle(MP_EvolventenKreis_x, MP_EvolventenKreis_y, Evolventenkreis_r, 0, 0); catC2D_EvolventenKreis1.CenterPoint = catP2D_MP_EvolventenKreis1; catC2D_EvolventenKreis1.StartPoint = catP2D_SP_EvolventenKopfKreis1; catC2D_EvolventenKreis1.EndPoint = catP2D_SP_EvolventeVerrundung1; Circle2D catC2D_Evolventenkreis2 = catFactory2D1.CreateCircle(-MP_EvolventenKreis_x, MP_EvolventenKreis_y, Evolventenkreis_r, 0, 0); catC2D_Evolventenkreis2.CenterPoint = catP2D_MP_EvolventenKreis2; catC2D_Evolventenkreis2.StartPoint = catP2D_SP_EvolventeVerrundung2; catC2D_Evolventenkreis2.EndPoint = catP2D_SP_EvolventenKopfKreis2; Circle2D catC2D_VerrundungsKreis1 = catFactory2D1.CreateCircle(MP_Verrundung_x, MP_Verrundung_y, vd_r, 0, 0); catC2D_VerrundungsKreis1.CenterPoint = catP2D_MP_Verrundung1; catC2D_VerrundungsKreis1.StartPoint = catP2D_SP_FußkreisVerrundungsRadius1; catC2D_VerrundungsKreis1.EndPoint = catP2D_SP_EvolventeVerrundung1; Circle2D catC2D_VerrundungsKreis2 = catFactory2D1.CreateCircle(-MP_Verrundung_x, MP_Verrundung_y, vd_r, 0, 0); catC2D_VerrundungsKreis2.CenterPoint = catP2D_MP_Verrundung2; catC2D_VerrundungsKreis2.StartPoint = catP2D_SP_EvolventeVerrundung2; catC2D_VerrundungsKreis2.EndPoint = catP2D_SP_FußkreisVerrundungsRadius2; hsp_catiaProfil.CloseEdition(); hsp_catiaPart.Part.Update(); //Skizze und Referenzen Factory2D Factory2D1 = hsp_catiaProfil.Factory2D; HybridShapePointCoord Ursprung = HSF_I.AddNewPointCoord(0, 0, 0); Reference RefUrsprung = hsp_catiaPart.Part.CreateReferenceFromObject(Ursprung); HybridShapeDirection XDir = HSF_I.AddNewDirectionByCoord(1, 0, 0); Reference RefXDir = hsp_catiaPart.Part.CreateReferenceFromObject(XDir); //Kreismuster mit Daten füllen CircPattern Kreismuster = SF_I.AddNewSurfacicCircPattern(Factory2D1, 1, 2, 0, 0, 1, 1, RefUrsprung, RefXDir, false, 0, true, false); Kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = Kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / dat.getZaehnezahlZahnrad1()); AngularRepartition angularRepartition2 = Kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(dat.getZaehnezahlZahnrad1()) + 1; //geschlossene Kontur Reference Ref_Kreismuster = hsp_catiaPart.Part.CreateReferenceFromObject(Kreismuster); HybridShapeAssemble Verbindung = HSF_I.AddNewJoin(Ref_Kreismuster, Ref_Kreismuster); Reference Ref_Verbindung = hsp_catiaPart.Part.CreateReferenceFromObject(Verbindung); HSF_I.GSMVisibility(Ref_Verbindung, 0); hsp_catiaPart.Part.Update(); /*Bodies bodies = hsp_catiaPart.Part.Bodies; * Body myBody = bodies.Add(); * myBody.set_Name("Zahnrad"); * myBody.InsertHybridShape(Verbindung); * * hsp_catiaPart.Part.Update();*/ //Tasche für Innenverzahnung(grob) hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part.MainBody; Pocket catPocketInnen = SF_I.AddNewPocketFromRef(Ref_Verbindung, dat.getBreiteZahnrad1()); hsp_catiaPart.Part.Update(); }
private void ReadCoord_Click(object sender, EventArgs e) { progressBar.Value = 0; if (datatable.Columns.Count < 1) { InitDataTable(); } this.WindowState = FormWindowState.Minimized; RepeatNum = 0; Array.Clear(GetRepeatRef, 0, GetRepeatRef.Length); ReadType = 2; Selection SelectArc = null; CATIA_Class.GetSelect(CatDocument, ref SelectArc, this); if (SelectArc == null || SelectArc.Count2 == 0) { this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; this.TopMost = true; return; } int ERR = 0; progressBar.Maximum = SelectArc.Count2; progressBar.Step = 1; for (int i = 1; i < SelectArc.Count2 + 1; i++) { object[] PointCoord = new object[] { -99, -99, -99, -99, -99, -99 }; HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory; SPAWorkbench TheSPAWorkbench = null; TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench"); // Default Get Coordxyz From Word Reference referenceObject; String ObjType = SelectArc.Item(i).Type; Boolean LeafProductProcessed; string TName = string.Empty; switch (ObjType) { case "HybridShape": { referenceObject = SelectArc.Item(i).Reference; //!=null? SelectArc.Item(i).Reference: Temp; TName = referenceObject.get_Name(); //读取选择的曲面名称 break; } case "Shape": { string Name = string.Empty; Shape shape = (Shape)SelectArc.Item(i).Value; Product product = (Product)SelectArc.Item(i).LeafProduct; TName = product.get_PartNumber(); //读取选择的曲面名称 String RefStr = product.GetMasterShapeRepresentationPathName(); //获取零件路径地址 string[] RefStrArry = RefStr.Split('\\'); if (RefStrArry.Length > 1) { RefStr = RefStrArry.Last(); } Part RefPart = ((PartDocument)CatApplication.Documents.Item(RefStr)).Part; //通过总文档将当前零件转换成PartDocumet TName = RefPart.get_Name(); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (getJTCoord.Checked) { try { //Product PCompoments = (Product)product.Parent; //TName = PCompoments.get_Name(); //referenceObject = PCompoments.CreateReferenceFromName(TName); //Measurable TheMeasurable1 = TheSPAWorkbench.GetMeasurable(referenceObject); } catch (Exception) { throw; } } //String RefStr1 = productPre.GetMasterShapeRepresentationPathName(); //获取零件路径地址 //string[] RefStrArry1 = RefStr1.Split('\\'); //if (RefStrArry.Length > 1) //{ // RefStr1 = RefStrArry1.Last(); //} //string tname= productPre.get_PartNumber(); //referenceObject= productPre.CreateReferenceFromName(TName); //Product RefProduct = ((ProductDocument)CatApplication.Documents.Item("70918")).Product;//通过总文档将当前零件转换成PartDocumet ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// try { //RefPart = (Part)RefPart.Parent; referenceObject = RefPart.CreateReferenceFromObject(shape); } catch (Exception) { MessageBox.Show("请确认当前是否打开了多个窗口,软件识别的零件和您选择的零件不在一个集合!"); return; } break; } default: { AnyObject Feature = (AnyObject)SelectArc.Item(i).Value; try { String Name = string.Empty; Shape GE = (Shape)SelectArc.Item(i).Value; //Name = GE.get_Name(); //Pad Spad = (Pad)GE.GetItem("Face1"); //Name = Spad.get_Name(); referenceObject = PartID.CreateReferenceFromObject(Feature); PartHyb.AddNewPointCenter(referenceObject); } catch (Exception) { ERR += 1; var LeafProduct = SelectArc.Item(i).LeafProduct; LeafProductProcessed = true; if (LeafProduct.get_Name() == "InvalidLeafProduct") { LeafProductProcessed = false; } if (LeafProductProcessed) { String ShapeName = Feature.get_Name(); VisPropertySet VPS = SelectArc.VisProperties; VPS.SetVisibleColor(255, 0, 0, 0); continue; } else { String ShapeName = Feature.get_Name(); VisPropertySet VPS = SelectArc.VisProperties; VPS.SetVisibleColor(255, 0, 0, 0); continue; } } } break; } Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject); try { TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标 } catch (Exception) { try { TheMeasurable.GetCOG(PointCoord); } catch (Exception) { ERR += 1; } } if (!KeepName.Checked) { TName = "Rx_" + (datatable.Rows.Count + 1); } WriteObjectToDataGrid(TName, PointCoord, referenceObject, IgRepeat.Checked); //记录数据到DataGridView try { this.Update(); //Updata Draw } catch (Exception) { } progressBar.PerformStep(); } SetDataGrid(); if (ERR > 0) { MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!"); } if (RepeatCheck.Checked) { CheckRepeat(SelectArc); } DataGrid.AllowUserToAddRows = false; }
public void Stirnzahnrad(MainWindow.Außenverzahnung av) { //Profil Erstellen //Nullpunkt double x0 = 0; double y0 = 0; //Hilfsgrößen double Teilkreisradius = av.d / 2; double Hilfskreisradius = Teilkreisradius * 0.94; double Fußkreisradius = Teilkreisradius - (1.25 * av.m); double Kopfkreisradius = Teilkreisradius + av.m; double Verrundungsradius = 0.35 * av.m; double Alpha = 2; double Alpharad = Math.PI * Alpha / 180; double Beta = 140 / av.z; double Betarad = Math.PI * Beta / 180; double Gamma = 90 - (Alpha - Beta); double Gammarad = Math.PI * Gamma / 180; double Totalangel = 360.0 / av.z; double Totalangelrad = Math.PI * Totalangel / 180; //Punkte //Kopfkreis double xKopfkreis = -Kopfkreisradius *Math.Sin(Alpharad); double yKopfkreis = Kopfkreisradius * Math.Cos(Alpharad); //Fußkreis double xFußkreis = -Fußkreisradius *Math.Sin(Betarad); double yFußkreis = Fußkreisradius * Math.Cos(Betarad); //Koordinaten Anfangspunkt Fußkreis double Hilfswinkel = Totalangelrad - Math.Atan(Math.Abs(xFußkreis) / Math.Abs(yFußkreis)); double x_AnfangspunktFußkreis = Fußkreisradius * Math.Sin(Hilfswinkel); double y_AnfangspunktFußkreis = Fußkreisradius * Math.Cos(Hilfswinkel); //Skizze umbenennen und öffnen hsp_catiaProfil.set_Name("Zahnradskizze"); Factory2D catfactory2D1 = hsp_catiaProfil.OpenEdition(); //Nun die Punkte in die Skizze Point2D point_Ursprung = catfactory2D1.CreatePoint(x0, y0); Point2D point_KopfkreisLinks = catfactory2D1.CreatePoint(xKopfkreis, yKopfkreis); Point2D point_FußkreisLinks = catfactory2D1.CreatePoint(xFußkreis, yFußkreis); Point2D point_KopfkreisRechts = catfactory2D1.CreatePoint(-xKopfkreis, yKopfkreis); Point2D point_FußkreisRechts = catfactory2D1.CreatePoint(-xFußkreis, yFußkreis); Point2D point_AnfangspunktLinks = catfactory2D1.CreatePoint(-x_AnfangspunktFußkreis, y_AnfangspunktFußkreis); //Linien Line2D line_FußkreisKopfkreis = catfactory2D1.CreateLine(xFußkreis, yFußkreis, xKopfkreis, yKopfkreis); line_FußkreisKopfkreis.StartPoint = point_FußkreisLinks; line_FußkreisKopfkreis.EndPoint = point_KopfkreisLinks; Line2D line_KopfkreisFußkreis = catfactory2D1.CreateLine(-xKopfkreis, yKopfkreis, -xFußkreis, yFußkreis); line_KopfkreisFußkreis.StartPoint = point_KopfkreisRechts; line_KopfkreisFußkreis.EndPoint = point_FußkreisRechts; //Kreise Circle2D circle_KopfkreisLinksRechts = catfactory2D1.CreateCircle(x0, y0, Kopfkreisradius, 0, Math.PI * 2); circle_KopfkreisLinksRechts.CenterPoint = point_Ursprung; circle_KopfkreisLinksRechts.EndPoint = point_KopfkreisLinks; circle_KopfkreisLinksRechts.StartPoint = point_KopfkreisRechts; Circle2D circle_AnfangFußkreis = catfactory2D1.CreateCircle(x0, x0, Fußkreisradius, 0, Math.PI * 2); circle_AnfangFußkreis.CenterPoint = point_Ursprung; circle_AnfangFußkreis.EndPoint = point_AnfangspunktLinks; circle_AnfangFußkreis.StartPoint = point_FußkreisLinks; hsp_catiaProfil.CloseEdition(); hsp_catiaPart.Part.Update(); //Profilerstellen Ende //Kreismuster ShapeFactory SF = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; HybridShapeFactory HSF = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; Part myPart = hsp_catiaPart.Part; Factory2D Factory2D2 = hsp_catiaProfil.Factory2D; HybridShapePointCoord Ursprung = HSF.AddNewPointCoord(0, 0, 0); Reference RefUrsprung = myPart.CreateReferenceFromObject(Ursprung); HybridShapeDirection XDir = HSF.AddNewDirectionByCoord(1, 0, 0); Reference RefXDir = myPart.CreateReferenceFromObject(XDir); CircPattern Kreismuster = SF.AddNewSurfacicCircPattern(Factory2D2, 1, 2, 0, 0, 1, 1, RefUrsprung, RefXDir, false, 0, true, false); Kreismuster.CircularPatternParameters = CatCircularPatternParameters.catInstancesandAngularSpacing; AngularRepartition angularRepartition1 = Kreismuster.AngularRepartition; Angle angle1 = angularRepartition1.AngularSpacing; angle1.Value = Convert.ToDouble(360 / Convert.ToDouble(av.z)); AngularRepartition angularRepartition2 = Kreismuster.AngularRepartition; IntParam intParam1 = angularRepartition2.InstancesCount; intParam1.Value = Convert.ToInt32(av.z) + 1; Reference Ref_Kreismuster = myPart.CreateReferenceFromObject(Kreismuster); HybridShapeAssemble Verbindung = HSF.AddNewJoin(Ref_Kreismuster, Ref_Kreismuster); Reference Ref_Verbindung = myPart.CreateReferenceFromObject(Verbindung); HSF.GSMVisibility(Ref_Verbindung, 0); myPart.Update(); Bodies bodies = myPart.Bodies; Body myBody = bodies.Add(); myBody.set_Name("Zahnrad"); myBody.InsertHybridShape(Verbindung); myPart.Update(); myPart.InWorkObject = myBody; Pad myPad = SF.AddNewPadFromRef(Ref_Verbindung, av.t); myPart.Update(); //Bohrung Reference RefBohrung1 = hsp_catiaPart.Part.CreateReferenceFromBRepName("FSur:(Face:(Brp:(Pad.1;2);None:();Cf11:());WithTemporaryBody;WithoutBuildError;WithInitialFeatureSupport;MonoFond;MFBRepVersion_CXR15)", myPad); Hole catBohrung1 = SF.AddNewHoleFromPoint(0, 0, 0, RefBohrung1, 0); Length catLengthBohrung1 = catBohrung1.Diameter; catLengthBohrung1.Value = Convert.ToDouble(av.d / 2); hsp_catiaPart.Part.Update(); }
/// <summary> /// 创建螺纹孔安装面 /// </summary> /// <param name="Spart">对象零件</param> /// <param name="UserSelected">用户选择参考对象2边1面</param> /// <param name="WeightEdge">宽边</param> /// <param name="LengthEdge">长边</param> /// <param name="Weight">宽边宽度</param> /// <param name="Length">长边长度</param> /// <param name="JianDis">孔间距</param> public void CreateThreadHole(Part Spart, Reference[] UserSelected, object[] UserSelectedValue, Edge WeightEdge, Edge LengthEdge, double Weight, double Length, double JianDis) { //对与孔装配的零件执行打孔 object[] SHolePoint = new object[3]; Selection SelectArc = CatActiveDoc.Selection; SelectArc.Clear(); var Result = SelectArc.SelectElement2(InputObjectType(2), "请选择子零件孔支持面!", true); if (Result == "Cancel" || SelectArc == null || SelectArc.Count2 == 0) { return; } Reference SonReface = SelectArc.Item(1).Reference; GetProductByFace SGPB = new GetProductByFace(); Part SonPart = SGPB.GetPart((Face)SelectArc.Item(1).Value); SelectArc.Item(1).GetCoordinates(SHolePoint); SelectArc.Clear(); ShapeFactory NextshapeFactory = (ShapeFactory)SonPart.ShapeFactory; HybridShapeFactory NextHyShapeFactory = (HybridShapeFactory)SonPart.HybridShapeFactory; InstanceFactory NextInf = (InstanceFactory)SonPart.GetCustomerFactory("InstanceFactory"); NextInf.AddInstance(WeightEdge); try { Reference Wref = null; Reference Lref = null; try { object[] LinePoint = new object[12]; object[] LineDirection = new object[12]; SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatActiveDoc.GetWorkbench("SPAWorkbench"); Measurable LengthA = TheSPAWorkbench.GetMeasurable(WeightEdge); Measurable LengthB = TheSPAWorkbench.GetMeasurable(LengthEdge); //LengthA.GetMinimumDistancePoints(, LinePoint); //LengthA.GetDirection(LineDirection); //NextHyShapeFactory.AddNewLineNormal(SonReface, 10, 10, true); Edge WeightEdgeT = (Edge)UserSelectedValue[0]; Edge LengthEdgeT = (Edge)UserSelectedValue[1]; string WeightEdgeName = WeightEdgeT.get_Name(); string LengthEdgeTName = LengthEdgeT.get_Name(); Wref = SonPart.CreateReferenceFromName(null); Lref = SonPart.CreateReferenceFromName(null); WeightEdgeName = Wref.get_Name(); LengthEdgeTName = Lref.get_Name(); SelectArc.Add(WeightEdgeT); SelectArc.Add(LengthEdgeT); SelectArc.Copy(); } catch (Exception e) { throw e; } Hole SonNwhole = NextshapeFactory.AddNewHoleWith2Constraints(Convert.ToDouble(SHolePoint[0]), Convert.ToDouble(SHolePoint[1]), Convert.ToDouble(SHolePoint[2]), Wref, Lref, SonReface, 50);//创建过孔 try { RxSetHoleType(SonNwhole, 10, Weight / 2, 9, RxHoleType.NSmoothHole); } catch (Exception) { RxSetHoleType(SonPart, SonNwhole, 10, Weight / 2, 9, RxHoleType.NSmoothHole, WeightEdge, LengthEdge); } SonPart.Update(); Hole SonNwPinHole = NextshapeFactory.AddNewHoleWith2Constraints(Convert.ToDouble(SHolePoint[0]) + 5, Convert.ToDouble(SHolePoint[1]) + 5, Convert.ToDouble(SHolePoint[2]), UserSelected[0], UserSelected[1], SonReface, 50);//创建销孔 RxSetHoleType(SonNwPinHole, 10, Weight / 2 + JianDis, 8, RxHoleType.PinHole); SonPart.Update(); if (Length <= 60) { RectPattern RPhole = NextshapeFactory.AddNewRectPattern(SonNwhole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔 RPhole.FirstRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing; RPhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing; Spart.Update(); } else { RectPattern RPhole = NextshapeFactory.AddNewRectPattern(SonNwhole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔 RPhole.FirstRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing; RPhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing; RectPattern RPinhole = NextshapeFactory.AddNewRectPattern(SonNwPinHole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔 RPinhole.FirstRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing; RPinhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing; Spart.Update(); } } catch (Exception) { throw; MessageBox.Show("打孔失败!请确定选择是否有误!"); } }
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(); }
internal void PrintTriangles(Vector <double> x, List <int[]> triangles, MathNet.Spatial.Euclidean.Point3D oRoot, MathNet.Spatial.Euclidean.UnitVector3D vDir1, MathNet.Spatial.Euclidean.UnitVector3D vDir2, int iTrans, MathNet.Spatial.Euclidean.Point3D oTrans, bool just2D = false) { Part oPart = oPartDoc.Part; HybridShapeFactory hsf = (HybridShapeFactory)oPart.HybridShapeFactory; HybridBody hb1; try { hb1 = (HybridBody)oPart.HybridBodies.GetItem("Blank Calculator Result"); hb1.get_Name(); oSel.Clear(); oSel.Add(hb1); oSel.Delete(); } catch (Exception) {} hb1 = (HybridBody)oPart.HybridBodies.Add(); hb1.set_Name("Blank Calculator Result"); //CATIA.RefreshDisplay = false; //CATIA.Interactive = false; List <Reference> RsltPoints = new List <Reference>(); MathNet.Spatial.Euclidean.CoordinateSystem Axis = new MathNet.Spatial.Euclidean.CoordinateSystem(oRoot, vDir1, vDir2, vDir1.CrossProduct(vDir2)); if (just2D) { for (int i = 0; i < x.Count / 2; i++) { MathNet.Spatial.Euclidean.Point3D PtMath = new MathNet.Spatial.Euclidean.Point3D(new double[] { x[i * 2], x[i * 2 + 1], 0 }); Point PTCat = hsf.AddNewPointCoord(PtMath.X, PtMath.Y, PtMath.Z); PTCat.Compute(); RsltPoints.Add(oPart.CreateReferenceFromObject(PTCat)); } } else { MathNet.Spatial.Euclidean.Point3D PtMath = new MathNet.Spatial.Euclidean.Point3D(new double[] { x[iTrans * 2], x[iTrans * 2 + 1], 0 }); PtMath = Axis.TransformToCoordSys(PtMath); double[] vecTranslation = new double[] { oTrans.X - PtMath.X, oTrans.Y - PtMath.Y, oTrans.Z - PtMath.Z }; for (int i = 0; i < x.Count / 2; i++) { PtMath = new MathNet.Spatial.Euclidean.Point3D(new double[] { x[i * 2], x[i * 2 + 1], 0 }); PtMath = Axis.TransformToCoordSys(PtMath); Point PTCat = hsf.AddNewPointCoord(PtMath.X + vecTranslation[0], PtMath.Y + vecTranslation[1], PtMath.Z + vecTranslation[2]); PTCat.Compute(); RsltPoints.Add(oPart.CreateReferenceFromObject(PTCat)); } } foreach (int[] item in triangles) { Line lUp = hsf.AddNewLinePtPt(RsltPoints[item[0]], RsltPoints[item[1]]); lUp.Compute(); hb1.AppendHybridShape(lUp); Line l0 = hsf.AddNewLinePtPt(RsltPoints[item[1]], RsltPoints[item[2]]); l0.Compute(); hb1.AppendHybridShape(l0); Line lDown = hsf.AddNewLinePtPt(RsltPoints[item[2]], RsltPoints[item[0]]); lDown.Compute(); hb1.AppendHybridShape(lDown); } //CATIA.RefreshDisplay = true; //CATIA.Interactive = true; }