internal void ErstelleFase(object[] ParameterListe) { bool GewindeFeature = Convert.ToBoolean(ParameterListe[10]); bool GewindeHelix = Convert.ToBoolean(ParameterListe[11]); myBody = hsp_catiaPart.Part.MainBody; hsp_catiaPart.Part.InWorkObject = myBody; if (GewindeHelix) { HybridShapeDirection HelixDir = HSF.AddNewDirectionByCoord(1, 0, 0); Reference RefHelixDir = hsp_catiaPart.Part.CreateReferenceFromObject(HelixDir); Groove myChamfer = SF.AddNewGroove(hsp_catiaProfil_Fase); myChamfer.RevoluteAxis = RefHelixDir; } else { Groove grooveFase = SF.AddNewGroove(hsp_catiaProfil_Fase); GeometricElements element1 = hsp_catiaProfil_Gewinde.GeometricElements; Axis2D axis2D1 = (Axis2D)element1.Item("Absolute Achse"); Reference reference3 = (Reference)axis2D1.GetItem("V-Richtung"); grooveFase.RevoluteAxis = reference3; } hsp_catiaPart.Part.Update(); }
/// <summary> /// 设置无尺寸约束的孔属性 /// </summary> /// <param name="Nwhole">孔对象</param> /// <param name="LengthDis">孔距离长边距离</param> /// <param name="WeightDis">孔距离短边距离</param> /// <param name="Diameter">孔直径</param> /// <param name="HoleType">孔类型</param> /// <param name="Comstraints">1:宽边,2:长边</param> private void RxSetHoleType(Part Tpart, Hole Nwhole, double LengthDis, double WeightDis, double Diameter, RxHoleType HoleType, Edge WidthEdge, Edge LengthEdge) { Nwhole.Type = CatHoleType.catSimpleHole; Nwhole.AnchorMode = CatHoleAnchorMode.catExtremPointHoleAnchor; Nwhole.BottomType = CatHoleBottomType.catVHoleBottom; Limit BottomLimit = Nwhole.BottomLimit; BottomLimit.LimitMode = CatLimitMode.catOffsetLimit; Nwhole.Diameter.Value = Diameter; Nwhole.BottomAngle.Value = 120; Nwhole.ThreadingMode = CatHoleThreadingMode.catSmoothHoleThreading; Sketch Hosketch = Nwhole.Sketch; MECMOD.Constraints HoleConstraint = Hosketch.Constraints; int Cont = Hosketch.GeometricElements.Count; string Type = Hosketch.GeometricElements.Item(2).get_Name(); Point2D HoleCenterPoint = (Point2D)Hosketch.GeometricElements.Item(2); Reference refPoint = Tpart.CreateReferenceFromObject(HoleCenterPoint); if (HoleConstraint.Count < 3) { Tpart.InWorkObject = Hosketch; Factory2D factory2D = Hosketch.OpenEdition(); GeometricElements geWidthEdge = factory2D.CreateProjections(WidthEdge); GeometricElements geLengthEdge = factory2D.CreateProjections(LengthEdge); Geometry2D geoWidthEdge = (Geometry2D)geWidthEdge.Item("标记.1"); Geometry2D geoLengthEdge = (Geometry2D)geLengthEdge.Item("标记.1"); geoWidthEdge.Construction = true; geoLengthEdge.Construction = true; Reference EpWidth = Tpart.CreateReferenceFromObject(geoWidthEdge); Reference EpLength = Tpart.CreateReferenceFromObject(geoLengthEdge); //geo1.Construction = true; Constraint holeConstraintL = HoleConstraint.AddBiEltCst(CatConstraintType.catCstTypeDistance, refPoint, EpWidth); Constraint holeConstraintW = HoleConstraint.AddBiEltCst(CatConstraintType.catCstTypeDistance, refPoint, EpLength); holeConstraintL.Dimension.Value = WeightDis; //孔距离宽边的距离 holeConstraintW.Dimension.Value = LengthDis; //孔距离长边的距离 Hosketch.CloseEdition(); } else { HoleConstraint.Item(1).Dimension.Value = WeightDis; //孔距离宽边的距离 HoleConstraint.Item(2).Dimension.Value = LengthDis; //孔距离长边的距离 } //HoleConstraint.Item(2).Dimension.Value = 10; Nwhole.ThreadSide = CatHoleThreadSide.catRightThreadSide; BottomLimit.LimitMode = CatLimitMode.catUpThruNextLimit; ChangeHoleColor(Nwhole, HoleType); }
//create 2DLine------------------------------------------------------ private void button4_Click(object sender, EventArgs e) { //object[] Crd1 = new object[2]; //object[] Crd2 = new object[2]; object[] CrdSt = new object[2]; object[] CrdEn = new object[2]; try { Point2D strP = lin.StartPoint; Point2D endP = lin.EndPoint; strP.GetCoordinates(CrdSt); endP.GetCoordinates(CrdEn); PartDocument prtDoc = (PartDocument)catia.ActiveDocument; GeometricElements geo2D = (GeometricElements)p1.Parent; Sketch skt = (Sketch)geo2D.Parent; Factory2D fac = skt.OpenEdition(); Line2D lin2 = fac.CreateLine((double)CrdSt[0], (double)CrdSt[1], (double)arrCoord1[0], (double)arrCoord1[1]); lin2.StartPoint = strP; lin2.EndPoint = p1; Line2D lin3 = fac.CreateLine((double)CrdEn[0], (double)CrdEn[1], (double)arrCoord1[0], (double)arrCoord1[1]); lin3.StartPoint = endP; lin3.EndPoint = p1; Line2D lin4 = fac.CreateLine((double)arrCoord1[0], (double)arrCoord1[1], (double)arrCoord2[0], (double)arrCoord2[1]); lin4.StartPoint = p1; lin4.EndPoint = p2; //Line2D lin2 = CreateLine(fac,strP,p1) ; skt.CloseEdition(); } catch (Exception) { MessageBox.Show("선택한 정보가 없습니다."); return; } }
public void Senkkopf(MetrischeGewindegroesse m) { #region SKizze bauen // neue Skizze im ausgewaehlten geometrischen Set anlegen Sketches catSketches1 = catHybridBody1.HybridSketches; OriginElements catOriginElements = hsp_catiaPart.Part.OriginElements; Reference catReference1 = (Reference)catOriginElements.PlaneZX; hsp_catiaProfil = catSketches1.Add(catReference1); // Achsensystem in Skizze erstellen ErzeugeAchsensystem(); hsp_catiaProfil.set_Name("Senkkopf"); // Skizzierer verlassen hsp_catiaProfil.CloseEdition(); // Part aktualisieren hsp_catiaPart.Part.Update(); Factory2D catFactory2D1 = hsp_catiaProfil.OpenEdition(); #endregion #region Profil double tan45 = 1; double tan30 = Math.Sqrt(3) / 3; double winkel; if (m.bezeichnung <= 20) { winkel = tan45; } else { winkel = tan30; } double HoeheP4 = ((m.innenskkopfdurchmesser / 2) - (m.bezeichnung / 2)) / winkel; // erst die Punkte Point2D catPoint2D1 = catFactory2D1.CreatePoint(0, 0); Point2D catPoint2D2 = catFactory2D1.CreatePoint(m.innenskkopfhöhe, 0); Point2D catPoint2D3 = catFactory2D1.CreatePoint(m.innenskkopfhöhe, m.innenskkopfdurchmesser / 2); Point2D catPoint2D4 = catFactory2D1.CreatePoint(HoeheP4, m.innenskkopfdurchmesser / 2); Point2D catPoint2D5 = catFactory2D1.CreatePoint(0, m.bezeichnung / 2); // dann das Profil Line2D catLine2D1 = catFactory2D1.CreateLine(0, 0, m.innenskkopfhöhe, 0); catLine2D1.StartPoint = catPoint2D1; catLine2D1.EndPoint = catPoint2D2; Line2D catLine2D2 = catFactory2D1.CreateLine(m.innenskkopfhöhe, 0, m.innenskkopfhöhe, m.innenskkopfdurchmesser / 2); catLine2D2.StartPoint = catPoint2D2; catLine2D2.EndPoint = catPoint2D3; Line2D catLine2D3 = catFactory2D1.CreateLine(m.innenskkopfhöhe, m.innenskkopfdurchmesser / 2, HoeheP4, m.innenskkopfdurchmesser / 2); catLine2D3.StartPoint = catPoint2D3; catLine2D3.EndPoint = catPoint2D4; Line2D catLine2D4 = catFactory2D1.CreateLine(HoeheP4, m.innenskkopfdurchmesser / 2, 0, m.bezeichnung / 2); catLine2D4.StartPoint = catPoint2D4; catLine2D4.EndPoint = catPoint2D5; Line2D catLine2D5 = catFactory2D1.CreateLine(0, m.bezeichnung / 2, 0, 0); catLine2D5.StartPoint = catPoint2D5; catLine2D5.EndPoint = catPoint2D1; Point2D AxisPoint1 = catFactory2D1.CreatePoint(0, 0); Point2D AxisPoint2 = catFactory2D1.CreatePoint(m.innenskkopfhöhe, 0); Line2D AxisLine1 = catFactory2D1.CreateLine(0, 0, m.innenskkopfhöhe, 0); AxisLine1.StartPoint = AxisPoint1; AxisLine1.EndPoint = AxisPoint2; Reference Axisreference1 = hsp_catiaPart.Part.CreateReferenceFromObject(AxisPoint1); GeometricElements geometricElements1 = hsp_catiaProfil.GeometricElements; Axis2D catAxis2D1 = (Axis2D)geometricElements1.Item("Absolute Achse"); Line2D AxisLine2 = (Line2D)catAxis2D1.GetItem("H-Richtung"); Reference Axisreference2 = hsp_catiaPart.Part.CreateReferenceFromObject(AxisLine2); Constraints constraints1 = hsp_catiaProfil.Constraints; Constraint constraint1 = constraints1.AddBiEltCst(CatConstraintType.catCstTypeOn, Axisreference1, Axisreference2); constraint1.Mode = CatConstraintMode.catCstModeDrivingDimension; Reference Axisreference3 = hsp_catiaPart.Part.CreateReferenceFromObject(AxisLine1); Reference Axisreference4 = hsp_catiaPart.Part.CreateReferenceFromObject(AxisLine2); Constraint constraint2 = constraints1.AddBiEltCst(CatConstraintType.catCstTypeVerticality, Axisreference3, Axisreference4); constraint2.Mode = CatConstraintMode.catCstModeDrivingDimension; hsp_catiaProfil.CenterLine = AxisLine1; // Skizzierer verlassen hsp_catiaProfil.CloseEdition(); // Part aktualisieren hsp_catiaPart.Part.Update(); #endregion #region Shaft hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part.MainBody; ShapeFactory catShapeFactory1 = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; Reference reference1 = hsp_catiaPart.Part.CreateReferenceFromObject(hsp_catiaProfil); SenkkopfShaft = catShapeFactory1.AddNewShaftFromRef(reference1); SenkkopfShaft.SetProfileElement(reference1); SenkkopfShaft.set_Name("Kopf"); // Part aktualisieren hsp_catiaPart.Part.Update(); #endregion #region Offsetebene Reference RefmyPlaneYZ = (Reference)catOriginElements.PlaneYZ; hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part; HybridShapeFactory hybridShapeFactory1 = (HybridShapeFactory)hsp_catiaPart.Part.HybridShapeFactory; HybridShapePlaneOffset OffsetEbene = hybridShapeFactory1.AddNewPlaneOffset(RefmyPlaneYZ, m.innenskkopfhöhe, true); OffsetEbene.set_Name("OffsetEbene"); Reference RefOffsetEbene = hsp_catiaPart.Part.CreateReferenceFromObject(OffsetEbene); HybridBodies hybridBodies1 = hsp_catiaPart.Part.HybridBodies; HybridBody hybridBody1 = hybridBodies1.Item("Profile"); hybridBody1.AppendHybridShape(OffsetEbene); hsp_catiaPart.Part.Update(); Sketches catSketches2 = catHybridBody1.HybridSketches; Sketch SkizzeaufOffset = catSketches2.Add(RefOffsetEbene); hsp_catiaPart.Part.InWorkObject = SkizzeaufOffset; SkizzeaufOffset.set_Name("OffsetSkizze"); // Achsensystem in Skizze erstellen ErzeugeAchsensystem(); // Skizzierer verlassen SkizzeaufOffset.CloseEdition(); // Part aktualisieren hsp_catiaPart.Part.Update(); #endregion #region Innensechskant Factory2D catFactory2D2 = SkizzeaufOffset.OpenEdition(); // Sechskant erzeugen double cos30 = Math.Sqrt(3) / 2; double mSW = m.innensechskant / 2; // erst die Punkte Point2D catPoint2D6 = catFactory2D2.CreatePoint(mSW, tan30 * mSW); Point2D catPoint2D7 = catFactory2D2.CreatePoint(mSW, -(tan30 * mSW)); Point2D catPoint2D8 = catFactory2D2.CreatePoint(0, -(mSW / cos30)); Point2D catPoint2D9 = catFactory2D2.CreatePoint(-mSW, -(tan30 * mSW)); Point2D catPoint2D10 = catFactory2D2.CreatePoint(-mSW, tan30 * mSW); Point2D catPoint2D11 = catFactory2D2.CreatePoint(0, mSW / cos30); // dann die Linien Line2D catLine2D6 = catFactory2D2.CreateLine(mSW, tan30 * mSW, mSW, -(tan30 * mSW)); catLine2D6.StartPoint = catPoint2D6; catLine2D6.EndPoint = catPoint2D7; Line2D catLine2D7 = catFactory2D2.CreateLine(mSW, -(tan30 * mSW), 0, -(mSW / cos30)); catLine2D7.StartPoint = catPoint2D7; catLine2D7.EndPoint = catPoint2D8; Line2D catLine2D8 = catFactory2D2.CreateLine(0, -(mSW / cos30), -mSW, -(tan30 * mSW)); catLine2D8.StartPoint = catPoint2D8; catLine2D8.EndPoint = catPoint2D9; Line2D catLine2D9 = catFactory2D2.CreateLine(-mSW, -(tan30 * mSW), -mSW, (tan30 * mSW)); catLine2D9.StartPoint = catPoint2D9; catLine2D9.EndPoint = catPoint2D10; Line2D catLine2D10 = catFactory2D2.CreateLine(-mSW, (tan30 * mSW), 0, mSW / cos30); catLine2D10.StartPoint = catPoint2D10; catLine2D10.EndPoint = catPoint2D11; Line2D catLine2D11 = catFactory2D2.CreateLine(0, mSW / cos30, mSW, tan30 * mSW); catLine2D11.StartPoint = catPoint2D11; catLine2D11.EndPoint = catPoint2D6; // Part aktualisieren hsp_catiaPart.Part.Update(); #endregion #region Tasche Innensechskant // Hauptkoerper in Bearbeitung definieren hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part.MainBody; // Tasche erzeugen erzeugen ShapeFactory catShapeFactory2 = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; SchlitzPocket = catShapeFactory2.AddNewPocket(SkizzeaufOffset, -m.schlitztiefe); // Block umbenennen SchlitzPocket.set_Name("Innensechskannt"); // Part aktualisieren hsp_catiaPart.Part.Update(); #endregion }
public void Sechskantverrundung(MetrischeGewindegroesse m) { #region SKizze bauen // neue Skizze im ausgewaehlten geometrischen Set anlegen Sketches catSketches1 = catHybridBody1.HybridSketches; OriginElements catOriginElements = hsp_catiaPart.Part.OriginElements; Reference catReference1 = (Reference)catOriginElements.PlaneZX; hsp_catiaProfil = catSketches1.Add(catReference1); // Achsensystem in Skizze erstellen ErzeugeAchsensystem(); hsp_catiaProfil.set_Name("Kopffase"); // Skizzierer verlassen hsp_catiaProfil.CloseEdition(); // Part aktualisieren hsp_catiaPart.Part.Update(); Factory2D catFactory2D1 = hsp_catiaProfil.OpenEdition(); #endregion #region Profil zeichnen double tan30 = Math.Sqrt(3) / 3; double cos30 = Math.Sqrt(3) / 2; double mSW = (m.schluesselweite / 2); double Breite = (mSW / cos30); Point2D catPoint2D1 = catFactory2D1.CreatePoint(m.kopfhoehesechs, mSW * 0.95); Point2D catPoint2D2 = catFactory2D1.CreatePoint(m.kopfhoehesechs, Breite); Point2D catPoint2D3 = catFactory2D1.CreatePoint(m.kopfhoehesechs - (tan30 * (Breite - mSW)), Breite); Line2D catLine2D1 = catFactory2D1.CreateLine(m.kopfhoehesechs, mSW * 0.95, m.kopfhoehesechs, Breite); catLine2D1.StartPoint = catPoint2D1; catLine2D1.EndPoint = catPoint2D2; Line2D catLine2D2 = catFactory2D1.CreateLine(m.kopfhoehesechs, Breite, m.kopfhoehesechs - (tan30 * (Breite - mSW)), Breite); catLine2D2.StartPoint = catPoint2D2; catLine2D2.EndPoint = catPoint2D3; Line2D catLine2D3 = catFactory2D1.CreateLine(m.kopfhoehesechs - (tan30 * (Breite - mSW)), Breite, m.kopfhoehesechs, mSW * 0.95); catLine2D3.StartPoint = catPoint2D3; catLine2D3.EndPoint = catPoint2D1; Point2D AxisPoint1 = catFactory2D1.CreatePoint(0, 0); Point2D AxisPoint2 = catFactory2D1.CreatePoint(m.kopfhoehesechs, 0); Line2D AxisLine1 = catFactory2D1.CreateLine(0, 0, m.kopfhoehesechs, 0); AxisLine1.StartPoint = AxisPoint1; AxisLine1.EndPoint = AxisPoint2; Reference Axisreference1 = hsp_catiaPart.Part.CreateReferenceFromObject(AxisPoint1); GeometricElements geometricElements1 = hsp_catiaProfil.GeometricElements; Axis2D catAxis2D1 = (Axis2D)geometricElements1.Item("Absolute Achse"); Line2D AxisLine2 = (Line2D)catAxis2D1.GetItem("H-Richtung"); Reference Axisreference2 = hsp_catiaPart.Part.CreateReferenceFromObject(AxisLine2); Constraints constraints1 = hsp_catiaProfil.Constraints; Constraint constraint1 = constraints1.AddBiEltCst(CatConstraintType.catCstTypeOn, Axisreference1, Axisreference2); constraint1.Mode = CatConstraintMode.catCstModeDrivingDimension; Reference Axisreference3 = hsp_catiaPart.Part.CreateReferenceFromObject(AxisLine1); Reference Axisreference4 = hsp_catiaPart.Part.CreateReferenceFromObject(AxisLine2); Constraint constraint2 = constraints1.AddBiEltCst(CatConstraintType.catCstTypeVerticality, Axisreference3, Axisreference4); constraint2.Mode = CatConstraintMode.catCstModeDrivingDimension; hsp_catiaProfil.CenterLine = AxisLine1; // Skizzierer verlassen hsp_catiaProfil.CloseEdition(); // Part aktualisieren hsp_catiaPart.Part.Update(); #endregion #region Nut hsp_catiaPart.Part.InWorkObject = hsp_catiaPart.Part.MainBody; ShapeFactory catShapeFactory1 = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory; Reference reference1 = hsp_catiaPart.Part.CreateReferenceFromObject(hsp_catiaProfil); SechskantGroove = catShapeFactory1.AddNewGrooveFromRef(reference1); SechskantGroove.SetProfileElement(reference1); SechskantGroove.set_Name("Kopfnut"); // Part aktualisieren hsp_catiaPart.Part.Update(); #endregion }