如何使用Inventor API和C#或vb.net创建螺旋曲线

时间:2019-08-23 22:10:39

标签: helix autodesk-inventor

我在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 
}

1 个答案:

答案 0 :(得分:0)

这是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