/// <summary> /// Отрисовка второй ступени (тонкой) /// </summary> private void BuildSecondStage(RocketBuildStyle style) { WorkAxis xAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis yAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis zAxis = _inventorApi.PartDefinition.WorkAxes[3]; var secondStageLenght = RocketParameters.GetParameter(ParameterType.SecondStageLength).Value; var secondStageDiameter = RocketParameters.GetParameter(ParameterType.SecondStageDiameter).Value; var coneLenght = RocketParameters.GetParameter(ParameterType.ConeLength).Value; var secondStagePoint1 = _inventorApi.TransientGeometry.CreatePoint2d(0, 0); var secondStagePoint2 = _inventorApi.TransientGeometry. CreatePoint2d(secondStageDiameter, coneLenght + secondStageLenght); var secondStagePoint3 = _inventorApi.TransientGeometry. CreatePoint2d(secondStageDiameter, coneLenght); var xySketch = _inventorApi.MakeNewSketch(3, coneLenght); xySketch.SketchCircles.AddByCenterRadius(secondStagePoint1, secondStageDiameter); var xySketchProfile = xySketch.Profiles.AddForSolid(); var extrudeDef = _inventorApi.PartDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition( xySketchProfile, PartFeatureOperationEnum.kJoinOperation); // Отрисовка при помощи выдавливания круга (тест) extrudeDef.SetDistanceExtent(secondStageLenght, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); var extrude = _inventorApi.PartDefinition.Features.ExtrudeFeatures.Add(extrudeDef); if (style == RocketBuildStyle.Color) { _inventorApi.SetColor(extrude.Faces, "Nickel"); } }
private MateiMateDefinition findAxis(PartComponentDefinition def, Edge ed) { if (ed.TangentiallyConnectedEdges.Count == 1) { Face f = (ed.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) ? ed.Faces[1] : ed.Faces[2]; return(def.iMateDefinitions.AddMateiMateDefinition(f, 0, InferredTypeEnum.kInferredLine)); } SelectionFilterEnum[] sels = new SelectionFilterEnum[] { SelectionFilterEnum.kWorkAxisFilter }; Arc3d c = ed.Geometry as Arc3d; ObjectsEnumerator col = def.FindUsingPoint(ed.PointOnEdge, ref sels, c.Radius * 5, false); WorkAxis ax = null; foreach (var item in col.OfType <WorkAxis>()) { ax = item; //Face f = (ed.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) ? ed.Faces[1]: ed.Faces[2]; if (ax.DefinitionType == WorkAxisDefinitionEnum.kNormalToSurfaceWorkAxis) { return(def.iMateDefinitions.AddMateiMateDefinition(ax, 0, InferredTypeEnum.kInferredLine)); } ax = null; } if (ax == null) { return(iMate__(ed, def)); } return(null); }
///////////////////////////////////////////////////////////// // Use: Inserts new sketch in part and copies content // from input sketch ///////////////////////////////////////////////////////////// public static PlanarSketch InsertSketch(PartDocument doc, PlanarSketch sketch, UnitVector xAxis, UnitVector yAxis, Point basePoint) { PartComponentDefinition compDef = doc.ComponentDefinition; WorkAxis wa1 = compDef.WorkAxes.AddFixed( basePoint, xAxis, _ConstructionWorkFeature); WorkAxis wa2 = compDef.WorkAxes.AddFixed( basePoint, yAxis, _ConstructionWorkFeature); WorkPlane wp = compDef.WorkPlanes.AddByTwoLines( wa1, wa2, _ConstructionWorkFeature); WorkPoint origin = compDef.WorkPoints.AddFixed( basePoint, _ConstructionWorkFeature); PlanarSketch newSketch = compDef.Sketches.AddWithOrientation( wp, wa1, true, true, origin, false); sketch.CopyContentsTo(newSketch as Sketch); return(newSketch); }
//Массив по кругу public void Create_Circular_Array(RevolveFeature revolve) { ObjectCollection obj_collection = InventorApplication.TransientObjects.CreateObjectCollection(); obj_collection.Add(revolve); WorkAxis XAxis = partCompDef.WorkAxes[1]; CircularPatternFeature pattern = partCompDef.Features.CircularPatternFeatures.Add(obj_collection, XAxis, false, 10, "360 grad", false, PatternComputeTypeEnum.kIdenticalCompute); }
///////////////////////////////////////////////////////////// // Use: Creates CoilFeature that represents the modelized // Thread. ///////////////////////////////////////////////////////////// private static bool CreateCoilFeature(PartDocument doc, Profile profile, Vector threadDirection, Point basePoint, bool rightHanded, double taper, double pitch, double extraPitch) { try { PartComponentDefinition compDef = doc.ComponentDefinition; WorkAxis wa = compDef.WorkAxes.AddFixed( basePoint, threadDirection.AsUnitVector(), _ConstructionWorkFeature); double height = threadDirection.Length + 2 * pitch; double coilPitch = pitch * (100 + extraPitch) * 0.01; CoilFeature coil = compDef.Features.CoilFeatures.AddByPitchAndHeight( profile, wa, coilPitch, height, PartFeatureOperationEnum.kCutOperation, false, !rightHanded, taper, false, 0, 0, false, 0, 0); ObjectCollection bodies = _Application.TransientObjects. CreateObjectCollection(null); bodies.Add( compDef.SurfaceBodies[compDef.SurfaceBodies.Count]); coil.SetAffectedBodies(bodies); return(coil.HealthStatus == HealthStatusEnum.kUpToDateHealth); } catch { return(false); } }
/// <summary> /// Отрисовка и вращение стабилизаторов второй ступени /// </summary> private void BuildSecondStabilizer(RocketBuildStyle style) { WorkAxis xAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis yAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis zAxis = _inventorApi.PartDefinition.WorkAxes[3]; var secondStageDiameter = RocketParameters.GetParameter(ParameterType.SecondStageDiameter).Value; var secondStabilizerSpan = RocketParameters.GetParameter(ParameterType.SecondStabilizerSpan).Value - secondStageDiameter; var secondStabilizerCount = RocketParameters.GetParameter(ParameterType.SecondStabilizerCount).Value; var coneLenght = RocketParameters.GetParameter(ParameterType.ConeLength).Value; var secondStageLenght = RocketParameters.GetParameter(ParameterType.SecondStageLength).Value + coneLenght; var stabilizerWidth = RocketParameters.GetParameter(ParameterType.StabilizerWidth).Value; //Необходимые параметры для отрисовки стабилизатора в соответсвии с чертежом double parameterPointStabilizer1 = 0.25; double parameterPointStabilizer2 = 0.2; double parameterPointStabilizer3 = 0.05; var secondStabilizerPoint1 = _inventorApi.TransientGeometry.CreatePoint2d( secondStageDiameter, secondStageLenght - secondStageLenght * 0.25); var secondStabilizerPoint2 = _inventorApi.TransientGeometry.CreatePoint2d( secondStageDiameter, secondStageLenght); var secondStabilizerPoint3 = _inventorApi.TransientGeometry.CreatePoint2d( secondStabilizerSpan, secondStageLenght + secondStabilizerSpan * 0.2); var secondStabilizerPoint4 = _inventorApi.TransientGeometry.CreatePoint2d( secondStabilizerSpan, secondStageLenght - secondStageLenght * 0.05); var xySketch = _inventorApi.MakeNewSketch(1, 0); var line1 = xySketch.SketchLines.AddByTwoPoints(secondStabilizerPoint1, secondStabilizerPoint2); var line2 = xySketch.SketchLines.AddByTwoPoints(line1.EndSketchPoint, secondStabilizerPoint3); var line3 = xySketch.SketchLines.AddByTwoPoints(line2.EndSketchPoint, secondStabilizerPoint4); xySketch.SketchLines.AddByTwoPoints(line1.StartSketchPoint, line3.EndSketchPoint); var xySketchProfile = xySketch.Profiles.AddForSolid(); //Метод выдавливания var extrudeDef = _inventorApi.PartDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition( xySketchProfile, PartFeatureOperationEnum.kJoinOperation); //Выдвыливание extrudeDef.SetDistanceExtent(stabilizerWidth, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); var extrude = _inventorApi.PartDefinition.Features.ExtrudeFeatures.Add(extrudeDef); ObjectCollection objectCollection = _inventorApi.CreateObjectCollection(); objectCollection.Add(extrude); //Вращение по массиву _inventorApi.PartDefinition.Features.CircularPatternFeatures.Add( objectCollection, zAxis, true, secondStabilizerCount, "360 deg", true, PatternComputeTypeEnum.kAdjustToModelCompute); }
/// <summary> /// Отрисовка стабилизаторов первой ступени /// </summary> private void BuildFirstStabilizer(RocketBuildStyle style) { WorkAxis xAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis yAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis zAxis = _inventorApi.PartDefinition.WorkAxes[3]; var firstStageDiameter = RocketParameters.GetParameter(ParameterType.FirstStageDiameter).Value; var firstStageLenght = RocketParameters.GetParameter(ParameterType.FirstStageLength).Value; var rocketLenght = RocketParameters.GetParameter(ParameterType.RocketLength).Value; var nozzleLenght = firstStageLenght * 0.25; var firstStabilizerSpan = RocketParameters.GetParameter(ParameterType.FirstStabilizerSpan).Value - firstStageDiameter; var firstStabilizerCount = RocketParameters.GetParameter(ParameterType.FirstStabilizerCount).Value; var stabilizerWidth = RocketParameters.GetParameter(ParameterType.StabilizerWidth).Value; var nozzleDiameter = RocketParameters.GetParameter(ParameterType.NozzleDiameter).Value; double parameterPointStabilizer1 = 0.2; double parameterPointStabilizer2 = 0.1; double parameterPointStabilizer3 = 0.05; var firstStabilizerPoint1 = _inventorApi.TransientGeometry.CreatePoint2d( firstStageDiameter, rocketLenght - firstStageLenght * parameterPointStabilizer3); var firstStabilizerPoint2 = _inventorApi.TransientGeometry.CreatePoint2d( nozzleDiameter, rocketLenght + nozzleLenght); var firstStabilizerPoint3 = _inventorApi.TransientGeometry.CreatePoint2d( nozzleDiameter + nozzleDiameter * parameterPointStabilizer2, rocketLenght + nozzleLenght + firstStageDiameter * parameterPointStabilizer1); var firstStabilizerPoint4 = _inventorApi.TransientGeometry.CreatePoint2d( firstStabilizerSpan, rocketLenght + nozzleLenght - firstStabilizerSpan * parameterPointStabilizer2); var firstStabilizerPoint5 = _inventorApi.TransientGeometry.CreatePoint2d( firstStabilizerSpan, rocketLenght + nozzleLenght * parameterPointStabilizer2); var xySketch = _inventorApi.MakeNewSketch(1, 0); var line1 = xySketch.SketchLines.AddByTwoPoints(firstStabilizerPoint1, firstStabilizerPoint2); var line2 = xySketch.SketchLines.AddByTwoPoints(line1.EndSketchPoint, firstStabilizerPoint3); var line3 = xySketch.SketchLines.AddByTwoPoints(line2.EndSketchPoint, firstStabilizerPoint4); var line4 = xySketch.SketchLines.AddByTwoPoints(line3.EndSketchPoint, firstStabilizerPoint5); xySketch.SketchLines.AddByTwoPoints(line1.StartSketchPoint, line4.EndSketchPoint); var xySketchProfile = xySketch.Profiles.AddForSolid(); var extrudeDef = _inventorApi.PartDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition( xySketchProfile, PartFeatureOperationEnum.kJoinOperation); extrudeDef.SetDistanceExtent(stabilizerWidth, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); var extrude = _inventorApi.PartDefinition.Features.ExtrudeFeatures.Add(extrudeDef); ObjectCollection objectCollection = _inventorApi.CreateObjectCollection(); objectCollection.Add(extrude); var curc = _inventorApi.PartDefinition.Features.CircularPatternFeatures.Add( objectCollection, zAxis, true, firstStabilizerCount, "360 deg", true, PatternComputeTypeEnum.kAdjustToModelCompute); }
/// <summary> /// Отрисовка сопла (модернизирована с добавлением имитации двигателя) /// </summary> private void BuildNozzle(RocketBuildStyle style) { WorkAxis xAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis yAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis zAxis = _inventorApi.PartDefinition.WorkAxes[3]; var firstStageLenght = RocketParameters.GetParameter(ParameterType.FirstStageLength).Value; var firstStageDiameter = RocketParameters.GetParameter(ParameterType.FirstStageDiameter).Value; var rocketLenght = RocketParameters.GetParameter(ParameterType.RocketLength).Value; var nozzleDiameter = RocketParameters.GetParameter(ParameterType.NozzleDiameter).Value; double parameterPointNozzle1 = 0.25; double parameterPointNozzle2 = 0.30; double parameterPointNozzle3 = 0.1; double parameterPointNozzle4 = 0.5; var nozzlePoint1 = _inventorApi.TransientGeometry.CreatePoint2d(0, rocketLenght); var nozzlePoint2 = _inventorApi.TransientGeometry. CreatePoint2d(0, rocketLenght + (firstStageLenght * parameterPointNozzle1) * parameterPointNozzle2); var nozzlePoint3 = _inventorApi.TransientGeometry. CreatePoint2d(nozzleDiameter * 0.30, rocketLenght + (firstStageLenght * parameterPointNozzle1) * parameterPointNozzle3); var nozzlePoint4 = _inventorApi.TransientGeometry. CreatePoint2d(nozzleDiameter * 0.95, rocketLenght + firstStageLenght * parameterPointNozzle1); var nozzleBezierPoint = _inventorApi.TransientGeometry. CreatePoint2d(0.85 * nozzleDiameter, rocketLenght + (firstStageLenght * parameterPointNozzle1) * parameterPointNozzle4); var nozzlePoint5 = _inventorApi.TransientGeometry. CreatePoint2d(nozzleDiameter, rocketLenght + firstStageLenght * 0.25); var nozzlePoint6 = _inventorApi.TransientGeometry.CreatePoint2d(firstStageDiameter, rocketLenght); var xySketch = _inventorApi.MakeNewSketch(1, 0); var line1 = xySketch.SketchLines.AddByTwoPoints(nozzlePoint1, nozzlePoint2); var line2 = xySketch.SketchLines.AddByTwoPoints(line1.EndSketchPoint, nozzlePoint3); var line3 = xySketch.SketchArcs.AddByThreePoints(line2.EndSketchPoint, nozzleBezierPoint, nozzlePoint4); var line4 = xySketch.SketchLines.AddByTwoPoints(line3.EndSketchPoint, nozzlePoint5); var line5 = xySketch.SketchLines.AddByTwoPoints(line4.EndSketchPoint, nozzlePoint6); xySketch.SketchLines.AddByTwoPoints(line1.StartSketchPoint, line5.EndSketchPoint); var xySketchProfile = xySketch.Profiles.AddForSolid(); var revolve = _inventorApi.PartDefinition.Features.RevolveFeatures.AddFull(xySketchProfile, zAxis, PartFeatureOperationEnum.kJoinOperation); if (style == RocketBuildStyle.Color) { _inventorApi.SetColor(revolve.Faces, "Nickel"); } }
/// <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 double GetDistanceBtwPointandLine(Inventor.Point mouseupPoint, WorkAxis workaxis) { PartDocument partDoc; partDoc = (PartDocument)m_inventorApplication.ActiveDocument; PartComponentDefinition partComDef; partComDef = partDoc.ComponentDefinition; NameValueMap cont; cont = m_inventorApplication.TransientObjects.CreateNameValueMap(); Double oDistance; oDistance = m_inventorApplication.MeasureTools.GetMinimumDistance(mouseupPoint, workaxis, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference, cont); return(oDistance); }
/// <summary> /// Отрисовка верхнего конуса /// </summary> private void BuildCone(RocketBuildStyle style) { // Комментарий к методу один раз так как дальше все по аналогии одинаково =) //Задаем плоскости WorkAxis xAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis yAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis zAxis = _inventorApi.PartDefinition.WorkAxes[3]; //Задаем опорные точки double coneBezierParameter1 = 0.625; double coneBezierParameter2 = 0.325; var coneLenght = RocketParameters.GetParameter(ParameterType.ConeLength).Value; var coneDiameter = RocketParameters.GetParameter(ParameterType.SecondStageDiameter).Value; var conePoint1 = _inventorApi.TransientGeometry.CreatePoint2d(0, 0); var conePoint2 = _inventorApi.TransientGeometry.CreatePoint2d(0, coneLenght); var conePoint3 = _inventorApi.TransientGeometry.CreatePoint2d(coneDiameter, coneLenght); var coneBezierPoint = _inventorApi.TransientGeometry. CreatePoint2d(coneBezierParameter1 * coneDiameter, coneBezierParameter2 * coneLenght); //Создаем скетч var xySketch = _inventorApi.MakeNewSketch(1, 0); //Добавляем в него линии по точкам (внимательно! нужно указывать начало и конец линий) var line1 = xySketch.SketchLines.AddByTwoPoints(conePoint1, conePoint2); var line2 = xySketch.SketchLines.AddByTwoPoints(line1.EndSketchPoint, conePoint3); xySketch.SketchArcs.AddByThreePoints(line1.StartSketchPoint, coneBezierPoint, line2.EndSketchPoint); var xySketchProfile = xySketch.Profiles.AddForSolid(); //Вращаем на 360 градусов с выдавливанием вокруг оси Z var revolve = _inventorApi.PartDefinition.Features.RevolveFeatures.AddFull(xySketchProfile, zAxis, PartFeatureOperationEnum.kJoinOperation); //Выбор металла if (style == RocketBuildStyle.Color) { _inventorApi.SetColor(revolve.Faces, "Gold - Metal"); } }
/// <summary> /// Отрисовка промежуточной юбки между ступенями /// </summary> private void BuildBetweenStage(RocketBuildStyle style) { WorkAxis xAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis yAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis zAxis = _inventorApi.PartDefinition.WorkAxes[3]; var secondStageLenght = RocketParameters.GetParameter(ParameterType.SecondStageLength).Value; var secondStageDiameter = RocketParameters.GetParameter(ParameterType.SecondStageDiameter).Value; var coneLenght = RocketParameters.GetParameter(ParameterType.ConeLength).Value; var firstStageLenght = RocketParameters.GetParameter(ParameterType.FirstStageLength).Value; var firstStageDiameter = RocketParameters.GetParameter(ParameterType.FirstStageDiameter).Value; var rocketLength = RocketParameters.GetParameter(ParameterType.RocketLength).Value; var betweenStagePoint1 = _inventorApi.TransientGeometry. CreatePoint2d(0, coneLenght + secondStageLenght); var betweenStagePoint2 = _inventorApi.TransientGeometry. CreatePoint2d(0, rocketLength - firstStageLenght); var betweenStagePoint3 = _inventorApi.TransientGeometry. CreatePoint2d(firstStageDiameter, rocketLength - firstStageLenght); var betweenStagePoint4 = _inventorApi.TransientGeometry. CreatePoint2d(secondStageDiameter, coneLenght + secondStageLenght); var xySketch = _inventorApi.MakeNewSketch(1, 0); var line1 = xySketch.SketchLines.AddByTwoPoints(betweenStagePoint1, betweenStagePoint2); var line2 = xySketch.SketchLines.AddByTwoPoints(line1.EndSketchPoint, betweenStagePoint3); var line3 = xySketch.SketchLines.AddByTwoPoints(line2.EndSketchPoint, betweenStagePoint4); xySketch.SketchLines.AddByTwoPoints(line1.StartSketchPoint, line3.EndSketchPoint); var xySketchProfile = xySketch.Profiles.AddForSolid(); var revolve = _inventorApi.PartDefinition.Features.RevolveFeatures.AddFull(xySketchProfile, zAxis, PartFeatureOperationEnum.kJoinOperation); if (style == RocketBuildStyle.Color) { _inventorApi.SetColor(revolve.Faces, "Titanium"); } }
/// <summary> /// Отрисовка первой ступени методом вращения прямоугольника /// </summary> private void BuildFirstStage(RocketBuildStyle style) { WorkAxis xAxis = _inventorApi.PartDefinition.WorkAxes[1]; WorkAxis yAxis = _inventorApi.PartDefinition.WorkAxes[2]; WorkAxis zAxis = _inventorApi.PartDefinition.WorkAxes[3]; var firstStageLenght = RocketParameters.GetParameter(ParameterType.FirstStageLength).Value; var firstStageDiameter = RocketParameters.GetParameter(ParameterType.FirstStageDiameter).Value; var rocketLength = RocketParameters.GetParameter(ParameterType.RocketLength).Value; var firstStagePoint1 = _inventorApi.TransientGeometry.CreatePoint2d(0, rocketLength - firstStageLenght); var firstStagePoint2 = _inventorApi.TransientGeometry.CreatePoint2d(firstStageDiameter, rocketLength); var xySketch = _inventorApi.MakeNewSketch(1, 0); xySketch.SketchLines.AddAsTwoPointRectangle(firstStagePoint1, firstStagePoint2); var xySketchProfile = xySketch.Profiles.AddForSolid(); var revolve = _inventorApi.PartDefinition.Features.RevolveFeatures.AddFull(xySketchProfile, zAxis, PartFeatureOperationEnum.kJoinOperation); if (style == RocketBuildStyle.Color) { _inventorApi.SetColor(revolve.Faces, "Chrome - Polished"); } }
private double GetDistanceBetwLineAndFace(PartComponentDefinition partCompDef, WorkAxis workAxis, WorkPlane workPlane) { NameValueMap cont; cont = m_inventorApplication.TransientObjects.CreateNameValueMap(); Double oDistance; oDistance = m_inventorApplication.MeasureTools.GetMinimumDistance(workAxis, workPlane, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference, cont); return(oDistance); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static RectangularPatternFeature[] CopyRectangularPatternFeature(PartComponentDefinition partCompDef, RectangularPatternFeature AsmFeature, Matrix invTransfo, int elementIdx, ComponentOccurrence occurrence, out ReportData[] reports) { List <RectangularPatternFeature> newFeatures = new List <RectangularPatternFeature>(); ObjectCollection ParentFeatures = FeatureUtilities.CopyParentFeatures(partCompDef, AsmFeature.Parent.Document as Document, AsmFeature.ParentFeatures, invTransfo, occurrence, out reports); if (ParentFeatures.Count == 0) { return(null); } Sketch3D sketch3D = partCompDef.Sketches3D.Add(); List <RectangularPatternFeatureData> FeaturesDataList = new List <RectangularPatternFeatureData>(); //Only along X Axis if (AsmFeature.XDirectionEntity != null && AsmFeature.YDirectionEntity == null) { UnitVector xDirection = FeatureUtilities.GetDirection(AsmFeature.XDirectionEntity); xDirection.TransformBy(invTransfo); Point xDirStartPoint = null; WorkAxis xDirAxis = null; SketchPoint3D xDirStartPoint3D = null; try { xDirStartPoint = FeatureUtilities.GetPoint(AsmFeature.XDirectionStartPoint); xDirStartPoint.TransformBy(invTransfo); xDirAxis = partCompDef.WorkAxes.AddFixed(xDirStartPoint, xDirection, FeatureUtilities.ConstructionWorkAxis); xDirStartPoint3D = sketch3D.SketchPoints3D.Add(xDirStartPoint, false); } catch { xDirAxis = partCompDef.WorkAxes.AddFixed(partCompDef.WorkPoints[1].Point, xDirection, FeatureUtilities.ConstructionWorkAxis); } double count1 = (double)(AsmFeature.XCount.Value) - elementIdx + 1; //Check it's not the last pattern element if (count1 != 0 && elementIdx != (double)(AsmFeature.XCount.Value)) { RectangularPatternFeatureData featureData = newRectangularPatternFeatureData(); featureData.xCount = count1; featureData.xSpacing = AsmFeature.XSpacing.Value; featureData.naturalXDirection = AsmFeature.NaturalXDirection; featureData.xDirectionSpacingType = AsmFeature.XDirectionSpacingType; featureData.xDirAxis = xDirAxis; featureData.xDirStartPoint3D = xDirStartPoint3D; FeaturesDataList.Add(featureData); } double count2 = elementIdx; //Check it's not the first pattern element if (count2 != 0 && elementIdx != 1) { RectangularPatternFeatureData featureData = newRectangularPatternFeatureData(); featureData.xCount = count2; featureData.xSpacing = AsmFeature.XSpacing.Value; featureData.naturalXDirection = !AsmFeature.NaturalXDirection; featureData.xDirectionSpacingType = AsmFeature.XDirectionSpacingType; featureData.xDirAxis = xDirAxis; featureData.xDirStartPoint3D = xDirStartPoint3D; FeaturesDataList.Add(featureData); } } //Only along Y Axis if (AsmFeature.YDirectionEntity != null && AsmFeature.XDirectionEntity == null) { } //Only along both Axes if (AsmFeature.XDirectionEntity != null && AsmFeature.YDirectionEntity != null) { } foreach (RectangularPatternFeatureData featureData in FeaturesDataList) { RectangularPatternFeature newFeature = partCompDef.Features.RectangularPatternFeatures.Add(ParentFeatures, featureData.xDirAxis, featureData.naturalXDirection, featureData.xCount, featureData.xSpacing, featureData.xDirectionSpacingType, featureData.xDirStartPoint3D, featureData.yDirAxis, featureData.naturalYDirection, featureData.yCount, featureData.ySpacing, featureData.yDirectionSpacingType, featureData.yDirStartPoint3D, AsmFeature.ComputeType, AsmFeature.OrientationMethod); foreach (FeaturePatternElement element in newFeature.PatternElements) { if (newFeature.HealthStatus == HealthStatusEnum.kUpToDateHealth) { break; } if (element.Faces.Count == 0 && element.Index != 1) { element.Suppressed = true; } } if (newFeature != null) { newFeatures.Add(newFeature); } } return(newFeatures.ToArray()); }
/// <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); }
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; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static CircularPatternFeature[] CopyCircularPatternFeature(PartComponentDefinition partCompDef, CircularPatternFeature Feature, Matrix invTransfo, int elementIdx, ComponentOccurrence occurrence, out ReportData[] reports) { List <CircularPatternFeature> newFeatures = new List <CircularPatternFeature>(); ObjectCollection ParentFeatures = FeatureUtilities.CopyParentFeatures(partCompDef, Feature.Parent.Document as Document, Feature.ParentFeatures, invTransfo, occurrence, out reports); if (ParentFeatures.Count == 0) { return(null); } List <CircularPatternFeatureData> FeaturesDataList = new List <CircularPatternFeatureData>(); WorkAxis axis = FeatureUtilities.GetAxis(partCompDef, Feature.AxisEntity, invTransfo); double step = (double)Feature.Angle.Value / (double)Feature.Count.Value; double count1 = (double)Feature.Count.Value - elementIdx + 1; //Check it's not the last pattern element if (elementIdx != (double)(Feature.Count.Value)) { CircularPatternFeatureData featureData = new CircularPatternFeatureData(); featureData.axis = axis; featureData.naturalAxisDirection = Feature.NaturalAxisDirection; featureData.count = count1; featureData.angle = step * (count1 - 1); featureData.fitWithinAngle = Feature.FitWithinAngle; FeaturesDataList.Add(featureData); } double count2 = elementIdx; //Check it's not the first pattern element if (elementIdx != 1) { CircularPatternFeatureData featureData = new CircularPatternFeatureData(); featureData.axis = axis; featureData.naturalAxisDirection = !Feature.NaturalAxisDirection; featureData.count = count2; featureData.angle = step * (count2 - (elementIdx == (double)(Feature.Count.Value) ? 0 : 1)); featureData.fitWithinAngle = Feature.FitWithinAngle; FeaturesDataList.Add(featureData); } foreach (CircularPatternFeatureData featureData in FeaturesDataList) { CircularPatternFeature newFeature = partCompDef.Features.CircularPatternFeatures.Add(ParentFeatures, featureData.axis, featureData.naturalAxisDirection, featureData.count, featureData.angle, featureData.fitWithinAngle, Feature.ComputeType); if (newFeature != null) { newFeatures.Add(newFeature); } } return(newFeatures.ToArray()); }
///////////////////////////////////////////////////////////// // Use: Creates new solid bodies affected by the future // CoilFeature for Tapered Thread. ///////////////////////////////////////////////////////////// private static bool CreateCoilBodyTapered(PartDocument doc, ThreadInfo threadInfo, Face threadedFace, double depth, bool isInteriorFace) { try { PartComponentDefinition compDef = doc.ComponentDefinition; Vector direction = threadInfo.ThreadDirection; Point basePoint = threadInfo.ThreadBasePoints[1] as Point; Point endPoint = _Tg.CreatePoint( basePoint.X + direction.X, basePoint.Y + direction.Y, basePoint.Z + direction.Z); UnitVector yAxis = direction.AsUnitVector(); UnitVector xAxis = Toolkit.GetOrthoVector(yAxis); WorkPoint wpt = compDef.WorkPoints.AddFixed(basePoint, _ConstructionWorkFeature); WorkPlane wpl = compDef.WorkPlanes.AddFixed(basePoint, xAxis, yAxis, _ConstructionWorkFeature); WorkAxis xWa = compDef.WorkAxes.AddFixed(basePoint, xAxis, _ConstructionWorkFeature); WorkAxis yWa = compDef.WorkAxes.AddFixed(basePoint, yAxis, _ConstructionWorkFeature); PlanarSketch sketch = compDef.Sketches.AddWithOrientation(wpl, xWa, true, true, wpt, false); Cone cone = threadedFace.Geometry as Cone; double revDepth = depth / Math.Cos(cone.HalfAngle) * (isInteriorFace ? -1.0 : 1.0); Line l1 = Toolkit.GetFaceSideDirection(threadedFace, xAxis); Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector()); Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector()); Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point; Point p2 = l1.IntersectWithCurve(l3, 0.0001)[1] as Point; Point p3 = _Tg.CreatePoint( p2.X - xAxis.X * revDepth, p2.Y - xAxis.Y * revDepth, p2.Z - xAxis.Z * revDepth); Point p4 = _Tg.CreatePoint( p1.X - xAxis.X * revDepth, p1.Y - xAxis.Y * revDepth, p1.Z - xAxis.Z * revDepth); SketchPoint skp1 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p1), false); SketchPoint skp2 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p2), false); SketchPoint skp3 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p3), false); SketchPoint skp4 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p4), false); sketch.SketchLines.AddByTwoPoints(skp1, skp2); sketch.SketchLines.AddByTwoPoints(skp2, skp3); sketch.SketchLines.AddByTwoPoints(skp3, skp4); sketch.SketchLines.AddByTwoPoints(skp4, skp1); Profile profile = sketch.Profiles.AddForSolid(true, null, null); RevolveFeature rev1 = compDef.Features.RevolveFeatures.AddFull( profile, yWa, PartFeatureOperationEnum.kCutOperation); sketch = compDef.Sketches.AddWithOrientation(wpl, xWa, true, true, wpt, false); skp1 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p1), false); skp2 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p2), false); skp3 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p3), false); skp4 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p4), false); sketch.SketchLines.AddByTwoPoints(skp1, skp2); sketch.SketchLines.AddByTwoPoints(skp2, skp3); sketch.SketchLines.AddByTwoPoints(skp3, skp4); sketch.SketchLines.AddByTwoPoints(skp4, skp1); profile = sketch.Profiles.AddForSolid(true, null, null); RevolveFeature rev2 = compDef.Features.RevolveFeatures.AddFull( profile, yWa, PartFeatureOperationEnum.kNewBodyOperation); return(true); } catch { return(false); } }
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(); }