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); }
public void AssemblyFeature() { AssemblyDocument oAssDoc = (AssemblyDocument)_InvApplication.ActiveDocument; AssemblyComponentDefinition oAsmDef = oAssDoc.ComponentDefinition; // Create a sketch on the XY workplane. PlanarSketch oSketch = default(PlanarSketch); oSketch = oAsmDef.Sketches.Add(oAsmDef.WorkPlanes[3]); TransientGeometry oTG = default(TransientGeometry); oTG = _InvApplication.TransientGeometry; // Draw a rectangle. oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(0.1, 0.1), oTG.CreatePoint2d(1, 0.5)); // Create a profile Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); // Create the extrusion. ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oAsmDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kCutOperation); oExtrudeDef.SetDistanceExtent("2 cm", PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); oAsmDef.Features.ExtrudeFeatures.Add(oExtrudeDef); }
private void ExtrudeSketch(int x, int y) { //PartDocument oPartDoc = default(PartDocument); //oPartDoc = (PartDocument)_invApp.Documents.Add(Inventor.DocumentTypeEnum.kPartDocumentObject,_invApp.FileManager.GetTemplateFile(Inventor.DocumentTypeEnum.kPartDocumentObject)); PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument; PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; PlanarSketch oSketch = default(PlanarSketch); oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[1]); oSketch.SketchLines.AddAsTwoPointRectangle(_invApp.TransientGeometry.CreatePoint2d(-x, -y), _invApp.TransientGeometry.CreatePoint2d(x, y)); Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, Inventor.PartFeatureOperationEnum.kJoinOperation); oExtrudeDef.SetDistanceExtent(5, Inventor.PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); ExtrudeFeature oExtrude = default(ExtrudeFeature); oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef); }
private void Feature3(int x, int y) { PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument; oPartDoc.UnitsOfMeasure.LengthUnits = Inventor.UnitsTypeEnum.kMillimeterLengthUnits; PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; PlanarSketch oSketch = default(PlanarSketch); oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]); oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), 6); oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), 17.5); Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, Inventor.PartFeatureOperationEnum.kJoinOperation); oExtrudeDef.SetDistanceExtent(3, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature oExtrude = default(ExtrudeFeature); oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef); }
private void triangleSticker(ref PartDocument pDoc, double heigth, double width, string txt = "", double thickness = 0.01) { PartComponentDefinition compDef = pDoc.ComponentDefinition; PlanarSketch ps = compDef.Sketches.Add(compDef.WorkPlanes[3]); SketchLine line1 = ps.SketchLines.AddByTwoPoints(m_TG.CreatePoint2d(-width / 20, -heigth / 30), m_TG.CreatePoint2d(width / 20, -heigth / 30)); SketchLine line2 = ps.SketchLines.AddByTwoPoints(line1.StartSketchPoint, m_TG.CreatePoint2d(0, heigth / 30 * 2)); ps.SketchLines.AddByTwoPoints(line2.EndSketchPoint, line1.EndSketchPoint); Profile pr = ps.Profiles.AddForSolid(); ExtrudeDefinition extDef = compDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(pr, PartFeatureOperationEnum.kNewBodyOperation); extDef.SetDistanceExtent(thickness / 10, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature extr = compDef.Features.ExtrudeFeatures.Add(extDef); extr.Appearance = InvDoc.u.createColor(pDoc, "red_", "красный_", 255, 0, 0); if (txt != "") { ps = compDef.Sketches.Add(extr.EndFaces[1]); Inventor.TextBox tb = ps.TextBoxes.AddFitted(m_TG.CreatePoint2d(), txt); tb.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter; tb.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle; tb.SingleLineText = false; //tb.Rotation = Math.PI; if (mirror) { tb.Rotation = Math.PI; } EmbossFeature emb = compDef.Features.EmbossFeatures.AddEmbossFromFace(ps.Profiles.AddForSolid(false, ps.TextBoxes), 0.0005, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); emb.Appearance = InvDoc.u.createColor(pDoc, "black_", "черный_", 0, 0, 0); } }
// create a feature private void createFeature() { PartDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, null), true) as PartDocument; // Get the XZ Plane WorkPlane oWorkPlane = oDoc.ComponentDefinition.WorkPlanes[2]; PlanarSketch oSketch = oDoc.ComponentDefinition.Sketches.Add(oWorkPlane, false); TransientGeometry oTG = mApp.TransientGeometry; //Create some transient points used for defining the lines (see BRep Module) Point2d[] oPoints = new Point2d[5]; oPoints[0] = oTG.CreatePoint2d(0, 0); oPoints[1] = oTG.CreatePoint2d(-10, 0); oPoints[2] = oTG.CreatePoint2d(-10, -10); oPoints[3] = oTG.CreatePoint2d(5, -10); oPoints[4] = oTG.CreatePoint2d(5, -5); //Add the sketchlines, coincident constraints will be created automatically //since the "Line.EndSketchPoint" are provided each time we create a new line SketchLine[] oLines = new SketchLine[5]; oLines[0] = oSketch.SketchLines.AddByTwoPoints(oPoints[0], oPoints[1]); oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, oPoints[2]); oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, oPoints[3]); oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oPoints[4]); oSketch.SketchArcs.AddByCenterStartEndPoint(oTG.CreatePoint2d(0, -5), oLines[3].EndSketchPoint, oLines[0].StartSketchPoint, true); //Create a profile for the extrusion, here no need to worry since there is only //a single profile that is possible Profile oProfile = oSketch.Profiles.AddForSolid(true, null, null); // Definition Way: PartComponentDefinition oPartDocDef = oDoc.ComponentDefinition; // get ExtrudeFeatures collection ExtrudeFeatures extrudes = oPartDocDef.Features.ExtrudeFeatures; // Create an extrude definition in the new surface body ExtrudeDefinition extrudeDef = extrudes.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation); // Modify the extent extrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); // Create the extrusion. ExtrudeFeature extrude = extrudes.Add(extrudeDef); }
internal override void Create_BR(TransientGeometry TG, ref PlanarSketch sketch, EdgeCollection eColl, ref Face B_face, ref Face E_face, ref PartComponentDefinition partDef) { sketch.SketchCircles.AddByCenterRadius(TG.CreatePoint2d(), Radius); Profile profile = sketch.Profiles.AddForSolid(); ExtrudeDefinition extrude = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kNewBodyOperation); extrude.SetDistanceExtent(Length, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature extrudeFeature = partDef.Features.ExtrudeFeatures.Add(extrude); sketch = partDef.Sketches.Add(extrudeFeature.EndFaces[1]); Start_face = extrudeFeature.StartFaces[1]; End_face = extrudeFeature.EndFaces[1]; Side_face = extrudeFeature.SideFaces[1]; }
private Inventor.ExtrudeFeature CreateFlangeExtrustion(ref Inventor.PartDocument PartDocument, string FlangeDiaOD, string FlangeDiaID, string FlangeThickness) { Inventor.UnitsOfMeasure UnitsOfMeasure; Inventor.PlanarSketch Sketch; Inventor.TransientGeometry TransientGeometry; Inventor.SketchCircle SketchCircle; Inventor.WorkPoint WorkPoint; Inventor.WorkPlane BaseWorkPlane; Inventor.RadiusDimConstraint RadiusDimConstraint = null; Inventor.SketchEntity SketchEntity; Inventor.ObjectCollection SketchObjectCollection; Inventor.Profile Profile; Inventor.ExtrudeDefinition ExtrudeDefinition; Inventor.ExtrudeFeature ExtrudeFeature = null; SketchObjectCollection = InvApp.TransientObjects.CreateObjectCollection(); UnitsOfMeasure = PartDocument.UnitsOfMeasure; double DiaOD = 0, DiaID = 0, Thickness = 0; DiaOD = UnitsOfMeasure.GetValueFromExpression(FlangeDiaOD, Inventor.UnitsTypeEnum.kMillimeterLengthUnits); DiaID = UnitsOfMeasure.GetValueFromExpression(FlangeDiaID, Inventor.UnitsTypeEnum.kMillimeterLengthUnits); Thickness = UnitsOfMeasure.GetValueFromExpression(FlangeThickness, Inventor.UnitsTypeEnum.kMillimeterLengthUnits); TransientGeometry = InvApp.TransientGeometry; WorkPoint = PartDocument.ComponentDefinition.WorkPoints[1]; BaseWorkPlane = GetPartDocumentWorkPlane(ref PartDocument, "XY"); Sketch = PartDocument.ComponentDefinition.Sketches.Add(BaseWorkPlane, false); SketchEntity = Sketch.AddByProjectingEntity(WorkPoint); SketchCircle = Sketch.SketchCircles.AddByCenterRadius(TransientGeometry.CreatePoint2d(0, 0), DiaOD / 2); RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, TransientGeometry.CreatePoint2d(0, 0), false); Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint); RadiusDimConstraint = null; SketchCircle = null; SketchCircle = Sketch.SketchCircles.AddByCenterRadius(TransientGeometry.CreatePoint2d(0, 0), DiaID / 2); RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, TransientGeometry.CreatePoint2d(0, 0), false); Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint); SketchObjectCollection.Add(SketchCircle); Profile = Sketch.Profiles.AddForSolid(true, SketchObjectCollection); ExtrudeDefinition = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(Profile, Inventor.PartFeatureOperationEnum.kNewBodyOperation); ExtrudeDefinition.SetDistanceExtent(Thickness, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.Add(ExtrudeDefinition); ExtrudeFeature.Name = "FlangeBase"; return(ExtrudeFeature); }
private void createPart2() { // 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]); oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(-5, -5), oTG.CreatePoint2d(5, 5)); SketchPoint oSketchPt = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0)); Profile oProfile = oSketch.Profiles.AddForSolid(); // create a plate with a hole feature ExtrudeDefinition oExtrudDef = oDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation); oExtrudDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature oExtrudeF = oDef.Features.ExtrudeFeatures.Add(oExtrudDef); // Create an object collection for the hole center points. ObjectCollection oHoleCenters = default(ObjectCollection); oHoleCenters = mApp.TransientObjects.CreateObjectCollection(); oHoleCenters.Add(oSketchPt); // create hole feature HolePlacementDefinition oHPdef = (HolePlacementDefinition)oDef.Features.HoleFeatures.CreateSketchPlacementDefinition(oHoleCenters); HoleFeature oHoleF = oDef.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHPdef, "2", PartFeatureExtentDirectionEnum.kNegativeExtentDirection); Face oFace = oHoleF.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\test2.ipt")) { System.IO.File.Delete("c:\temp\test2.ipt"); } oDoc.SaveAs("c:\\temp\\test2.ipt", false); }
/// <summary> /// Ступень 2 /// </summary> private void BuildStem2() { PlanarSketch StemSketch2 = _inventorApi.MakeNewSketch(3, ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value);// второй параметр отодвигает по Z координате на заданную длину. _inventorApi.DrawCircle(ValParameters.GetParameter(ParameterType.RadiusSecondLevel).Value, StemSketch2, _curPoint); ExtrudeDefinition extrudeDef2 = _inventorApi.PartDefinition. Features. ExtrudeFeatures. CreateExtrudeDefinition(StemSketch2.Profiles.AddForSolid(), PartFeatureOperationEnum.kJoinOperation); extrudeDef2.SetDistanceExtent(ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature extrude2 = _inventorApi.PartDefinition.Features.ExtrudeFeatures.Add(extrudeDef2); }
internal override void Create_BR(TransientGeometry TG, ref PlanarSketch sketch, EdgeCollection eColl, ref Face B_face, ref Face E_face, ref PartComponentDefinition partDef) { sketch.SketchLines.AddAsPolygon(Number_of_Edges, TG.CreatePoint2d(), TG.CreatePoint2d(Radius), is_Inscribed); Profile profile = sketch.Profiles.AddForSolid(); ExtrudeDefinition extrude = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kNewBodyOperation); extrude.SetDistanceExtent(Length, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature extrudeFeature = partDef.Features.ExtrudeFeatures.Add(extrude); sketch = partDef.Sketches.Add(extrudeFeature.EndFaces[1]); Start_face = extrudeFeature.StartFaces[1]; End_face = extrudeFeature.EndFaces[1]; foreach (Face side in extrudeFeature.SideFaces) { Side_faces.Add(side); } }
/// <summary> /// Ступень 1 /// </summary> private void BuildStem1() { PlanarSketch StemSketch = _inventorApi.MakeNewSketch(3, 0); //[1 - ZY; 2 - ZX; 3 - XY] Point2d point = _inventorApi.TransientGeometry.CreatePoint2d(0, 0); //построен эскиз _inventorApi.DrawCircle(ValParameters.GetParameter(ParameterType.RadiusFirstLevel).Value, StemSketch, point); ExtrudeDefinition extrudeDef = _inventorApi.PartDefinition. Features. ExtrudeFeatures. CreateExtrudeDefinition(StemSketch.Profiles.AddForSolid(), PartFeatureOperationEnum.kJoinOperation); extrudeDef.SetDistanceExtent(ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature extrude = _inventorApi.PartDefinition.Features.ExtrudeFeatures.Add(extrudeDef); }
/// <summary> /// Зубья вала. /// </summary> private void BuildTeeth() { //Многоугольник для выдавливания PlanarSketch StemSketchQ = MakeNewSketch(3, ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value + ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value);// второй параметр отодвигает по Z координате на заданную длину. Point2d pointQ = _inventorApi.TransientGeometry.CreatePoint2d(ValParameters.GetParameter(ParameterType.RadiusThirdLevel).Value + 3, 0); Point2d CenterPointQ = _inventorApi.TransientGeometry.CreatePoint2d(ValParameters.GetParameter(ParameterType.RadiusThirdLevel).Value, 0); DrawPolygon(pointQ, StemSketchQ, CenterPointQ); ExtrudeDefinition extrudeDefQ = _inventorApi.PartDefinition. Features. ExtrudeFeatures. CreateExtrudeDefinition(StemSketchQ.Profiles.AddForSolid(), PartFeatureOperationEnum.kCutOperation); extrudeDefQ.SetDistanceExtent( ValParameters.GetParameter(ParameterType.LengthThirdLevel).Value, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature extrudeQ = _inventorApi.PartDefinition.Features.ExtrudeFeatures.Add(extrudeDefQ); //Базовые оси //для создания массива. WorkAxis XAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis YAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis ZAxis = _inventorApi.PartDefinition.WorkAxes[3]; //Create an object collection ObjectCollection objectCollection = _inventorApi.CreateObjectCollection(); objectCollection.Add(extrudeQ); _inventorApi.PartDefinition.Features.CircularPatternFeatures.Add( objectCollection, ZAxis, true, (int)(ValParameters.GetParameter(ParameterType.RadiusThirdLevel).Value / 1.5), "360 deg", true, PatternComputeTypeEnum.kAdjustToModelCompute); }
private void ExtrudeDoub(int x, int y) { try { PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument; PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; ExtrudeFeature oExtrude = default(ExtrudeFeature); oExtrude = oCompDef.Features.ExtrudeFeatures[1]; oExtrude.SetDistanceExtent(x, Inventor.PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); Random r = new Random(); int rand = r.Next(1, 20); if (rand > 18) { movrot.ChangeView(1, 0, 0, apply: false); } } catch (System.ArgumentException) { PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument; PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; PlanarSketch oSketch = default(PlanarSketch); oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[1]); oSketch.SketchLines.AddAsTwoPointRectangle(_invApp.TransientGeometry.CreatePoint2d(-x, -y), _invApp.TransientGeometry.CreatePoint2d(x, y)); Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, Inventor.PartFeatureOperationEnum.kJoinOperation); oExtrudeDef.SetDistanceExtent(x, Inventor.PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); ExtrudeFeature oExtrude = default(ExtrudeFeature); oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef); } }
/// <summary> /// Ступень 4 /// </summary> private void BuildStem4() { PlanarSketch StemSketch4 = _inventorApi.MakeNewSketch(3, ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value + ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value + ValParameters.GetParameter(ParameterType.LengthThirdLevel).Value);// второй параметр отодвигает по Z координате на заданную длину. // transientGeometry = invApp.TransientGeometry; // Point2d point2 = transientGeometry.CreatePoint2d(0, 0); //построен эскиз _inventorApi.DrawCircle(ValParameters.GetParameter(ParameterType.RadiusFourthLevel).Value, StemSketch4, _curPoint); ExtrudeDefinition extrudeDef4 = _inventorApi.PartDefinition. Features. ExtrudeFeatures. CreateExtrudeDefinition(StemSketch4.Profiles.AddForSolid(), PartFeatureOperationEnum.kJoinOperation); extrudeDef4.SetDistanceExtent(ValParameters.GetParameter(ParameterType.LengthFourthLevel).Value, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature extrude4 = _inventorApi.PartDefinition.Features.ExtrudeFeatures.Add(extrudeDef4); }
private void Feature4(int x, int y) { try { PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument; oPartDoc.UnitsOfMeasure.LengthUnits = Inventor.UnitsTypeEnum.kMillimeterLengthUnits; PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; //Inventor.Point2d point1 = _invApp.TransientGeometry.CreatePoint2d(6, 13.8); //Inventor.Point2d point2 = _invApp.TransientGeometry.CreatePoint2d(-6, 13.8); PlanarSketch oSketch = default(PlanarSketch); oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]); SketchArc arc1 = oSketch.SketchArcs.AddByThreePoints(_invApp.TransientGeometry.CreatePoint2d(5.879, 13.8), _invApp.TransientGeometry.CreatePoint2d(0, 15), _invApp.TransientGeometry.CreatePoint2d(-5.879, 13.8)); SketchArc arc2 = oSketch.SketchArcs.AddByThreePoints(arc1.StartSketchPoint, _invApp.TransientGeometry.CreatePoint2d(0, 9), arc1.EndSketchPoint); //oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), 15); //oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 15), 6); Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); //oProfile = oSketch.Profiles.AddForSurface(arc2); ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, Inventor.PartFeatureOperationEnum.kCutOperation); oExtrudeDef.SetDistanceExtent(3, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature oExtrude = default(ExtrudeFeature); oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef); } catch { try { Feature3(x, y); } catch { Feature2(x, y); } } }
private Inventor.ExtrudeFeature Extrude_FlangeBody(ref Inventor.PartDocument PartDocument) { Inventor.TransientGeometry TransientGeometry; Inventor.SketchCircle SketchCircle; Inventor.RadiusDimConstraint RadiusDimConstraint = null; Inventor.Profile SketchProfile; Inventor.ExtrudeDefinition ExtrudeDefinition; Inventor.ExtrudeFeature ExtrudeFeature = null; Inventor.PlanarSketch Sketch; Inventor.SketchEntity SketchEntity; PartDocument = AddSketchProjectCenterPoint(PartDocument, out Sketch, out SketchEntity); TransientGeometry = InvApp.TransientGeometry; SketchCircle = Sketch.SketchCircles.AddByCenterRadius(TransientGeometry.CreatePoint2d(0, 0), FlangeDiaOD / 2); RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, TransientGeometry.CreatePoint2d(0, 0), false); Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint); RadiusDimConstraint = null; SketchCircle = null; Inventor.ObjectCollection SketchObjectCollection; SketchObjectCollection = InvApp.TransientObjects.CreateObjectCollection(); SketchCircle = Sketch.SketchCircles.AddByCenterRadius(TransientGeometry.CreatePoint2d(0, 0), FlangeDiaID / 2); RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, TransientGeometry.CreatePoint2d(0, 0), false); Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint); SketchObjectCollection.Add(SketchCircle); SketchProfile = Sketch.Profiles.AddForSolid(true, SketchObjectCollection); ExtrudeDefinition = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(SketchProfile, Inventor.PartFeatureOperationEnum.kNewBodyOperation); ExtrudeDefinition.SetDistanceExtent(FlangeThickness, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection); //Extrude The Sketch Profile ExtrudeFeature = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.Add(ExtrudeDefinition); ExtrudeFeature.Name = "FlangeBody"; return(ExtrudeFeature); }
public Inventor.ExtrudeFeature Extrude_FlangeBody() { Inventor.TransientGeometry TransientGeometry; Inventor.SketchCircle SketchCircle; Inventor.RadiusDimConstraint RadiusDiamension = null; Inventor.Profile SketchProfile; Inventor.ExtrudeDefinition ExtrudeDefinition; Inventor.ExtrudeFeature ExtrudeFeature = null; Inventor.PlanarSketch Sketch; Inventor.SketchEntity SketchEntity; //Create Sketch on wp project 0,0,0 work point Geometry PartDocument = AddSketchProjectCenterPoint(PartDocument, out Sketch, out SketchEntity); //Get the Transient Geometry Object from Inventor TransientGeometry = InvApp.TransientGeometry; //Draw Outside Hole DrawCircle_Constrain_Diamension(TransientGeometry.CreatePoint2d(0, 0), out SketchCircle, out RadiusDiamension, Sketch, SketchEntity, FlangeDiaOD / 2); RadiusDiamension = null; // reset for next use SketchCircle = null; Inventor.ObjectCollection SketchObjectCollection; SketchObjectCollection = InvApp.TransientObjects.CreateObjectCollection(); //Draw Inside Hole Add to sketch objects DrawCircle_Constrain_Diamension(TransientGeometry.CreatePoint2d(0, 0), out SketchCircle, out RadiusDiamension, Sketch, SketchEntity, FlangeDiaID / 2); //Add to sketch Collection ready for Extrude SketchObjectCollection.Add(SketchCircle); //Convert to profileing SketchProfile = Sketch.Profiles.AddForSolid(true, SketchObjectCollection); ExtrudeDefinition = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(SketchProfile, Inventor.PartFeatureOperationEnum.kNewBodyOperation); ExtrudeDefinition.SetDistanceExtent(FlangeThickness, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection); //Extrude The Sketch Profile ExtrudeFeature = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.Add(ExtrudeDefinition); ExtrudeFeature.Name = "FlangeBody"; return(ExtrudeFeature); }
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); }
//creating shaft internal static void Revolve() { Profile profile; try { var_es.lines = new List <SketchLine>(); if (var_es.part_doc_def.Features.RevolveFeatures.Count != 0) { //partDef.Features.RevolveFeatures[1].Delete(); foreach (RevolveFeature s in var_es.part_doc_def.Features.RevolveFeatures) { s.Delete(); } } if (var_es.part_doc_def.Sketches.Count != 0) { foreach (Sketch s in var_es.part_doc_def.Sketches) { s.Delete(); } } partDef = var_es.part_doc.ComponentDefinition; tg = var_es.InventorApp.TransientGeometry; sketch = partDef.Sketches.Add(partDef.WorkPlanes[3]); if (var_es.lines.Count > 0) { var_es.lines.RemoveAt(var_es.lines.Count - 1); sketch.SketchLines[sketch.SketchLines.Count].Delete(); } foreach (Section obj in var_es._list) { obj.DrawGeom(tg, ref sketch, ref var_es.lines); } var_es.lines.Add(sketch.SketchLines.AddByTwoPoints(var_es.lines[0].StartSketchPoint, var_es.lines[var_es.lines.Count - 1].EndSketchPoint)); var_es.lines[var_es.lines.Count - 1].Centerline = true; profile = sketch.Profiles.AddForSolid(); RevolveFeature ex = partDef.Features.RevolveFeatures.AddFull(profile, var_es.lines[var_es.lines.Count - 1], PartFeatureOperationEnum.kNewBodyOperation); //assinging all faces to each section Assign_all_faces(); Assign_All_Faces(); } catch { } //Chamfers and Fillets creation Chamfer_creation(); #region Polygon creation try { //polyon creation by cutting out unneeded parts foreach (Section obj in var_es._list) { if (obj.GetType().ToString() == "InvAddIn.Pol") { PlanarSketch sketch; //getting sketch try { sketch = partDef.Sketches.Add(obj.Start_face); } catch { sketch = partDef.Sketches.Add(obj.End_face); } sketch.Name = "Pol" + obj.Position; //creatin points for sketchline, this line is polygon`s side, wich determines what should be cut off Point2d first = tg.CreatePoint2d(), second = tg.CreatePoint2d(); var k = (360 / obj.Number_of_Edges) / 2; first.X = Math.Cos(k * Math.PI / 180) * var_es._list[obj.Position].Radius; first.Y = Math.Sin(k * Math.PI / 180) * var_es._list[obj.Position].Radius; second.X = first.X; second.Y = first.Y * -1; sketch.SketchLines.AddByTwoPoints(first, second); //Arc to connect start and end point of polygon`s side , and mid-point is point on the the outside circle sketch.SketchArcs.AddByThreePoints(sketch.SketchLines[1].StartSketchPoint, tg.CreatePoint2d(var_es._list[obj.Position].Radius), sketch.SketchLines[1].EndSketchPoint); profile = sketch.Profiles.AddForSolid(); //adding extrude definition ExtrudeDefinition extrude = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kCutOperation); extrude.SetDistanceExtent(var_es._list[obj.Position].Length, PartFeatureExtentDirectionEnum.kNegativeExtentDirection); ExtrudeFeature extrudeFeature = partDef.Features.ExtrudeFeatures.Add(extrude); //creating circle array of features to make polygon ObjectCollection OBJ_colection = var_es.InventorApp.TransientObjects.CreateObjectCollection(); OBJ_colection.Add(partDef.Features.ExtrudeFeatures[partDef.Features.ExtrudeFeatures.Count] as Object); partDef.Features.CircularPatternFeatures.Add(OBJ_colection, partDef.WorkAxes[1], false, obj.Number_of_Edges + " ul", 360 + " deg", true, PatternComputeTypeEnum.kIdenticalCompute); } } } catch (Exception e5) { MessageBox.Show(e5.ToString()); } #endregion //All features creating try { Feature(); } catch (Exception e113) { MessageBox.Show(e113.ToString()); } }
public void RunWithArguments(Document doc, NameValueMap map) { //LogTrace("Processing " + doc.FullFileName); //try //{ // if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject) // { // using (new HeartBeat()) // { // // TODO: handle the Inventor part here // } // } // else if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) // Assembly. // { // using (new HeartBeat()) // { // // TODO: handle the Inventor assembly here // } // } //} //catch (Exception e) //{ // LogError("Processing failed. " + e.ToString()); //} LogTrace("Initialiting"); PartDocument oPartDoc = (PartDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true); LogTrace("Part template opened"); TransientGeometry oTG = inventorApplication.TransientGeometry; PartComponentDefinition oPartComDef = oPartDoc.ComponentDefinition; UserParameters oParams = oPartComDef.Parameters.UserParameters; oParams.AddByExpression("width", "50", UnitsTypeEnum.kMillimeterLengthUnits); oParams.AddByExpression("height", "10", UnitsTypeEnum.kMillimeterLengthUnits); oParams.AddByExpression("length", "10", UnitsTypeEnum.kMillimeterLengthUnits); LogTrace("Standard parameters created"); Point2d[] oPoints = new Point2d[4]; oPoints[0] = oTG.CreatePoint2d(0, 0); oPoints[1] = oTG.CreatePoint2d(0, oPartComDef.Parameters.GetValueFromExpression("width", UnitsTypeEnum.kMillimeterLengthUnits)); oPoints[2] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("height", UnitsTypeEnum.kMillimeterLengthUnits), 0); oPoints[3] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("height", UnitsTypeEnum.kMillimeterLengthUnits), oPartComDef.Parameters.GetValueFromExpression("width", UnitsTypeEnum.kMillimeterLengthUnits)); LogTrace("Inventor points created"); LogTrace("Initiating sketch creation..."); PlanarSketch oSketch = oPartComDef.Sketches.Add(oPartComDef.WorkPlanes[1]); SketchPoint[] osPoints = new SketchPoint[4]; SketchLine[] oLines = new SketchLine[4]; osPoints[0] = oSketch.SketchPoints.Add(oPoints[0]); osPoints[1] = oSketch.SketchPoints.Add(oPoints[1]); osPoints[2] = oSketch.SketchPoints.Add(oPoints[2]); osPoints[3] = oSketch.SketchPoints.Add(oPoints[3]); oLines[0] = oSketch.SketchLines.AddByTwoPoints(osPoints[0], osPoints[1]); oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, osPoints[3]); oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, osPoints[2]); oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oLines[0].StartSketchPoint); LogTrace("Sketch created, adding dimensions"); oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[0], osPoints[1], DimensionOrientationEnum.kAlignedDim, oPoints[1]); //d0// oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[1], osPoints[3], DimensionOrientationEnum.kAlignedDim, oPoints[3]); //d1// LogTrace("Dimensions added to the sketch, changing standard values for User parameter values"); var inventorMParams = oPartComDef.Parameters.ModelParameters; foreach (ModelParameter mParam in inventorMParams) { if (mParam.Name.Contains("d0")) { mParam.Expression = "width"; } else if (mParam.Name.Contains("d1")) { mParam.Expression = "height"; } } LogTrace("Dimensions with user parameter values created, starting extrude operation"); //oSketch.DimensionConstraints.AddTwoPointDistance(oPoints[0], oPoints[1], DimensionOrientationEnum.kAlignedDim, "width", true); Profile oProfile = oSketch.Profiles.AddForSolid(); ExtrudeDefinition oExtrudeDef = oPartComDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation); oExtrudeDef.SetDistanceExtent(oPartComDef.Parameters.UserParameters.AddByExpression("length", "length", UnitsTypeEnum.kMillimeterLengthUnits), PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature oExtrude = oPartComDef.Features.ExtrudeFeatures.Add(oExtrudeDef); //oExtrude.FeatureDimensions[1].Parameter.Name = "length"; LogTrace("Extrude operation finished"); XmlDocument xmlDoc = new XmlDocument(); string currentDir = System.IO.Directory.GetCurrentDirectory(); string projectDir = Directory.GetParent(currentDir).Parent.FullName; LogTrace("Reading XML input file from " + projectDir); xmlDoc.Load(System.IO.Path.Combine(projectDir, "React-BIM-output.xml")); //xmlDoc.Load("C:\\webapps\\IpartCreator\\React-BIM-output.xml"); XmlNodeList memberNodeList = xmlDoc.GetElementsByTagName("Member"); XmlNodeList partNumberNodeList = xmlDoc.GetElementsByTagName("PartNumber"); XmlNodeList widthNodeList = xmlDoc.GetElementsByTagName("width"); XmlNodeList heightNodeList = xmlDoc.GetElementsByTagName("height"); XmlNodeList lengthNodeList = xmlDoc.GetElementsByTagName("length"); LogTrace("XML tag values imported"); LogTrace("Creating iPart"); iPartFactory oFactory = oPartComDef.CreateFactory(); Worksheet oWS = oFactory.ExcelWorkSheet; Workbook oWB = (Workbook)oWS.Parent; LogTrace("Generating Excel file for iPart"); oWS.Cells[1, 1] = "Member<defaultRow>1</defaultRow><filename></filename>"; oWS.Cells[1, 2] = "Part Number [Project]"; oWS.Cells[1, 3] = "width"; oWS.Cells[1, 4] = "height"; oWS.Cells[1, 5] = "length"; for (int i = 0; i < memberNodeList.Count; i++) { oWS.Cells[(i + 2), 1] = memberNodeList[i].InnerText; oWS.Cells[(i + 2), 2] = partNumberNodeList[i].InnerText; oWS.Cells[(i + 2), 3] = widthNodeList[i].InnerText; oWS.Cells[(i + 2), 4] = heightNodeList[i].InnerText; oWS.Cells[(i + 2), 5] = lengthNodeList[i].InnerText; } oWB.Save(); oWB.Close(); LogTrace("Excel created"); oPartDoc.Update(); string iPartPath = projectDir + "/results/bimipart.ipt"; int iNumRows = oFactory.TableRows.Count; LogTrace("Saving iPart to " + iPartPath); oPartDoc.SaveAs(iPartPath, false); LogTrace("Opening new assembly template"); AssemblyDocument oAssyDoc = (AssemblyDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), true); AssemblyComponentDefinition oAssyComDef = oAssyDoc.ComponentDefinition; ComponentOccurrences oAssyCompOccs = oAssyComDef.Occurrences; LogTrace("Creating Matrix"); Matrix oPos = oTG.CreateMatrix(); int oStep = 0; int iRow; LogTrace("Placing iPart members to assembly"); for (iRow = 1; iRow <= iNumRows; iRow++) { oStep = oStep + 150; oPos.SetTranslation(oTG.CreateVector(oStep, oStep, 0), false); ComponentOccurrence oOcc = oAssyCompOccs.AddiPartMember(iPartPath, oPos, iRow); } string assyPath = projectDir + "/results/bimassy.iam"; LogTrace("Saving Assembly file to " + assyPath); oAssyDoc.SaveAs(assyPath, false); }
private void CircleSketch(int x, int y) { try { PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument; PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; PlanarSketch oSketch = default(PlanarSketch); oSketch = oCompDef.Sketches[1]; oSketch.SketchCircles[1].Radius = x; oSketch.SketchCircles[2].Radius = x - 2; Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); ExtrudeFeature oExtrude = default(ExtrudeFeature); oExtrude = oCompDef.Features.ExtrudeFeatures[1]; oExtrude.Definition.Profile = oProfile; oExtrude.Definition.SetDistanceExtent(y, Inventor.PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); /*ExtrudeFeature oExtrude = default(ExtrudeFeature); * oExtrude = oCompDef.Features.ExtrudeFeatures[1]; * oExtrude.*/ Random r = new Random(); int rand = r.Next(1, 20); if (rand > 17) { int ner = r.Next(1, 3); movrot.ChangeView(ner, 0, 0, apply: false); } if (x > 450 && y > 300) { oCompDef = oPartDoc.ComponentDefinition; foreach (Inventor.PartFeature oFeat in oCompDef.Features) { oFeat.Delete(); } foreach (Inventor.Sketch oSket in oCompDef.Sketches) { oSket.Delete(); } } if (rand == 15) { oCompDef = oPartDoc.ComponentDefinition; oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[1]); oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), x); oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), x - 2); oProfile = oSketch.Profiles.AddForSolid(); ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, Inventor.PartFeatureOperationEnum.kJoinOperation); oExtrudeDef.SetDistanceExtent(y, Inventor.PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef); } } catch { PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument; PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; PlanarSketch oSketch = default(PlanarSketch); oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[1]); oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), x); oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), x - 2); Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, Inventor.PartFeatureOperationEnum.kJoinOperation); oExtrudeDef.SetDistanceExtent(y, Inventor.PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); ExtrudeFeature oExtrude = default(ExtrudeFeature); oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef); } }
private void Button1_Click(object sender, EventArgs e) { PartDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, null), true) as PartDocument; // Get the XZ Plane WorkPlane oWorkPlane = oDoc.ComponentDefinition.WorkPlanes[2]; PlanarSketch oSketch = oDoc.ComponentDefinition.Sketches.Add(oWorkPlane, false); TransientGeometry oTG = mApp.TransientGeometry; //Create some transient points used for defining the lines (see BRep Module) Point2d[] oPoints = new Point2d[5]; oPoints[0] = oTG.CreatePoint2d(0, 0); oPoints[1] = oTG.CreatePoint2d(-10, 0); oPoints[2] = oTG.CreatePoint2d(-10, -10); oPoints[3] = oTG.CreatePoint2d(5, -10); oPoints[4] = oTG.CreatePoint2d(5, -5); //Add the sketchlines, coincident constraints will be created automatically //since the "Line.EndSketchPoint" are provided each time we create a new line SketchLine[] oLines = new SketchLine[5]; oLines[0] = oSketch.SketchLines.AddByTwoPoints(oPoints[0], oPoints[1]); oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, oPoints[2]); oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, oPoints[3]); oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oPoints[4]); oSketch.SketchArcs.AddByCenterStartEndPoint(oTG.CreatePoint2d(0, -5), oLines[3].EndSketchPoint, oLines[0].StartSketchPoint, true); //Create a profile for the extrusion, here no need to worry since there is only //a single profile that is possible Profile oProfile = oSketch.Profiles.AddForSolid(true, null, null); //this is the old way, i.e. create the extrude feature directly. it is still supported for backward compatibility //ExtrudeFeature oExtrude = oDoc.ComponentDefinition.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, // 5.0, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, PartFeatureOperationEnum.kNewBodyOperation, 0.0); // Definition Way: PartComponentDefinition oPartDocDef = oDoc.ComponentDefinition; // get ExtrudeFeatures collection ExtrudeFeatures extrudes = oPartDocDef.Features.ExtrudeFeatures; // Create an extrude definition in the new surface body ExtrudeDefinition extrudeDef = extrudes.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation); // Modify the extent and taper angles. extrudeDef.SetDistanceExtent(8, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); extrudeDef.SetDistanceExtentTwo(20); extrudeDef.TaperAngle = "-2 deg"; extrudeDef.TaperAngleTwo = "-10 deg"; // Create the extrusion. ExtrudeFeature extrude = extrudes.Add(extrudeDef); //Fit the view programmatically Camera oCamera = mApp.ActiveView.Camera; oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation; oCamera.Apply(); mApp.ActiveView.Fit(true); }
/// <summary> /// Построение зубьев вала. /// </summary> private void BuildTeeth() { if (ValParameters.GetParameter(ParameterType.NumTeethLevelSetted).Value == 1) { _numTeethLevelL = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value - ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value; _numTeethLevelR = ValParameters.GetParameter(ParameterType.RadiusFirstLevel).Value + ValParameters.GetParameter(ParameterType.RadiusFirstLevel).Value / 10; _numTeethLevelQ = ValParameters.GetParameter(ParameterType.RadiusFirstLevel).Value; _distance = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value; } // if (ValParameters.GetParameter(ParameterType.NumTeethLevelSetted).Value == 2) { _numTeethLevelL = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value; _numTeethLevelR = ValParameters.GetParameter(ParameterType.RadiusSecondLevel).Value + ValParameters.GetParameter(ParameterType.RadiusSecondLevel).Value / 10; _numTeethLevelQ = ValParameters.GetParameter(ParameterType.RadiusSecondLevel).Value; _distance = ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value; } // if (ValParameters.GetParameter(ParameterType.NumTeethLevelSetted).Value == 3) { _numTeethLevelL = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value + ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value; _numTeethLevelR = ValParameters.GetParameter(ParameterType.RadiusThirdLevel).Value + ValParameters.GetParameter(ParameterType.RadiusThirdLevel).Value / 10; _numTeethLevelQ = ValParameters.GetParameter(ParameterType.RadiusThirdLevel).Value; _distance = ValParameters.GetParameter(ParameterType.LengthThirdLevel).Value; } // if (ValParameters.GetParameter(ParameterType.NumTeethLevelSetted).Value == 4) { _numTeethLevelL = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value + ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value + ValParameters.GetParameter(ParameterType.LengthThirdLevel).Value; _numTeethLevelR = ValParameters.GetParameter(ParameterType.RadiusFourthLevel).Value + ValParameters.GetParameter(ParameterType.RadiusFourthLevel).Value / 10; _numTeethLevelQ = ValParameters.GetParameter(ParameterType.RadiusFourthLevel).Value; _distance = ValParameters.GetParameter(ParameterType.LengthFourthLevel).Value; } // if (ValParameters.GetParameter(ParameterType.NumTeethLevelSetted).Value == 5) { _numTeethLevelL = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value + ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value + ValParameters.GetParameter(ParameterType.LengthThirdLevel).Value + ValParameters.GetParameter(ParameterType.LengthFourthLevel).Value; _numTeethLevelR = ValParameters.GetParameter(ParameterType.RadiusFifthLevel).Value + ValParameters.GetParameter(ParameterType.RadiusFifthLevel).Value / 10; _numTeethLevelQ = ValParameters.GetParameter(ParameterType.RadiusFifthLevel).Value; _distance = ValParameters.GetParameter(ParameterType.LengthFifthLevel).Value; } // if (ValParameters.GetParameter(ParameterType.NumTeethLevelSetted).Value == 6) { _numTeethLevelL = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value + ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value + ValParameters.GetParameter(ParameterType.LengthThirdLevel).Value + ValParameters.GetParameter(ParameterType.LengthFourthLevel).Value + ValParameters.GetParameter(ParameterType.LengthFifthLevel).Value; _numTeethLevelR = ValParameters.GetParameter(ParameterType.RadiusSixthLevel).Value + ValParameters.GetParameter(ParameterType.RadiusSixthLevel).Value / 10; _numTeethLevelQ = ValParameters.GetParameter(ParameterType.RadiusSixthLevel).Value; _distance = ValParameters.GetParameter(ParameterType.LengthSixthLevel).Value; } // if (ValParameters.GetParameter(ParameterType.NumTeethLevelSetted).Value == 7) { _numTeethLevelL = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value + ValParameters.GetParameter(ParameterType.LengthSecondLevel).Value + ValParameters.GetParameter(ParameterType.LengthThirdLevel).Value + ValParameters.GetParameter(ParameterType.LengthFourthLevel).Value + ValParameters.GetParameter(ParameterType.LengthFifthLevel).Value + ValParameters.GetParameter(ParameterType.LengthSixthLevel).Value; _numTeethLevelR = ValParameters.GetParameter(ParameterType.RadiusSeventhLevel).Value + ValParameters.GetParameter(ParameterType.RadiusSeventhLevel).Value / 10; _numTeethLevelQ = ValParameters.GetParameter(ParameterType.RadiusSeventhLevel).Value; _distance = ValParameters.GetParameter(ParameterType.LengthSeventhLevel).Value; } PlanarSketch StemSketchQ = _inventorApi.MakeNewSketch(3, _numTeethLevelL);// второй параметр отодвигает по Z координате на заданную длину. Point2d pointQ = _inventorApi.TransientGeometry.CreatePoint2d(_numTeethLevelR, 0); Point2d CenterPointQ = _inventorApi.TransientGeometry.CreatePoint2d(_numTeethLevelQ, 0); _inventorApi.DrawPolygon(pointQ, StemSketchQ, CenterPointQ); //DrawPolygon(pointQ, StemSketchQ, CenterPointQ); ExtrudeDefinition extrudeDefQ = _inventorApi.PartDefinition. Features. ExtrudeFeatures. CreateExtrudeDefinition(StemSketchQ.Profiles.AddForSolid(), PartFeatureOperationEnum.kCutOperation); extrudeDefQ.SetDistanceExtent( _distance, // insteadof _distance = ValParameters.GetParameter(ParameterType.LengthFirstLevel).Value; PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature extrudeQ = _inventorApi.PartDefinition.Features.ExtrudeFeatures.Add(extrudeDefQ); //Базовые оси //для создания массива. WorkAxis XAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis YAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis ZAxis = _inventorApi.PartDefinition.WorkAxes[3]; //Create an object collection ObjectCollection objectCollection = _inventorApi.CreateObjectCollection(); objectCollection.Add(extrudeQ); _inventorApi.PartDefinition.Features.CircularPatternFeatures.Add( objectCollection, ZAxis, true, // (int)(ValParameters.GetParameter(ParameterType.RadiusThirdLevel).Value/1.5), (int)(ValParameters.GetParameter(ParameterType.NumTeeth).Value), "360 deg", true, PatternComputeTypeEnum.kAdjustToModelCompute); }
/// <summary> /// 'create more feature based on the start face of the first extrude feature /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { // create a new document with an extrude feature. createFeature(); PartDocument oPartDoc = mApp.ActiveDocument as PartDocument; // get a start face of the extrude feature ExtrudeFeature oExtrudeF = oPartDoc.ComponentDefinition.Features.ExtrudeFeatures[1]; Face oFirstFace = oExtrudeF.StartFaces[1]; // add a new sketch on the basis of the start face PlanarSketch oSketch = oPartDoc.ComponentDefinition.Sketches.Add(oFirstFace, false); TransientGeometry oTG = mApp.TransientGeometry; // create a circle and make a profile from the sketch oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, -5), 1); Profile oProfile = oSketch.Profiles.AddForSolid(true, null, null); // get ExtrudeFeatures collection ExtrudeFeatures extrudes = oPartDoc.ComponentDefinition.Features.ExtrudeFeatures; // Create an extrude definition in the new surface body ExtrudeDefinition extrudeDef = extrudes.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation); // Modify the extent extrudeDef.SetDistanceExtent(2, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); // Create the extrusion. ExtrudeFeature extrude = extrudes.Add(extrudeDef); // FilletFeatures oFilletFs = oPartDoc.ComponentDefinition.Features.FilletFeatures; //create fillet definition FilletDefinition oFilletDef = oFilletFs.CreateFilletDefinition(); // FaceCollection FaceCollection oFacesCollOne = mApp.TransientObjects.CreateFaceCollection(); oFacesCollOne.Add(oFirstFace); FaceCollection oFacesCollTwo = mApp.TransientObjects.CreateFaceCollection(); oFacesCollTwo.Add(extrude.SideFaces[1]);//cylinder face oFilletDef.AddFaceSet(oFacesCollOne, oFacesCollTwo, 0.1); oFilletFs.Add(oFilletDef); //Fit the view programmatically Camera oCamera = mApp.ActiveView.Camera; oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation; oCamera.Apply(); mApp.ActiveView.Fit(true); }
public void RunWithArguments(Document doc, NameValueMap map) { LogTrace("Initialiting"); PartDocument oPartDoc = (PartDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true); LogTrace("Part template opened"); TransientGeometry oTG = inventorApplication.TransientGeometry; PartComponentDefinition oPartComDef = oPartDoc.ComponentDefinition; UserParameters oParams = oPartComDef.Parameters.UserParameters; XmlDocument xmlDoc = new XmlDocument(); string currentDir = System.IO.Directory.GetCurrentDirectory(); string projectDir = Directory.GetParent(currentDir).Parent.FullName; LogTrace("Reading XML input file from " + projectDir); xmlDoc.Load(System.IO.Path.Combine(projectDir, "react-test-output.xml")); //xmlDoc.Load("react-test-output.xml"); //xmlDoc.Load("C:\\webapps\\IpartCreator\\React-BIM-output.xml"); XmlNodeList FloorList = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor"); XmlNodeList FloorPointList = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point"); XmlNodeList ComponentName = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/ComponentName"); XmlNodeList PointX = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/X"); XmlNodeList PointY = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/Y"); XmlNodeList PointZ = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/Z"); for (int i = 0; i < FloorList.Count; i++) { //oParams.AddByExpression("ComponentName" + i, ComponentName[i].InnerText, UnitsTypeEnum.kUnitlessUnits); int numPoint = FloorPointList.Count / FloorList.Count; Point2d[] oPoints = new Point2d[numPoint]; SketchPoint[] osPoints = new SketchPoint[numPoint]; for (int j = 0; j < numPoint; j++) { oParams.AddByExpression("PointX" + j, PointX[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits); oParams.AddByExpression("PointY" + j, PointY[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits); oParams.AddByExpression("PointZ" + j, PointZ[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits); oPoints[j] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("PointX" + j, UnitsTypeEnum.kMillimeterLengthUnits), oPartComDef.Parameters.GetValueFromExpression("PointY" + j, UnitsTypeEnum.kMillimeterLengthUnits)); } SketchLine[] oLines = new SketchLine[numPoint]; PlanarSketch oSketch = oPartComDef.Sketches.Add(oPartComDef.WorkPlanes[2]); osPoints[0] = oSketch.SketchPoints.Add(oPoints[0]); osPoints[1] = oSketch.SketchPoints.Add(oPoints[1]); osPoints[2] = oSketch.SketchPoints.Add(oPoints[2]); osPoints[3] = oSketch.SketchPoints.Add(oPoints[3]); oLines[0] = oSketch.SketchLines.AddByTwoPoints(osPoints[0], osPoints[1]); oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, osPoints[2]); oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, osPoints[3]); oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oLines[0].StartSketchPoint); oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[0], osPoints[1], DimensionOrientationEnum.kAlignedDim, oPoints[1]); //d0// oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[1], osPoints[2], DimensionOrientationEnum.kAlignedDim, oPoints[3]); //d1// Profile oProfile = oSketch.Profiles.AddForSolid(); ExtrudeDefinition oExtrudeDef = oPartComDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation); oExtrudeDef.SetDistanceExtent(oPartComDef.Parameters.UserParameters.AddByExpression("length", "8", UnitsTypeEnum.kMillimeterLengthUnits), PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature oExtrude = oPartComDef.Features.ExtrudeFeatures.Add(oExtrudeDef); string PartPath = projectDir + "/results/" + ComponentName[i].InnerText + i + ".ipt"; //string PartPath = ComponentName[i].InnerText + i + ".ipt"; oPartDoc.SaveAs(PartPath, false); oExtrude.Delete(); } oPartDoc.Close(false); AssemblyDocument oAssyDoc = (AssemblyDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), true); AssemblyComponentDefinition oAssyComDef = oAssyDoc.ComponentDefinition; ComponentOccurrences oAssyCompOccs = oAssyComDef.Occurrences; Matrix oPos = oTG.CreateMatrix(); int oStep = 0; int icomp; int numite = FloorPointList.Count / FloorList.Count; for (icomp = 0; icomp <= numite; icomp++) { oStep = oStep + 150; oPos.SetTranslation(oTG.CreateVector(oStep, oStep, 0), false); string PartPath = projectDir + "/results/" + ComponentName[icomp].InnerText + icomp + ".ipt"; //string PartPath = ComponentName[icomp].InnerText + icomp + ".ipt"; ComponentOccurrence oOcc = oAssyCompOccs.Add(PartPath, oPos); } oAssyDoc.SaveAs(projectDir + "/results/result.iam", false); //oAssyDoc.SaveAs("result.iam", false); oAssyDoc.Close(); ZipFile.CreateFromDirectory(projectDir + "/results", projectDir + "/forgeResult.zip"); }
private void Button_ok_Click(object sender, EventArgs e) { // references to some useful objects TransientGeometry geom = m_inventorApplication.TransientGeometry; //PartDocument document = m_inventorApplication.ActiveDocument as PartDocument; //_Document document = m_inventorApplication.ActiveDocument; /* * if (document == null) * { * AssemblyDocument asm = m_inventorApplication.ActiveDocument as AssemblyDocument; * m_inventorApplication.ActiveDocument; * } */ PartComponentDefinition def; // = document.ComponentDefinition; UnitsOfMeasure units; // = document.UnitsOfMeasure; UserParameters user_params; Document document = m_inventorApplication.ActiveDocument; if (m_inventorApplication.ActiveDocument is AssemblyDocument) { AssemblyDocument doc = m_inventorApplication.ActiveDocument as AssemblyDocument; PartDocument part = doc.ActivatedObject as PartDocument; if (part == null) { m_inventorApplication.ErrorManager.Show("Please activate a part!", true, false); return; } def = part.ComponentDefinition; units = part.UnitsOfMeasure; user_params = part.ComponentDefinition.Parameters.UserParameters; } else if (m_inventorApplication.ActiveDocument is PartDocument) { PartDocument doc = m_inventorApplication.ActiveDocument as PartDocument; def = doc.ComponentDefinition; units = doc.UnitsOfMeasure; user_params = doc.ComponentDefinition.Parameters.UserParameters; } else { m_inventorApplication.ErrorManager.Show("Current document is neither an Assembly nor a Part.", true, false); return; } // get and check selected faces ObjectsEnumerator JustSelectedEntities = m_selects.SelectedEntities; if (JustSelectedEntities.Count == 0) { m_inventorApplication.ErrorManager.Show("Select at least one planar, rectangular face.", true, false); return; } foreach (Object _f in JustSelectedEntities) { Face f = _f as Face; if (f == null) { m_inventorApplication.ErrorManager.Show("Somehow, you managed to select something that isn't a face. This should not happen, please report it.", true, false); return; } if (f.Edges.Count != 4) { m_inventorApplication.ErrorManager.Show("Please only select rectangular faces.", true, false); return; } } // TODO: catch exception when invalid was is entered UserParameter tab_user_constr; if (m_dialog.mode_count.Checked) { tab_user_constr = user_params.AddByExpression("tab_count", m_dialog.tab_size_input.Text, UnitsTypeEnum.kUnitlessUnits); } else { tab_user_constr = user_params.AddByExpression("tab_size", m_dialog.tab_size_input.Text, UnitsTypeEnum.kDefaultDisplayLengthUnits); } int total_operations = JustSelectedEntities.Count; WorkAxis[] extrusion_dir = new WorkAxis[total_operations]; bool[] long_edge_dir = new bool[total_operations]; PlanarSketch[] all_sketches = new PlanarSketch[total_operations]; Profile[] profile = new Profile[total_operations]; ExtrudeFeature[] extrusion = new ExtrudeFeature[total_operations]; TwoPointDistanceDimConstraint[] tab_length_constr = new TwoPointDistanceDimConstraint[total_operations]; TwoPointDistanceDimConstraint[] tab_widthdepth_constr = new TwoPointDistanceDimConstraint[total_operations]; TwoPointDistanceDimConstraint[] total_length_constr = new TwoPointDistanceDimConstraint[total_operations]; RectangularPatternFeature[] rect_pattern = new RectangularPatternFeature[total_operations]; Transaction transaction = m_inventorApplication.TransactionManager.StartTransaction(m_inventorApplication.ActiveDocument, "LaserTab"); // create extrusion feature for each face int i = 0; foreach (Object _f in JustSelectedEntities) { Face f = _f as Face; if (_f is FaceProxy) { f = ((FaceProxy)_f).NativeObject; } // TODO: make sure active document is a partDocument and ActiveEditObject is not a sketch (should be also a partDocument?) // TODO: wrap it all into a ClientFeature // TODO: maybe also wrap it in a Transaction? // create sketch PlanarSketch sketch = def.Sketches.Add(f, false); // don't project anything //PlanarSketch sketch = def.Sketches.Add(f, true); // project existing geometry //PlanarSketch sketch = def.Sketches.AddWithOrientation(f, long_edge, true, true, long_edge.StartVertex, true); Edge short_edge, long_edge; Vertex vert_origin, vert_short_end, vert_long_end; determine_orientation(f, out long_edge, out short_edge, out vert_origin, out vert_long_end, out vert_short_end); // remember wheter 'long_edge' starts or stops at 'P_orig' (which is important for the direction of the rectangular pattern) long_edge_dir[i] = long_edge.StartVertex == vert_origin; extrusion_dir[i] = def.WorkAxes.AddByLine(long_edge, true); // project important points SketchPoint P_orig = sketch.AddByProjectingEntity(vert_origin) as SketchPoint; SketchPoint P_long = sketch.AddByProjectingEntity(vert_long_end) as SketchPoint; SketchPoint P_short = sketch.AddByProjectingEntity(vert_short_end) as SketchPoint; // fails! :( // driven constraint of short dimension (determining thickness and depth of tab) tab_widthdepth_constr[i] = sketch.DimensionConstraints.AddTwoPointDistance( P_orig, P_short, DimensionOrientationEnum.kAlignedDim, P_short.Geometry, true); // driven constraint of long dimenstion (determining number/size of tabs) total_length_constr[i] = sketch.DimensionConstraints.AddTwoPointDistance( P_orig, P_long, DimensionOrientationEnum.kAlignedDim, P_long.Geometry, true); // appearantly, Profiles.AddForSolid() doesn't like lines that are made entirely out of projected points... (maybe because the line already exists?) SketchPoint P_orig_proj = P_orig, P_short_proj = P_short; P_short = sketch.SketchPoints.Add(P_short_proj.Geometry, false); P_orig = sketch.SketchPoints.Add(P_orig_proj.Geometry, false); // create dimension constraints // TODO: calculate better position for text label //Debug.Print("constraint short: {0} = {1}", constr_short.Parameter.Expression, constr_short.Parameter.Value); //Debug.Print("constraint long: {0} = {1}", constr_long.Parameter.Expression, constr_long.Parameter.Value); // create endpoint for rectangle Point2d P_end2 = P_short.Geometry.Copy(); Point2d P_end1 = P_orig.Geometry.Copy(); Vector2d long_direction = P_orig.Geometry.VectorTo(P_long.Geometry); long_direction.ScaleBy(0.2); P_end1.TranslateBy(long_direction); P_end2.TranslateBy(long_direction); SketchPoint P_end1_sk = sketch.SketchPoints.Add(P_end1, false); SketchPoint P_end2_sk = sketch.SketchPoints.Add(P_end2, false); // constrain endpoints properly //sketch.GeometricConstraints.AddCoincident((SketchEntity)long_line2, (SketchEntity)P_end2_sk); //sketch.GeometricConstraints.AddCoincident((SketchEntity)long_line, (SketchEntity)P_end1_sk); // constraint for tab length (twice, once for each side of the rectangle) TwoPointDistanceDimConstraint tab_len_constraint1 = sketch.DimensionConstraints.AddTwoPointDistance(P_orig, P_end1_sk, DimensionOrientationEnum.kAlignedDim, P_end1); TwoPointDistanceDimConstraint tab_len_constraint2 = sketch.DimensionConstraints.AddTwoPointDistance(P_short, P_end2_sk, DimensionOrientationEnum.kAlignedDim, P_end2); tab_length_constr[i] = tab_len_constraint1; // {0}: total length // {1}: user input (count or length of single tab) string expr; if (m_dialog.mode_count.Checked) { if (m_dialog.force_parity.Checked) { if (m_dialog.parity_even.Checked) { expr = "{0} / ( round({1}/2)*2 )"; } else { expr = "{0} / ( round( ({1}+1)/2 )*2 - 1 )"; } } else { expr = "{0} / {1}"; } } else { // TODO: take dropdown of >/</~ into account if (m_dialog.force_parity.Checked) { if (m_dialog.parity_even.Checked) { expr = "{0} / ( round( {0}/{1}/2 )*2 )"; } else { expr = "{0} / ( round( ({0}/{1}+1)/2 )*2 - 1)"; } } else { expr = "{0} / round({0}/{1})"; } } tab_len_constraint1.Parameter.Expression = string.Format(expr, total_length_constr[i].Parameter.Name, tab_user_constr.Name); tab_len_constraint2.Parameter.Expression = tab_len_constraint1.Parameter.Name; // create a rectangle based on these points // two-point rectangle is always axis-aligned -> doesn't work for rotated stuff //SketchEntitiesEnumerator rect = sketch.SketchLines.AddAsTwoPointRectangle(P_orig, P_end_sk); // this is cumbersome, as the third point is transient and therefore the rectangle would have to be constrained afterwards //SketchEntitiesEnumerator rect = sketch.SketchLines.AddAsThreePointRectangle(P_orig, P_short, P_end); ObjectCollection rect = m_inventorApplication.TransientObjects.CreateObjectCollection(); rect.Add(sketch.SketchLines.AddByTwoPoints(P_orig, P_end1_sk)); rect.Add(sketch.SketchLines.AddByTwoPoints(P_end1_sk, P_end2_sk)); rect.Add(sketch.SketchLines.AddByTwoPoints(P_end2_sk, P_short)); rect.Add(sketch.SketchLines.AddByTwoPoints(P_short, P_orig)); // constrain rectangle if (m_dialog.offset.Checked) { sketch.GeometricConstraints.AddCoincident((SketchEntity)rect[1], (SketchEntity)P_orig_proj); sketch.GeometricConstraints.AddCoincident((SketchEntity)rect[3], (SketchEntity)P_short_proj); sketch.GeometricConstraints.AddPerpendicular((SketchEntity)rect[1], (SketchEntity)rect[2]); TwoPointDistanceDimConstraint offset_dist = sketch.DimensionConstraints.AddTwoPointDistance(P_orig, P_orig_proj, DimensionOrientationEnum.kAlignedDim, P_orig_proj.Geometry); offset_dist.Parameter.Expression = tab_len_constraint1.Parameter.Name; } else { sketch.GeometricConstraints.AddCoincident((SketchEntity)P_short, (SketchEntity)P_short_proj); sketch.GeometricConstraints.AddCoincident((SketchEntity)P_orig, (SketchEntity)P_orig_proj); } sketch.GeometricConstraints.AddCoincident((SketchEntity)rect[1], (SketchEntity)P_long); sketch.GeometricConstraints.AddParallel((SketchEntity)rect[1], (SketchEntity)rect[3]); profile[i] = sketch.Profiles.AddForSolid(false, rect); all_sketches[i] = sketch; i++; } // do extrusions for (i = 0; i < total_operations; i++) { string dist_expr; if (m_dialog.auto_depth.Checked) { // use thickness of material dist_expr = tab_widthdepth_constr[i].Parameter.Name; } else { // use user input // TODO: validate! dist_expr = m_dialog.tab_depth_input.Text; } PartFeatureExtentDirectionEnum dir; PartFeatureOperationEnum op; if (m_dialog.extrude_positive.Checked) { dir = PartFeatureExtentDirectionEnum.kPositiveExtentDirection; op = PartFeatureOperationEnum.kJoinOperation; } else { dir = PartFeatureExtentDirectionEnum.kNegativeExtentDirection; op = PartFeatureOperationEnum.kCutOperation; } // extrude said rectangle ExtrudeDefinition extrusion_def = def.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile[i], op); extrusion_def.SetDistanceExtent(dist_expr, dir); extrusion[i] = def.Features.ExtrudeFeatures.Add(extrusion_def); } // do rectangular patterns for (i = 0; i < total_operations; i++) { // now repeat that extrusion ObjectCollection col = m_inventorApplication.TransientObjects.CreateObjectCollection(); col.Add(extrusion[i]); // TODO: is ceil() actually correct here? string offset = (m_dialog.offset.Checked ? "1" : "0"); string count_expr = string.Format("ceil(round({0} / {1} - {2}) / 2)", total_length_constr[i].Parameter.Name, tab_length_constr[i].Parameter.Name, offset); RectangularPatternFeatureDefinition pattern_def = def.Features.RectangularPatternFeatures.CreateDefinition( col, extrusion_dir[i], long_edge_dir[i], count_expr, tab_length_constr[i].Parameter.Name + "*2"); // TODO: we could use PatternSpacingType kFitToPathLength here... try { rect_pattern[i] = def.Features.RectangularPatternFeatures.AddByDefinition(pattern_def); } catch (Exception ex) { Debug.Print("rect pattern failed: {0}", ex.Message); Debug.Print("long edge: {0}, dir: {1}, count_expr = '{2}', len = '{3}'", extrusion_dir[i], long_edge_dir[i], count_expr, tab_length_constr[i].Parameter.Name + "*2"); transaction.End(); return; } } stop_selection(); // create custom feature (called a ClientFeature by Inventor) containing all our sketches, extrusions and patterns in a single node object start_element; if (total_operations == 1) { // if there is only a single operation, the tree looks like this: /* * - extrusion 1 (consumed sketch 1) * - pattern 1 */ start_element = extrusion[0]; } else { // if there are multiple operations, the sketch is not consumed by the extrusion // and the tree looks like this: /* * - sketch 1 * - sketch 2 * - extrusion 1 * - extrusion 2 * - pattern 1 * - pattern 2 */ start_element = all_sketches[0]; } ClientFeatureDefinition feature_def = def.Features.ClientFeatures.CreateDefinition("LaserTab", start_element, rect_pattern[total_operations - 1]); ClientFeature feature = def.Features.ClientFeatures.Add(feature_def, "{0defbf22-e302-4266-9bc9-fb80d5c8eb7e}"); // load the icon for our custom feature if not done so already if (m_browser_icon == null) { stdole.IPictureDisp icon = PictureConverter.ImageToPictureDisp(Properties.Resources.browser_icon_16); m_browser_icon = document.BrowserPanes.ClientNodeResources.Add("{0defbf22-e302-4266-9bc9-fb80d5c8eb7e}", -1, icon); } NativeBrowserNodeDefinition ndef = document.BrowserPanes[1].GetBrowserNodeFromObject(feature).BrowserNodeDefinition as NativeBrowserNodeDefinition; ndef.OverrideIcon = m_browser_icon; transaction.End(); }
/// <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); }
private void circleSticker(ref PartDocument pDoc, double heigth, double width, double R, string txt = "", double thickness = 0.1) { PartComponentDefinition compDef = pDoc.ComponentDefinition; heigth /= 10; width /= 10; thickness /= 10; PlanarSketch ps = compDef.Sketches.Add(compDef.WorkPlanes[2]); //SketchEntity origin = ps.AddByProjectingEntity(compDef.WorkPoints[1]); double alfa = alfaFromL(heigth, R); Point2d startPt = m_TG.CreatePoint2d(); SketchArc arc = ps.SketchArcs.AddByCenterStartSweepAngle(startPt, R, 3.1415926 / 2 - alfa / 2, alfa); //ObjectCollection objs = invApp.TransientObjects.CreateObjectCollection(); //objs.Add(arc); //ps.RotateSketchObjects(objs, arc.CenterSketchPoint.Geometry, 1,RemoveConstraints:true); //arc = (SketchArc)en[1]; //ps.GeometricConstraints.AddVerticalAlign((SketchPoint)origin, arc.CenterSketchPoint); ObjectCollection objCol = invApp.TransientObjects.CreateObjectCollection(); objCol.Add(arc); SketchEntitiesEnumerator sArc = ps.OffsetSketchEntitiesUsingDistance(objCol, thickness, true); SketchArc arc2 = (SketchArc)sArc[1]; ps.SketchLines.AddByTwoPoints(arc2.StartSketchPoint, arc.StartSketchPoint); ps.SketchLines.AddByTwoPoints(arc2.EndSketchPoint, arc.EndSketchPoint); Profile pr = ps.Profiles.AddForSolid(); ExtrudeDefinition extDef = compDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(pr, PartFeatureOperationEnum.kNewBodyOperation); extDef.SetDistanceExtent(width / 2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection); extDef.SetDistanceExtentTwo(width / 2); ExtrudeFeature extr = compDef.Features.ExtrudeFeatures.Add(extDef); extr.Appearance = InvDoc.u.createColor(pDoc, "white_", "белый_", 255, 255, 255); if (txt != "") { ps = compDef.Sketches.Add(compDef.WorkPlanes[3]); Inventor.TextBox tb = ps.TextBoxes.AddByRectangle(pts(-heigth, -width), pts(heigth, width), txt); tb.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter; tb.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle; tb.SingleLineText = false; tb.Rotation = Math.PI; if (mirror) { tb.Rotation = Math.PI; } if (this.radioButton1.Checked == false) { //ObjectCollection col = invApp.TransientObjects.CreateObjectCollection(); //col.Add(tb); //ps.RotateSketchObjects(col, pt, Math.PI / 4); tb.Rotation -= Math.PI / 2; } Face face2 = null; foreach (Face f in compDef.SurfaceBodies[1].Faces) { if (f.SurfaceType == SurfaceTypeEnum.kCylinderSurface) { double val = Math.Round(((Cylinder)f.Geometry).Radius, 3) * 100; val = Math.Round(val, 0); if /*((int)val == (int)((R + thickness)*100))*/ (InvDoc.u.eq(val, (R + thickness) * 100)) { face2 = f; break; } } } EmbossFeature emb = compDef.Features.EmbossFeatures.AddEmbossFromFace(ps.Profiles.AddForSolid(false, ps.TextBoxes), 0.0005, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, WrapFace: face2); emb.Appearance = InvDoc.u.createColor(pDoc, "black_", "черный_", 0, 0, 0); } }