首页 > 解决方案 > 如何使用发明者 api 和 c# 或 vb.net 创建螺旋曲线

问题描述

我在 c# windows 应用程序中有代码在 2D 草图中创建一条线。然后我创建了一个 3D 草图。最终,我想从 3D 草图中围绕这条线添加一条螺旋曲线。谁能帮我解决这个问题?提前致谢。

  public void MyMethod(Inventor.Application ThisApplication)
        {
            PartDocument oSheetMetalDoc = (PartDocument)m_oInventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, m_oInventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kMetricSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"), true);

            // Set a reference to the component definition.

            SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oSheetMetalDoc.ComponentDefinition;

            // Set a reference to the sheet
            // metal features collection.

            SheetMetalFeatures oSheetMetalFeatures = (SheetMetalFeatures)oCompDef.Features;

            // Create a new sketch on the X-Y work plane.
            PlanarSketch oSketch = default(PlanarSketch);
            oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]);


            TransientGeometry oTransGeom = (TransientGeometry)ThisApplication.TransientGeometry;

            // Draw a 4cm x 3cm rectangle with the
            // corner at (0,0)


            SketchLine line = (SketchLine)oSketch.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(0, 0), oTransGeom.CreatePoint2d(0, 500)); // 2. ihtimal


            // skecth line turn to centerline 


            line.Centerline = true;

            ThisApplication.ActiveView.GoHome();
            // Create a 3D sketch.

            Sketch3D sketch3 = (Sketch3D)oCompDef.Sketches3D.Add();

             SketchEntity3D selectObj = m_oInventorApp.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Select 3d sketch entity");
            if (selectObj == null)
            {

            }
          // HelicalConstraint3D . want to add helical curve around the line above 
}

标签: helixautodesk-inventor

解决方案


这是 iLogic/VB.net 代码,用于根据选定的 SketchLine 创建螺旋曲线。零件文档必须处于活动状态,并且必须至少有一个 SketchLine 可见以供选择。

Sub Main()

    Dim oSketchLine As SketchLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter,
                                                                        "Select line")
    CreateHelicalCurve(oSketchLine)
End Sub

Private Sub CreateHelicalCurve(oSketchLine As SketchLine)

    Dim partDef As PartComponentDefinition = oSketchLine.Parent.Parent

    Dim sketch3D As Sketch3D = partDef.Sketches3D.Add()

    Dim axisStartPoint As Point = oSketchLine.StartSketchPoint.Geometry3d
    Dim axisEndPoint As Point = oSketchLine.EndSketchPoint.Geometry3d

    Dim curveStartPoint As Point = axisStartPoint.Copy()
    curveStartPoint.TranslateBy(ThisApplication.TransientGeometry.CreateVector(0, 0, 1))

    Dim diameter As Double = 5 ' [cm]
    Dim pitch As Double = 1 ' [cm]
    Dim revolution As Object = Nothing ' Optional argument
    Dim height As Double = 5 ' [cm]

    Dim helicalCurveDefinition As HelicalCurveConstantShapeDefinition = sketch3D.HelicalCurves.
            CreateConstantShapeDefinition(
                HelicalShapeDefinitionTypeEnum.kPitchAndHeightShapeType,
                axisStartPoint,
                axisEndPoint,
                curveStartPoint,
                diameter,
                pitch,
                revolution,
                height
                )


    sketch3D.HelicalCurves.Add(helicalCurveDefinition)
End Sub

推荐阅读