0

I have code in c# windows app creating a line in a 2D sketch. And then I created a 3D sketch. Eventually I want to add a helical curve around this line from the 3D sketch. Can anyone help me please to solve this issue? Thanks in advance.

  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 
}
Avery
  • 37
  • 1
  • 8

1 Answers1

0

This is iLogic/VB.net code for creating helix curve based on selected SketchLine. Part document must be active, and at least one SketchLine must be visible for selection.

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
Michael Navara
  • 1,111
  • 2
  • 8
  • 13