// Circle (finished) public static string ExportCircle(SketchCircle circle, string entityName) { double radius = Math.Round(circle.Radius, 4) * factor; double x = Math.Round(circle.CenterSketchPoint.Geometry.X, 4) * factor; double y = Math.Round(circle.CenterSketchPoint.Geometry.Y, 4) * factor; string radiusString = entityName + "_Radius"; string xCoordinate = entityName + "_CenterX"; string yCoordinate = entityName + "_CenterY"; //create parameter Parameter param1 = new Parameter(radiusString, "radius of " + entityName, "float", radius, 0.1); Parameter param2 = new Parameter(xCoordinate, "X-Coordinate of " + entityName, "float", x, 0.1); Parameter param3 = new Parameter(yCoordinate, "Y-Coordinate of " + entityName, "float", y, 0.1); Shakespeare.ListOfParameter.Add(param1); Shakespeare.ListOfParameter.Add(param2); Shakespeare.ListOfParameter.Add(param3); string javaScriptVariable = "var " + entityName + " = CAG.circle (" + "{ center:[params." + xCoordinate + ", params." + yCoordinate + "], " + "radius: params." + radiusString + "});"; return("\t" + javaScriptVariable); }
private void CreatePart_Click(object sender, EventArgs e) { if (inventor == null) { MessageBox.Show("No inventor instance detected", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } PartDocument doc = inventor.Documents.Add(DocumentTypeEnum.kPartDocumentObject, null, true) as PartDocument; doc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"]["Author"].Value = "Vladyslav Romanchuk"; //User-defined property doc.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"].Add("Parts R Us", "Supplier"); PartComponentDefinition partDefinition = (PartComponentDefinition)doc.ComponentDefinition; // Create a 2D sketch on the X-Y plane. PlanarSketch sketch1 = (PlanarSketch)partDefinition.Sketches.Add(partDefinition.WorkPlanes[3]); TransientGeometry tg = inventor.TransientGeometry; Point2d[] points = new Point2d[5] { tg.CreatePoint2d(0, 0), tg.CreatePoint2d(0, 20), tg.CreatePoint2d(20, 20), tg.CreatePoint2d(20, -10), tg.CreatePoint2d(10, -10) }; SketchLine[] lines = new SketchLine[5]; lines[0] = sketch1.SketchLines.AddByTwoPoints(points[0], points[1]); for (int i = 1; i < lines.Length - 1; i++) { lines[i] = sketch1.SketchLines.AddByTwoPoints(lines[i - 1].EndSketchPoint, points[i + 1]); } sketch1.SketchArcs.AddByCenterStartEndPoint(tg.CreatePoint2d(10, 0), lines[3].EndSketchPoint, lines[0].StartSketchPoint, false); //Extrude Profile profile = sketch1.Profiles.AddForSolid(); ExtrudeDefinition extrudeDefinition = partDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kNewBodyOperation); extrudeDefinition.SetDistanceExtent(6, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); ExtrudeFeature extrude = (ExtrudeFeature)partDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition); //second scatch Face topCap = extrude.EndFaces[1]; sketch1 = partDefinition.Sketches.Add(topCap, false); Point2d center = sketch1.ModelToSketchSpace(tg.CreatePoint(2.5, 1.5, 1.5)); SketchCircle Circle = sketch1.SketchCircles.AddByCenterRadius(center, 1); profile = sketch1.Profiles.AddForSolid(true, null, null); extrudeDefinition = partDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kJoinOperation); extrudeDefinition.SetDistanceExtent(4, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); extrude = (ExtrudeFeature)partDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition); Edges cylinderEdges = extrude.SideFaces[1].Edges; EdgeCollection filletEdges = inventor.TransientObjects.CreateEdgeCollection(null); //foreach (var el in cylinderEdges) // filletEdges.Add(el); filletEdges.Add(cylinderEdges[2]); //adding fillet partDefinition.Features.FilletFeatures.AddSimple(filletEdges, 0.25, false, false, false, false, false, true); //doc.SaveAs("D:\\SaveTest2.ipt", false); }
// Circle public void exportCircle(SketchCircle circle, String varname) { double radius = circle.Radius; using (StreamWriter outputFile = new StreamWriter(jscadPath, true)) { outputFile.WriteLine("var " + varname + "= circle({r: " + convertCommaToDot(radius) + "})); "); } }
/// <summary> /// select a SketchLine and SketchCircle and get their intersect points /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button2_Click(object sender, EventArgs e) { if (((mApp.ActiveDocument != null))) { if ((mApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject)) { PartDocument oDoc = mApp.ActiveDocument as PartDocument; if ((oDoc.SelectSet.Count == 2)) { if (((oDoc.SelectSet[1]) is SketchLine & (oDoc.SelectSet[2]) is SketchCircle)) { SketchLine oSketchLine = oDoc.SelectSet[1] as SketchLine; SketchCircle oSketchCircle = oDoc.SelectSet[2] as SketchCircle; Line2d oLine2d = mApp.TransientGeometry.CreateLine2d(oSketchLine.Geometry.StartPoint, oSketchLine.Geometry.Direction); Circle2d oCircle2d = oSketchCircle.Geometry; ObjectsEnumerator objectsEnum = oLine2d.IntersectWithCurve(oCircle2d, 0.0001); if ((objectsEnum == null)) { System.Windows.Forms.MessageBox.Show("No intersection between extended Line and Circle", "BRep Sample"); return; } string strResult = "Intersection point(s): \n"; int i = 0; for (i = 1; i <= objectsEnum.Count; i++) { Point2d oPoint = objectsEnum[i] as Point2d; strResult += "[" + oPoint.X.ToString("F2") + ", " + oPoint.Y.ToString("F2") + "]" + "\n"; } System.Windows.Forms.MessageBox.Show(strResult, "BRep Sample"); return; } else { System.Windows.Forms.MessageBox.Show("Entity 1 must be a SketchLine, Entity 2 must be a SketchCircle", "BRep Sample"); return; } } else { System.Windows.Forms.MessageBox.Show("Incorrect selection of sketch entities", "BRep Sample"); return; } } } }
private static bool CreateCircle(DataRow iRow, Sheet iSheet, DrawingSketch iSketch, TransientGeometry tg) { bool isCircleCreated = false; try { int circleInst = Int32.Parse(iRow.ItemArray[iRow.ItemArray.Count() - 1].ToString()); int startNum = 0; string tempCoord = iRow.ItemArray[4].ToString(); string[] coord = tempCoord.Split(','); Double initX = Double.Parse(coord[0]); Double initY = Double.Parse(coord[1]); Double hOffset = Double.Parse(iRow.ItemArray[5].ToString()); Double vOffset = Double.Parse(iRow.ItemArray[6].ToString()); Double radius = Double.Parse(iRow.ItemArray[3].ToString()) / 2; do { iSketch.Edit(); Point2d cen; if (startNum < circleInst / 2) { cen = tg.CreatePoint2d(initX + (hOffset * startNum), initY); } else { cen = tg.CreatePoint2d(initX + (hOffset * (startNum - 4)), initY + vOffset); } SketchCircle iCircle = iSketch.SketchCircles.AddByCenterRadius(cen, 2); GeometryIntent oGeo1 = iSheet.CreateGeometryIntent(iCircle, null); iSketch.ExitEdit(); iSheet.DrawingDimensions.GeneralDimensions.AddDiameter(cen, oGeo1, false, false, false); isCircleCreated = true; startNum += 1; } while (startNum < circleInst); } catch (Exception e) { Console.WriteLine(e.Message); } return(isCircleCreated); }
//creating a new sketched symbol definition object and // inserting it into the active sheet. // This sample consists of two subs. // The first demonstrates the creation of a sketched symbol definition and // the second inserts it into the active sheet. // To run the sample have a drawing document open and run the CreateSketchedSymbolDefinition Sub. // After this you can run the InsertSketchedSymbolOnSheet to insert the sketched symbol into the active sheet. // The insertion sub demonstrates the use of the insertion point in the symbol's definition while inserting the symbol. /// <summary> /// creating a new sketched symbol definition object ''' /// </summary> /// <remarks></remarks> public void CreateSketchedSymbolDefinition() { // Set a reference to the drawing document. // This assumes a drawing document is active. DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument; // Create the new sketched symbol definition. SketchedSymbolDefinition oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Circular Callout"); // Open the sketched symbol definition's sketch for edit. This is done by calling the Edit // method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates // a copy of the sketched symbol definition's and opens it for edit. DrawingSketch oSketch = null; oSketchedSymbolDef.Edit(out oSketch); TransientGeometry oTG = _InvApplication.TransientGeometry; // Use the functionality of the sketch to add sketched symbol graphics. SketchLine oSketchLine = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(20, 0)); SketchCircle oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(22, 0), 2); oSketch.GeometricConstraints.AddCoincident((SketchEntity)oSketchLine.EndSketchPoint, (SketchEntity)oSketchCircle); // Make the starting point of the sketch line the insertion point oSketchLine.StartSketchPoint.InsertionPoint = true; // Add a prompted text field at the center of the sketch circle. string sText = null; sText = "<Prompt>Enter text 1</Prompt>"; Inventor.TextBox oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(22, 0), sText); oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle; oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter; oSketchedSymbolDef.ExitEdit(true); }
void createPart1() { // create a new part PartDocument oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject); PartComponentDefinition oDef = oDoc.ComponentDefinition; TransientGeometry oTG = mApp.TransientGeometry; // create sketch elements PlanarSketch oSketch = oDef.Sketches.Add(oDef.WorkPlanes[3]); SketchCircle oCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), 1); Profile oProfile = oSketch.Profiles.AddForSolid(); // create a cylinder feature ExtrudeDefinition oExtrudDef = oDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation); oExtrudDef.SetDistanceExtent(5, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature oExtrudeF = oDef.Features.ExtrudeFeatures.Add(oExtrudDef); //add an attribute to cylinder face Face oFace = oExtrudeF.SideFaces[1]; AttributeSet oAttSet = default(AttributeSet); Inventor.Attribute oAtt = null; oAttSet = oFace.AttributeSets.Add("demoAttset"); oAtt = oAttSet.Add("demoAtt", ValueTypeEnum.kStringType, "namedEdge"); if (System.IO.File.Exists("c:\temp\test1.ipt")) { System.IO.File.Delete("c:\temp\test1.ipt"); } oDoc.SaveAs("c:\\temp\\test1.ipt", false); }
private void button2_Click(object sender, EventArgs e) { try { ThisApplication = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application"); if (ThisApplication != null) { label1.Text = "Inventor запущен."; } } catch { MessageBox.Show("Запустите Inventor!"); return; } //Перевод мм в см D /= 10; d /= 10; B /= 10; r /= 10; r1 /= 10; //Sketch.. New_document_Name("Подшипник"); oPartDoc["Подшипник"].DisplayName = "Подшипник"; PlanarSketch oSketch = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]); SketchPoint[] point = new SketchPoint[101]; SketchArc[] arc = new SketchArc[101]; SketchPoint[] center_arc = new SketchPoint[101]; SketchLine[] lines = new SketchLine[101]; SketchCircle[] circles = new SketchCircle[101]; //Координаты точек вершин прямоугольника point[0] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2)); point[1] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, d / 2)); point[2] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, d / 2)); point[3] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2)); point[4] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (D / 2 - d / 2) / 3 + d / 2)); point[5] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (D / 2 - d / 2) * 2 / 3 + d / 2)); point[6] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, (D / 2 - d / 2) / 3 + d / 2)); point[7] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, (D / 2 - d / 2) * 2 / 3 + d / 2)); //Соединение верхнего прямоугольника lines[0] = oSketch.SketchLines.AddByTwoPoints(point[0], point[5]); lines[1] = oSketch.SketchLines.AddByTwoPoints(point[3], point[7]); lines[2] = oSketch.SketchLines.AddByTwoPoints(point[0], point[3]); lines[3] = oSketch.SketchLines.AddByTwoPoints(point[5], point[7]); //Содинение вершин нижнего прямоугольника lines[4] = oSketch.SketchLines.AddByTwoPoints(point[4], point[1]); lines[5] = oSketch.SketchLines.AddByTwoPoints(point[1], point[2]); lines[6] = oSketch.SketchLines.AddByTwoPoints(point[4], point[6]); lines[7] = oSketch.SketchLines.AddByTwoPoints(point[6], point[2]); //Ось вращения двух прямоугольников point[8] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0)); point[9] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0)); lines[8] = oSketch.SketchLines.AddByTwoPoints(point[8], point[9]); //Closing the sketch oTrans["Подшипник"].End(); //Вращение Profile oProfile = default(Profile); oProfile = (Profile)oSketch.Profiles.AddForSolid(); RevolveFeature revolvefeature = default(RevolveFeature); revolvefeature = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile, lines[8], PartFeatureOperationEnum.kJoinOperation); /* * Новый скетч 1 */ //Новый sketch с окружностями PlanarSketch oSketch1 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]); Transaction oTrans1 = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample"); //Окружности point[10] = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, (D / 2 + d / 2) / 2)); point[11] = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, (D / 2 + d / 2) / 2)); circles[0] = oSketch1.SketchCircles.AddByCenterRadius(point[10], (D / 2 - d / 2) / 3.6); circles[1] = oSketch1.SketchCircles.AddByCenterRadius(point[11], (D / 2 - d / 2) / 3.6); //Ось вращения подшипника point[12] = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0)); point[13] = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0)); lines[9] = oSketch1.SketchLines.AddByTwoPoints(point[12], point[13]); //Closing the sketch 1 oTrans1.End(); //Выдавливание выемки Profile oProfile1 = default(Profile); oProfile1 = (Profile)oSketch1.Profiles.AddForSolid(); RevolveFeature revolvefeature1 = default(RevolveFeature); revolvefeature1 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile1, lines[9], PartFeatureOperationEnum.kCutOperation); /* * New sketch 4 */ //New sketch 4 PlanarSketch oSketch4 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]); Transaction oTrans4 = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample"); //Четырехугольник для вычетания выдавливания по краям подшипнника (слева) point[20] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2 * 0.7916875 - 0.1)); point[21] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2 * 0.9275625)); point[22] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * 0.861125)); point[23] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * 0.7916875 - 0.1)); lines[12] = oSketch4.SketchLines.AddByTwoPoints(point[20], point[21]); lines[13] = oSketch4.SketchLines.AddByTwoPoints(point[20], point[23]); lines[14] = oSketch4.SketchLines.AddByTwoPoints(point[21], point[22]); lines[15] = oSketch4.SketchLines.AddByTwoPoints(point[22], point[23]); point[26] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2 * 0.7916875 - 0.1)); point[27] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2 * 0.9275625)); point[28] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * 0.861125)); point[29] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * 0.7916875 - 0.1)); lines[17] = oSketch4.SketchLines.AddByTwoPoints(point[26], point[27]); lines[18] = oSketch4.SketchLines.AddByTwoPoints(point[27], point[28]); lines[19] = oSketch4.SketchLines.AddByTwoPoints(point[28], point[29]); lines[20] = oSketch4.SketchLines.AddByTwoPoints(point[29], point[26]); //ось point[24] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0)); point[25] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0)); lines[16] = oSketch4.SketchLines.AddByTwoPoints(point[24], point[25]); //Closing the sketch 4 oTrans4.End(); //Вычетание началось (слева) Profile oProfile4 = default(Profile); oProfile4 = (Profile)oSketch4.Profiles.AddForSolid(); RevolveFeature revolveFeature4 = default(RevolveFeature); revolveFeature4 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile4, lines[16], PartFeatureOperationEnum.kCutOperation); /* * New sketch 2 */ //Новый sketch с окружностями PlanarSketch oSketch2 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]); Transaction oTrans2 = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample"); //Задаю полуокружность! point[14] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * n)); point[15] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * m)); lines[10] = oSketch2.SketchLines.AddByTwoPoints(point[14], point[15]); point[16] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, (D / 2 + d / 2) / 2)); arc[0] = oSketch2.SketchArcs.AddByCenterStartEndPoint(point[16], point[15], point[14], false); //Closing the sketch 2 oTrans2.End(); //Выдавливание окружности 1 Profile oProfile2 = default(Profile); oProfile2 = (Profile)oSketch2.Profiles.AddForSolid(); RevolveFeature revolveFeature2 = default(RevolveFeature); revolveFeature2 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile2, lines[10], PartFeatureOperationEnum.kJoinOperation); //New sketch 3 PlanarSketch oSketch3 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]); Transaction oTrans3 = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample"); //Задаю окружность второго шарика point[17] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * n)); point[18] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * m)); lines[11] = oSketch3.SketchLines.AddByTwoPoints(point[17], point[18]); point[19] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, (D / 2 + d / 2) / 2)); arc[1] = oSketch3.SketchArcs.AddByCenterStartEndPoint(point[19], point[17], point[18], false); //Closing the sketch 3 oTrans3.End(); //Вращение шарика Profile oProfile3 = default(Profile); oProfile3 = (Profile)oSketch3.Profiles.AddForSolid(); RevolveFeature revolveFeature3 = default(RevolveFeature); revolveFeature3 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile3, lines[11], PartFeatureOperationEnum.kJoinOperation); WorkAxis oAxis = oCompDef["Подшипник"].WorkAxes[1]; ObjectCollection oObjCollection = ThisApplication.TransientObjects.CreateObjectCollection(); oObjCollection.Add(revolveFeature3); CircularPatternFeature CircularPatternFeature = oCompDef["Подшипник"].Features.CircularPatternFeatures.Add(oObjCollection, oAxis, true, count, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute); WorkAxis oAxis1 = oCompDef["Подшипник"].WorkAxes[1]; ObjectCollection oObjCollection1 = ThisApplication.TransientObjects.CreateObjectCollection(); oObjCollection1.Add(revolveFeature2); CircularPatternFeature oCircularPatternFeature1 = oCompDef["Подшипник"].Features.CircularPatternFeatures.Add(oObjCollection1, oAxis1, true, count, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute); /*НАЧАЛО ВАЛА * НАЧАЛО ВАЛА * НАЧАЛО ВАЛА * НАЧАЛО ВАЛА */ //New sketch 5 PlanarSketch oSketch5 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]); Transaction oTrans5 = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample"); //Ось вала point[30] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0)); point[31] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0.7, 0)); lines[16] = oSketch5.SketchLines.AddByTwoPoints(point[30], point[31]); //Эскиз вала point[32] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (((D / 2 - d / 2) / 3 + d / 2) + d / 2) / 2)); point[33] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, d / 2)); lines[17] = oSketch5.SketchLines.AddByTwoPoints(point[32], point[33]); point[34] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(-0.1 * k, (((D / 2 - d / 2) / 3 + d / 2) + d / 2) / 2)); lines[18] = oSketch5.SketchLines.AddByTwoPoints(point[32], point[34]); point[35] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(-0.1 * k, 0)); lines[19] = oSketch5.SketchLines.AddByTwoPoints(point[34], point[35]); point[36] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k, d / 2)); lines[20] = oSketch5.SketchLines.AddByTwoPoints(point[33], point[36]); point[37] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k, 0.4 * k)); lines[21] = oSketch5.SketchLines.AddByTwoPoints(point[36], point[37]); point[38] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k + 0.3 * k, 0.4 * k)); lines[22] = oSketch5.SketchLines.AddByTwoPoints(point[37], point[38]); point[39] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k + 0.3 * k, 0)); lines[23] = oSketch5.SketchLines.AddByTwoPoints(point[38], point[39]); lines[24] = oSketch5.SketchLines.AddByTwoPoints(point[39], point[35]); //Closing oTrans5.End(); //Вращение вала Profile oProfile5 = default(Profile); oProfile5 = (Profile)oSketch5.Profiles.AddForSolid(); RevolveFeature revolveFeature5 = default(RevolveFeature); revolveFeature5 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile5, lines[16], PartFeatureOperationEnum.kJoinOperation); //Вращение вала /*Profile oProfile5 = default(Profile); * oProfile5 = (Profile)oSketch5.Profiles.AddForSolid(); * RevolveFeature revolveFeature5 = default(RevolveFeature); * revolveFeature5 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile5, lines[16], PartFeatureOperationEnum.kJoinOperation);*/ //см в мм D *= 10; d *= 10; B *= 10; r *= 10; r1 *= 10; }
/// <summary> /// Add iMate definitions using AddMateiMateDefinition and AddInsertiMateDefinition. /// </summary> /// <remarks></remarks> public void CreateiMateDefinition() { // Create a new part document, using the default part template. PartDocument oPartDoc = (PartDocument)_InvApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, _InvApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject)); // Set a reference to the component definition. PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; // Create a new sketch on the X-Y work plane. PlanarSketch oSketch = default(PlanarSketch); oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]); // Set a reference to the transient geometry object. TransientGeometry oTransGeom = default(TransientGeometry); oTransGeom = _InvApplication.TransientGeometry; // Draw a 4cm x 3cm rectangle with the corner at (0,0) SketchEntitiesEnumerator oRectangleLines = default(SketchEntitiesEnumerator); oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle(oTransGeom.CreatePoint2d(0, 0), oTransGeom.CreatePoint2d(4, 3)); // Create a profile. Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); // Create a base extrusion 1cm thick. ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation); oExtrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kNegativeExtentDirection); ExtrudeFeature oExtrude1 = default(ExtrudeFeature); oExtrude1 = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef); // Get the top face of the extrusion to use for creating the new sketch. Face oFrontFace = default(Face); oFrontFace = oExtrude1.StartFaces[1]; // Create a new sketch on this face, but use the method that allows you to // control the orientation and orgin of the new sketch. oSketch = oCompDef.Sketches.AddWithOrientation(oFrontFace, oCompDef.WorkAxes[1], true, true, oCompDef.WorkPoints[1]); // Create a sketch circle with the center at (2, 1.5). SketchCircle oCircle = default(SketchCircle); oCircle = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(2, 1.5), 0.5); // Create a profile. oProfile = oSketch.Profiles.AddForSolid(); // Create the second extrude (a hole). ExtrudeFeature oExtrude2 = default(ExtrudeFeature); oExtrude2 = oCompDef.Features.ExtrudeFeatures.AddByThroughAllExtent(oProfile, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kCutOperation); // Create a mate iMateDefinition on a side face of the first extrude. MateiMateDefinition oMateiMateDefinition = default(MateiMateDefinition); oMateiMateDefinition = oCompDef.iMateDefinitions.AddMateiMateDefinition(oExtrude1.SideFaces[1], 0, InferredTypeEnum.kNoInference, null, "MateA"); // Create a match list of names to use for the next iMateDefinition. string[] strMatchList = new string[3]; strMatchList[0] = "InsertA"; strMatchList[1] = "InsertB"; strMatchList[2] = "InsertC"; // Create an insert iMateDefinition on the cylindrical face of the second extrude. InsertiMateDefinition oInsertiMateDefinition = default(InsertiMateDefinition); oInsertiMateDefinition = oCompDef.iMateDefinitions.AddInsertiMateDefinition(oExtrude2.SideFaces[1], false, 0, null, "InsertA", strMatchList); }
public static double H5 = 205, D51 = 200, L51 = 20, D52 = 245, L52 = 45, D53 = 100, L53 = 22.5, D54 = 122.5, L54 = 35; // Крышка public static void Build(InventorAPI api, string formName) { var oParameters = api.GetCompDef().Parameters; PlanarSketch[] sketch = new PlanarSketch[11]; Profile[] profile = new Profile[11]; SketchPoint[] point = new SketchPoint[10]; SketchLine[] line = new SketchLine[10]; SketchCircle[] circle = new SketchCircle[2]; ExtrudeFeature[] extrude = new ExtrudeFeature[10]; // Основание sketch[0] = api.Sketch(api.GetCompDef().WorkPlanes[2]); circle[0] = api.Circle(sketch[0], api.Point(sketch[0], 0, 0), D1 / 10 / 2); profile[0] = api.Profile(sketch[0]); extrude[0] = api.Extrude(profile[0], H1 / 10, 0, 0); sketch[1] = api.Sketch(extrude[0].Faces[3]); circle[0] = api.Circle(sketch[1], api.Point(sketch[1], 0, 0), D2 / 10 / 2); profile[1] = api.Profile(sketch[1]); extrude[1] = api.Extrude(profile[1], H2 / 10, 0, 0); // Кубическая часть корпуса sketch[2] = api.Sketch(extrude[1].Faces[2]); point[0] = api.Point(sketch[2], L2 / 10 / 2, L1 / 10 / 2); point[1] = api.Point(sketch[2], point[0].Geometry.X, -point[0].Geometry.Y); point[2] = api.Point(sketch[2], -point[0].Geometry.X, -point[0].Geometry.Y); point[3] = api.Point(sketch[2], -point[0].Geometry.X, point[0].Geometry.Y); line[0] = api.Line(sketch[2], point[0], point[1]); line[1] = api.Line(sketch[2], point[1], point[2]); line[2] = api.Line(sketch[2], point[2], point[3]); line[3] = api.Line(sketch[2], point[3], point[0]); profile[2] = api.Profile(sketch[2]); extrude[2] = api.Extrude(profile[2], T / 10, 0, 0); sketch[3] = api.Sketch(extrude[2].Faces[6]); point[0] = api.Point(sketch[3], L2 / 10 / 2, L1 / 10 / 2); point[1] = api.Point(sketch[3], point[0].Geometry.X, -point[0].Geometry.Y); point[2] = api.Point(sketch[3], -point[0].Geometry.X, -point[0].Geometry.Y); point[3] = api.Point(sketch[3], -point[0].Geometry.X, point[0].Geometry.Y); line[0] = api.Line(sketch[3], point[0], point[1]); line[1] = api.Line(sketch[3], point[1], point[2]); line[2] = api.Line(sketch[3], point[2], point[3]); line[3] = api.Line(sketch[3], point[3], point[0]); point[4] = api.Point(sketch[3], point[0].Geometry.X - T / 10, point[0].Geometry.Y - T / 10); point[5] = api.Point(sketch[3], point[0].Geometry.X - T / 10, -point[0].Geometry.Y + T / 10); point[6] = api.Point(sketch[3], -point[0].Geometry.X + T / 10, -point[0].Geometry.Y + T / 10); point[7] = api.Point(sketch[3], -point[0].Geometry.X + T / 10, point[0].Geometry.Y - T / 10); line[4] = api.Line(sketch[3], point[4], point[5]); line[5] = api.Line(sketch[3], point[5], point[6]); line[6] = api.Line(sketch[3], point[6], point[7]); line[7] = api.Line(sketch[3], point[7], point[4]); profile[3] = api.Profile(sketch[3]); extrude[3] = api.Extrude(profile[3], (HB - T * 2) / 10, 0, 0); var oWorkPlane4 = api.GetCompDef().WorkPlanes.AddByPlaneAndOffset(api.GetCompDef().WorkPlanes[2], (H1 + H2 + HB - T) / 10); oWorkPlane4.Visible = false; sketch[4] = api.Sketch(oWorkPlane4); point[0] = api.Point(sketch[4], L2 / 10 / 2, L1 / 10 / 2); point[1] = api.Point(sketch[4], point[0].Geometry.X, -point[0].Geometry.Y); point[2] = api.Point(sketch[4], -point[0].Geometry.X, -point[0].Geometry.Y); point[3] = api.Point(sketch[4], -point[0].Geometry.X, point[0].Geometry.Y); line[0] = api.Line(sketch[4], point[0], point[1]); line[1] = api.Line(sketch[4], point[1], point[2]); line[2] = api.Line(sketch[4], point[2], point[3]); line[3] = api.Line(sketch[4], point[3], point[0]); circle[0] = api.Circle(sketch[4], api.Point(sketch[4], 0, 0), D3 / 2 / 10); profile[4] = api.Profile(sketch[4]); extrude[4] = api.Extrude(profile[4], T / 10, 0, 0); // Переход к коническому корпусу sketch[5] = api.Sketch(extrude[4].Faces[3]); circle[0] = api.Circle(sketch[5], api.Point(sketch[5], 0, 0), D3 / 2 / 10); circle[1] = api.Circle(sketch[5], api.Point(sketch[5], 0, 0), (D3 / 2 + T) / 10); profile[5] = api.Profile(sketch[5]); extrude[5] = api.Extrude(profile[5], H3 / 10, 0, 0); // Отверстия у основания sketch[6] = api.Sketch(api.GetCompDef().WorkPlanes[2]); point[0] = api.Point(sketch[6], 0, 0); point[1] = api.Point(sketch[6], 0, DR / 2 / 10); point[2] = api.Point(sketch[6], DR / 2 / 10, 0); line[0] = api.Line(sketch[6], point[0], point[1]); line[1] = api.Line(sketch[6], point[0], point[2]); sketch[6].DimensionConstraints.AddTwoLineAngle(line[0], line[1], api.GetTransGeom().CreatePoint2d(1, 1)); sketch[6].GeometricConstraints.AddHorizontal((SketchEntity)line[1]); circle[0] = api.Circle(sketch[6], api.Point(sketch[6], DR / 10, -1), Or / 10); oParameters["d13"].Expression = "105 degree"; sketch[6].GeometricConstraints.AddCoincident((SketchEntity)circle[0].CenterSketchPoint, (SketchEntity)point[1]); profile[6] = api.Profile(sketch[6]); extrude[6] = api.Extrude(profile[6], H1 / 10, 0, 1); var objCollection = api.ObjectCollection(); objCollection.Add(extrude[6]); api.GetCompDef().Features.CircularPatternFeatures.Add(objCollection, api.GetCompDef().WorkAxes[2], true, 12, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute); // Трубки sketch[7] = api.Sketch(api.GetCompDef().WorkPlanes[1]); circle[0] = api.Circle(sketch[7], api.Point(sketch[7], H4 / 10, 0), D4D / 2 / 10); profile[7] = api.Profile(sketch[7]); extrude[7] = api.Extrude(profile[7], D3 / 10 + T * 2 / 10 + A * 2 / 10, 2, 0); sketch[8] = api.Sketch(api.GetCompDef().WorkPlanes[1]); circle[0] = api.Circle(sketch[8], api.Point(sketch[8], H4 / 10, 0), D4d / 2 / 10); profile[8] = api.Profile(sketch[8]); extrude[8] = api.Extrude(profile[8], D3 / 10 + T * 2 / 10 + A * 2 / 10, 2, 1); sketch[9] = api.Sketch(extrude[4].Faces[3]); circle[0] = api.Circle(sketch[9], api.Point(sketch[9], 0, 0), D3 / 2 / 10); profile[9] = api.Profile(sketch[9]); extrude[9] = api.Extrude(profile[9], H3, 0, 1); // Крышка sketch[10] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[10], L2 / 2 / 10, H5 / 10); point[1] = api.Point(sketch[10], point[0].Geometry.X, point[0].Geometry.Y + D51 / 2 / 10); point[2] = api.Point(sketch[10], point[1].Geometry.X + L51 / 10, point[1].Geometry.Y); point[3] = api.Point(sketch[10], point[2].Geometry.X, point[0].Geometry.Y + D52 / 2 / 10); point[4] = api.Point(sketch[10], point[3].Geometry.X + L52 / 10, point[3].Geometry.Y); point[5] = api.Point(sketch[10], point[4].Geometry.X, point[0].Geometry.Y + D53 / 2 / 10); point[6] = api.Point(sketch[10], point[5].Geometry.X + L53 / 10, point[5].Geometry.Y); point[7] = api.Point(sketch[10], point[6].Geometry.X, point[0].Geometry.Y + D54 / 2 / 10); point[8] = api.Point(sketch[10], point[7].Geometry.X + L54 / 10, point[7].Geometry.Y); point[9] = api.Point(sketch[10], point[8].Geometry.X, point[0].Geometry.Y); line[0] = api.Line(sketch[10], point[0], point[1]); line[1] = api.Line(sketch[10], point[1], point[2]); line[2] = api.Line(sketch[10], point[2], point[3]); line[3] = api.Line(sketch[10], point[3], point[4]); line[4] = api.Line(sketch[10], point[4], point[5]); line[5] = api.Line(sketch[10], point[5], point[6]); line[6] = api.Line(sketch[10], point[6], point[7]); line[7] = api.Line(sketch[10], point[7], point[8]); line[8] = api.Line(sketch[10], point[8], point[9]); line[9] = api.Line(sketch[10], point[9], point[0]); profile[10] = api.Profile(sketch[10]); api.Revolve(profile[10], line[9], 0); System.Windows.Forms.MessageBox.Show(formName + " завершено.", formName); }
public static void Build(InventorAPI api, string formName) { PlanarSketch[] sketch = new PlanarSketch[4]; Profile[] profile = new Profile[4]; SketchPoint[] point = new SketchPoint[5]; SketchLine[] line = new SketchLine[5]; SketchCircle[] circle = new SketchCircle[1]; ExtrudeFeature[] extrude = new ExtrudeFeature[4]; // Нижняя основа sketch[0] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[0], 0, 0); point[1] = api.Point(sketch[0], B / 10, 0); point[2] = api.Point(sketch[0], B / 10, -S1 / 10); point[3] = api.Point(sketch[0], 0, -S1 / 10); line[0] = api.Line(sketch[0], point[0], point[1]); line[1] = api.Line(sketch[0], point[1], point[2]); line[2] = api.Line(sketch[0], point[2], point[3]); line[3] = api.Line(sketch[0], point[3], point[0]); profile[0] = api.Profile(sketch[0]); extrude[0] = api.Extrude(profile[0], A1 / 10, 2, 0); // Боковые крепления var oWorkPlane1 = api.GetCompDef().WorkPlanes.AddByPlaneAndOffset(api.GetCompDef().WorkPlanes[3], A / 2 / 10); oWorkPlane1.Visible = false; sketch[1] = api.Sketch(oWorkPlane1); point[0] = api.Point(sketch[1], 0, 0); point[1] = api.Point(sketch[1], (B * System.Math.Sin(Parts.MainBody.Degree / 180 * System.Math.PI)) / 10, H * System.Math.Cos(Parts.MainBody.Degree / 180 * System.Math.PI) / 10 - S1 / 10); point[2] = api.Point(sketch[1], point[1].Geometry.X + K / 10, point[1].Geometry.Y); point[3] = api.Point(sketch[1], B / 10, K1 / 10); point[4] = api.Point(sketch[1], B / 10, 0); line[0] = api.Line(sketch[1], point[0], point[1]); line[1] = api.Line(sketch[1], point[1], point[2]); line[2] = api.Line(sketch[1], point[2], point[3]); line[3] = api.Line(sketch[1], point[3], point[4]); line[4] = api.Line(sketch[1], point[4], point[0]); profile[1] = api.Profile(sketch[1]); extrude[1] = api.Extrude(profile[1], S1 / 10, 0, 0); var objCollection1 = api.ObjectCollection(); objCollection1.Add(extrude[1]); api.GetCompDef().Features.MirrorFeatures.AddByDefinition(api.GetCompDef().Features.MirrorFeatures.CreateDefinition(objCollection1, api.GetCompDef().WorkPlanes[3], PatternComputeTypeEnum.kIdenticalCompute)); // Болтовое отверстие sketch[2] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[2], B / 10 - B1 / 10, -S1 / 10); point[1] = api.Point(sketch[2], point[0].Geometry.X + B2 / 10, point[0].Geometry.Y); point[2] = api.Point(sketch[2], point[1].Geometry.X, point[0].Geometry.Y - H1 / 10); point[3] = api.Point(sketch[2], point[0].Geometry.X, point[2].Geometry.Y); line[0] = api.Line(sketch[2], point[0], point[1]); line[1] = api.Line(sketch[2], point[1], point[2]); line[2] = api.Line(sketch[2], point[2], point[3]); line[3] = api.Line(sketch[2], point[3], point[0]); profile[2] = api.Profile(sketch[2]); extrude[2] = api.Extrude(profile[2], A2 / 10, 2, 0); sketch[3] = api.Sketch(api.GetCompDef().WorkPlanes[2]); circle[0] = api.Circle(sketch[3], api.Point(sketch[3], -(B / 10 - C / 10), 0), D6 / 2 / 10); profile[3] = api.Profile(sketch[3]); extrude[3] = api.Extrude(profile[3], H, 2, 1); // Резьба var EdgeCollection1 = api.EdgeCollection(); EdgeCollection1.Add(extrude[3].SideFaces[1].Edges[1]); var ThreadFeatures1 = api.ThreadFeatures(); var stInfo1 = ThreadFeatures1.CreateStandardThreadInfo(false, true, "ISO Metric profile", "M" + D6 + "x1.5", "6g"); ThreadFeatures1.Add(extrude[3].SideFaces[1], extrude[3].SideFaces[1].Edges[2], (ThreadInfo)stInfo1, false, true, 0); System.Windows.Forms.MessageBox.Show(formName + " завершено.", formName); }
public static void Build(InventorAPI api, string formName) { var oParameters = api.GetCompDef().Parameters; PlanarSketch[] sketch = new PlanarSketch[2]; Profile[] profile = new Profile[2]; SketchPoint[] point = new SketchPoint[8]; SketchLine[] line = new SketchLine[7]; SketchCircle[] circle = new SketchCircle[1]; // Создание конической основы sketch[0] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[0], 0.1, 0.1); point[1] = api.Point(sketch[0], 0.1, 0.2); line[0] = api.Line(sketch[0], point[0], point[1]); point[2] = api.Point(sketch[0], D / 2 - B, H); point[3] = api.Point(sketch[0], D / 2, H); point[4] = api.Point(sketch[0], D / 2, H - T); point[5] = api.Point(sketch[0], D / 2 - B + 1, H - T); point[6] = api.Point(sketch[0], Ds + 1, 0); point[7] = api.Point(sketch[0], Ds, 0); line[1] = api.Line(sketch[0], point[2], point[3]); line[2] = api.Line(sketch[0], point[3], point[4]); line[3] = api.Line(sketch[0], point[4], point[5]); line[4] = api.Line(sketch[0], point[5], point[6]); line[5] = api.Line(sketch[0], point[6], point[7]); line[6] = api.Line(sketch[0], point[7], point[2]); var SketchSize = api.GetTransGeom().CreatePoint2d(-1, -1); // Место для выноса размеров sketch[0].GeometricConstraints.AddVertical((SketchEntity)line[0]); sketch[0].GeometricConstraints.AddHorizontal((SketchEntity)line[1]); sketch[0].GeometricConstraints.AddVertical((SketchEntity)line[2]); sketch[0].GeometricConstraints.AddHorizontal((SketchEntity)line[3]); sketch[0].GeometricConstraints.AddHorizontal((SketchEntity)line[5]); sketch[0].GeometricConstraints.AddHorizontalAlign(point[0], point[7]); sketch[0].GeometricConstraints.AddParallel((SketchEntity)line[4], (SketchEntity)line[6]); sketch[0].DimensionConstraints.AddTwoPointDistance(point[0], point[7], DimensionOrientationEnum.kHorizontalDim, SketchSize); // Ds sketch[0].DimensionConstraints.AddTwoPointDistance(point[0], point[3], DimensionOrientationEnum.kVerticalDim, SketchSize); // H sketch[0].DimensionConstraints.AddTwoPointDistance(point[0], point[3], DimensionOrientationEnum.kHorizontalDim, SketchSize); // D sketch[0].DimensionConstraints.AddTwoPointDistance(point[2], point[3], DimensionOrientationEnum.kHorizontalDim, SketchSize); // B sketch[0].DimensionConstraints.AddOffset(line[4], (SketchEntity)line[6], SketchSize, false); // A sketch[0].DimensionConstraints.AddTwoPointDistance(point[3], point[4], DimensionOrientationEnum.kVerticalDim, SketchSize); // T oParameters["d0"].Expression = Ds / 2 + " mm"; oParameters["d1"].Expression = H + " mm"; oParameters["d2"].Expression = D / 2 + " mm"; oParameters["d3"].Expression = B + " mm"; oParameters["d4"].Expression = A + " mm"; oParameters["d5"].Expression = T + " mm"; point[0].MoveTo(api.GetTransGeom().CreatePoint2d(0, 0)); // Выравнивание осевой линии центра sketch[0].DimensionConstraints.AddTwoLineAngle(line[6], line[0], api.GetTransGeom().CreatePoint2d(10, 40), true); Degree = oParameters["d6"]._Value * (180 / System.Math.PI); profile[0] = api.Profile(sketch[0]); api.Revolve(profile[0], line[0], 0); // Отверстия sketch[1] = api.Sketch(api.GetCompDef().WorkPlanes[2]); point[0] = api.Point(sketch[1], 0, Rb / 10); circle[0] = api.Circle(sketch[1], point[0], Rm / 10 / 2); profile[1] = api.Profile(sketch[1]); var extrude = api.Extrude(profile[1], H / 10, 0, 1); var objCollection2 = api.ObjectCollection(); objCollection2.Add(extrude); api.GetCompDef().Features.CircularPatternFeatures.Add(objCollection2, api.GetCompDef().WorkAxes[2], true, 3, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute); System.Windows.Forms.MessageBox.Show(formName + " завершено.", formName); }
public static double D1R = 380, D1r = 260, T1R = 240, O1r = 22, O1R = 168, R1R = 540; // Загрузка сыпучих материалов public static void Build(InventorAPI api, string formName) { var oParameters = api.GetCompDef().Parameters; PlanarSketch[] sketch = new PlanarSketch[12]; Profile[] profile = new Profile[12]; SketchPoint[] point = new SketchPoint[8]; SketchLine[] line = new SketchLine[8]; SketchCircle[] circle = new SketchCircle[1]; ExtrudeFeature[] extrude = new ExtrudeFeature[12]; // Основа корпуса sketch[0] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[0], 0, H / 10 - T / 10); point[1] = api.Point(sketch[0], 0, H / 10); point[2] = api.Point(sketch[0], D1 / 10 / 2, H / 10); point[3] = api.Point(sketch[0], D1 / 10 / 2, T / 10); point[4] = api.Point(sketch[0], D / 10 / 2, T / 10); point[5] = api.Point(sketch[0], D / 10 / 2, 0); point[6] = api.Point(sketch[0], D1 / 10 / 2 - T / 10, 0); point[7] = api.Point(sketch[0], D1 / 10 / 2 - T / 10, H / 10 - T / 10); line[0] = api.Line(sketch[0], point[0], point[1]); line[1] = api.Line(sketch[0], point[1], point[2]); line[2] = api.Line(sketch[0], point[2], point[3]); line[3] = api.Line(sketch[0], point[3], point[4]); line[4] = api.Line(sketch[0], point[4], point[5]); line[5] = api.Line(sketch[0], point[5], point[6]); line[6] = api.Line(sketch[0], point[6], point[7]); line[7] = api.Line(sketch[0], point[7], point[0]); profile[0] = api.Profile(sketch[0]); api.Revolve(profile[0], line[0], 0); // Ребра жесткости sketch[1] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[1], D1 / 10 / 2 - T / 10, H / 10); point[1] = api.Point(sketch[1], point[0].Geometry.X + T / 10 * 2, H / 10); point[2] = api.Point(sketch[1], D / 10 / 2, T / 10 * 2); point[3] = api.Point(sketch[1], D / 10 / 2, T / 10); point[4] = api.Point(sketch[1], point[0].Geometry.X, T / 10); line[0] = api.Line(sketch[1], point[0], point[1]); line[0] = api.Line(sketch[1], point[1], point[2]); line[0] = api.Line(sketch[1], point[2], point[3]); line[0] = api.Line(sketch[1], point[3], point[4]); line[0] = api.Line(sketch[1], point[4], point[0]); profile[1] = api.Profile(sketch[1]); extrude[1] = api.Extrude(profile[1], A / 10, 2, 0); var objCollection1 = api.ObjectCollection(); objCollection1.Add(extrude[1]); api.GetCompDef().Features.CircularPatternFeatures.Add(objCollection1, api.GetCompDef().WorkAxes[2], true, ACount, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute); // Резервные проходы (2 штуки) var oWorkPlane2 = api.GetCompDef().WorkPlanes.AddByPlaneAndOffset(api.GetCompDef().WorkPlanes[2], HR / 10); oWorkPlane2.Visible = false; sketch[2] = api.Sketch(oWorkPlane2); circle[0] = api.Circle(sketch[2], api.Point(sketch[2], RR / 10, 0), DR / 10 / 2); profile[2] = api.Profile(sketch[2]); extrude[2] = api.Extrude(profile[2], Hr / 10, 2, 0); sketch[3] = api.Sketch(oWorkPlane2); circle[0] = api.Circle(sketch[3], api.Point(sketch[3], RR / 10, 0), Dr / 10 / 2); profile[3] = api.Profile(sketch[3]); extrude[3] = api.Extrude(profile[3], HR / 10 - H / 10, 1, 0); sketch[4] = api.Sketch(oWorkPlane2); circle[0] = api.Circle(sketch[4], api.Point(sketch[4], RR / 10, 0), TR / 10 / 2); profile[4] = api.Profile(sketch[4]); extrude[4] = api.Extrude(profile[4], 10000, 2, 1); sketch[5] = api.GetCompDef().Sketches.Add(oWorkPlane2); sketch[5] = api.Sketch(oWorkPlane2); circle[0] = api.Circle(sketch[5], api.Point(sketch[5], RR / 10, OR / 10), Or / 10 / 2); profile[5] = api.Profile(sketch[5]); extrude[5] = api.Extrude(profile[5], Hr / 10, 2, 1); var Axis5 = api.GetCompDef().WorkAxes.AddByRevolvedFace(extrude[4].Faces[1]); Axis5.Visible = false; var objCollection5 = api.ObjectCollection(); objCollection5.Add(extrude[5]); var CircularPatternFeature5 = api.GetCompDef().Features.CircularPatternFeatures.Add(objCollection5, Axis5, true, 8, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute); var objCollection6 = api.ObjectCollection(); for (int i = 2; i < 6; i++) { objCollection6.Add(extrude[i]); } objCollection6.Add(CircularPatternFeature5); api.GetCompDef().Features.CircularPatternFeatures.Add(objCollection6, api.GetCompDef().WorkAxes[2], true, 2, "150 degree", true, PatternComputeTypeEnum.kIdenticalCompute); // Отверстия под болты sketch[7] = api.Sketch(api.GetCompDef().WorkPlanes[2]); point[0] = api.Point(sketch[7], 0, 0); point[1] = api.Point(sketch[7], 0, MBRb / 10); point[2] = api.Point(sketch[7], MBRb / 10, 0); line[0] = api.Line(sketch[7], point[1], point[0]); line[1] = api.Line(sketch[7], point[0], point[2]); sketch[7].DimensionConstraints.AddTwoLineAngle(line[0], line[1], api.GetTransGeom().CreatePoint2d(1, 1)); sketch[7].GeometricConstraints.AddHorizontal((SketchEntity)line[1]); circle[0] = api.Circle(sketch[7], point[1], MBRm / 10 / 2); oParameters["d21"].Expression = "82.5 degree"; sketch[7].GeometricConstraints.AddCoincident((SketchEntity)circle[0].CenterSketchPoint, (SketchEntity)point[1]); profile[7] = api.Profile(sketch[7]); extrude[7] = api.Extrude(profile[7], 10000, 2, 1); var objCollection7 = api.ObjectCollection(); objCollection7.Add(extrude[7]); api.GetCompDef().Features.CircularPatternFeatures.Add(objCollection7, api.GetCompDef().WorkAxes[2], true, 3, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute); // Загрузка сыпучих материалов sketch[8] = api.Sketch(oWorkPlane2); point[0] = api.Point(sketch[8], 0, 0); point[1] = api.Point(sketch[8], 0, -R1R / 10); point[2] = api.Point(sketch[8], -R1R / 10, 0); line[0] = api.Line(sketch[8], point[0], point[1]); line[1] = api.Line(sketch[8], point[0], point[2]); sketch[8].DimensionConstraints.AddTwoLineAngle(line[0], line[1], api.GetTransGeom().CreatePoint2d(1, 1)); sketch[8].GeometricConstraints.AddVertical((SketchEntity)line[0]); circle[0] = api.Circle(sketch[8], api.Point(sketch[8], -R1R / 10, -1), D1R / 10 / 2); oParameters["d27"].Expression = "75 degree"; sketch[8].GeometricConstraints.AddCoincident((SketchEntity)circle[0].CenterSketchPoint, (SketchEntity)point[2]); profile[8] = api.Profile(sketch[8]); extrude[8] = api.Extrude(profile[8], Hr / 10, 2, 0); sketch[9] = api.Sketch(extrude[8].Faces[1]); circle[0] = api.Circle(sketch[9], api.Point(sketch[9], 0, 0), D1r / 10 / 2); profile[9] = api.Profile(sketch[9]); extrude[9] = api.Extrude(profile[9], HR / 10 - H / 10, 0, 0); sketch[10] = api.Sketch(extrude[8].Faces[1]); circle[0] = api.Circle(sketch[10], api.Point(sketch[10], 0, 0), T1R / 10 / 2); profile[10] = api.Profile(sketch[10]); extrude[10] = api.Extrude(profile[10], 10000, 2, 1); sketch[11] = api.Sketch(extrude[8].Faces[1]); circle[0] = api.Circle(sketch[11], api.Point(sketch[11], 0, O1R / 10), O1r / 10 / 2); profile[11] = api.Profile(sketch[11]); extrude[11] = api.Extrude(profile[11], Hr / 10, 1, 1); var Axis11 = api.GetCompDef().WorkAxes.AddByRevolvedFace(extrude[10].Faces[1]); Axis11.Visible = false; var objCollection11 = api.ObjectCollection(); objCollection11.Add(extrude[11]); api.GetCompDef().Features.CircularPatternFeatures.Add(objCollection11, Axis11, true, 12, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute); System.Windows.Forms.MessageBox.Show(formName + " завершено.", formName); }