Hide Table of Contents

Create and Modify Variable-pitch Helix Example (VB.NET)

This example shows how to create and modify a variable-pitch helix.

' Preconditions:
' 1. Specified part template exits.
' 2. Open the Immediate window.
' Postconditions:
' 1. Opens a new part document.
' 2. Selects Front Plane, creates a circle, and
'    and uses the circle to create a variable-pitch
'    helix feature named Helix/Spiral1.
' 3. Gets whether the Helix/Spiral1 feature is a
'    variable-pitch helix. If so:
'    a. Prints to the Immediate window the number
'       of regions.
'    b. Prints to the Immediate window
'       each region's diameter, pitch, height,
'       and revolution.
'    c. If region 2 of the variable-pitch helix
'       is defined by height and revolution:
'       1. Modifies region's diameter, height, and
'          revolution values.
'       2. Prints to the Immediate window the status
'          of modifications made in previous step.
'    d. Deletes the last region in the Helix/Spiral1 feature and
'       prints the status of the deletion to the Immediate window.
'    e. Adds a new last region to the Helix/Spiral1 feature and
'       prints the status of the addition to the Immediate window.
'    - or -
'    Prints to the Immediate window that the Helix/Spiral1
'    feature is not a variable-pitch helix.
' 4. Examine the Immediate window.
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
    Public Sub Main()
        Dim swPart As PartDoc
        Dim swModel As ModelDoc2
        Dim swModelDocExt As ModelDocExtension
        Dim swSketchMgr As SketchManager
        Dim swFeatureMgr As FeatureManager
        Dim swFeat As Feature
        Dim swHelixFeatData As HelixFeatureData
        Dim status As Boolean
        Dim i As Integer
        Dim helixType As Integer
        Dim helixStatus As Integer
        Dim helixRegionArray(0) As Integer
        swPart = swApp.NewDocument("C:\ProgramData\SolidWorks\SolidWorks 2015\templates\Part.prtdot", 0, 0, 0)
        swModel = swPart
        swModelDocExt = swModel.Extension
        'Select plane on which to create circle
        'for variable-pitch helix
        status = swModelDocExt.SelectByID2("Front Plane""PLANE", -0.0571253507530972, 0.0536428819342089, 0.00349118658744337, False, 0, Nothing, 0)
        swSketchMgr = swModel.SketchManager
        'Create circle for variable-pitch helix
        swSketchMgr.CreateCircle(0.007581, 0.053509, 0.0#, 0.013533, 0.016475, 0.0#)
        ' Create a variable-pitch helix using the just-sketched circle
        swFeatureMgr = swModel.FeatureManager
        status = swFeatureMgr.InsertVariablePitchHelix(FalseTrue, swHelixDefinedBy_e.swHelixDefinedByHeightAndRevolution, 4.712388980385)
        status = swFeatureMgr.AddVariablePitchHelixFirstPitchAndDiameter(0.053, 0.05382625271268)
        status = swFeatureMgr.AddVariablePitchHelixSegment(0.0265, 0.05382625271268, 0.5)
        status = swFeatureMgr.AddVariablePitchHelixSegment(0.03975, 0.05382625271268, 0.75)
        status = swFeatureMgr.AddVariablePitchHelixSegment(0.046375, 0.05382625271268, 0.875)
        status = swFeatureMgr.AddVariablePitchHelixSegment(0.053, 0.05382625271268, 1)
        swFeat = swFeatureMgr.EndVariablePitchHelix()
        'Get variable-pitch helix
        swHelixFeatData = swFeat.GetDefinition
        If swHelixFeatData.VariablePitch Then
            Debug.Print("  Number of regions: " & swHelixFeatData.PitchCount)
            For i = 1 To swHelixFeatData.PitchCount
                Debug.Print("   Region " & i & ":")
                Debug.Print("      Diameter: " & swHelixFeatData.GetRegionParameterAtIndex(i, swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Diameter))
                Debug.Print("      Pitch: " & swHelixFeatData.GetRegionParameterAtIndex(i, swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Pitch))
                Debug.Print("      Height: " & swHelixFeatData.GetRegionParameterAtIndex(i, swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Height))
                Debug.Print("      Revolutions: " & swHelixFeatData.GetRegionParameterAtIndex(i, swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Revolution))
            Next i
            'Modify Region 2 of variable-pitch helix
            'defined by height and revolution
            helixType = swHelixFeatData.DefinedBy
            Select Case helixType
                Case swHelixDefinedBy_e.swHelixDefinedByHeightAndRevolution
                    If i >= 2 Then
                        'Cannot change pitch
                        'Can change diameter, height, and revolution
                        'Revolution must be smaller than previous region's
                        'revolution and less than next region's revolution
                        Debug.Print("Helix defined by height and revolution:")
                        Debug.Print("   Region modified: 2")
                        helixStatus = swHelixFeatData.SetRegionParameterAtIndex(2, swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Diameter, 0.052)
                        Debug.Print("      Diameter modified (0 = success): " & helixStatus)
                        helixStatus = swHelixFeatData.SetRegionParameterAtIndex(2, swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Height, 0.025)
                        Debug.Print("      Height modified (0 = success): " & helixStatus)
                        helixStatus = swHelixFeatData.SetRegionParameterAtIndex(2, swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Revolution, 0.45)
                        Debug.Print("      Revolution modified (0 = success): " & helixStatus)
                        Debug.Print("Less than three regions in Helix/Spiral1 feature.)")
                    End If
                Case swHelixDefinedBy_e.swHelixDefinedByHeightAndPitch
                    'Cannot change revolution
                    'TODO: Add code for variable-pitch helix defined by height and pitch
                Case swHelixDefinedBy_e.swHelixDefinedByPitchAndRevolution
                    'Cannot change height
                    'TODO: Add code for variable-pitch helix defined by pitch and revolution            
            End Select
            'Delete last region in the Helix/Spiral1 feature
            helixRegionArray(0) = (i - 1)
            status = swHelixFeatData.DeleteRecord(helixRegionArray)
            Debug.Print("Last region in Helix/Spiral1 deleted; i.e., region " & i - 1 & " was deleted: " & status)
            'Add new region to end of Region parameters table
            Dim record(3) As Double
            record(0) = 0.055
            'Number of revolutions
            record(1) = 1
            '0 indicates that this value cannot be specified
            'for this type of variable-pitch helix (Height and Revolution)
            'Instead, SOLIDWORKS calculates it
            record(2) = 0
            record(3) = 0.05382625271268
            status = swHelixFeatData.AddLastRecord(record)
            Debug.Print("New region 5 added as last record to Helix/Spiral1: " & status)
            status = swFeat.ModifyDefinition(swHelixFeatData, swModel, Nothing)
            Debug.Print("Helix is not variable pitch.")
        End If
    End Sub
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
End Class

Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Create and Modify Variable-pitch Helix Example (VB.NET)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.