Hide Table of Contents

Insert Hole Wizard Slot and Hole Example (VB.NET)

This example shows how to use IFeatureManager::HoleWizard5 to insert a straight slot and a counterbore hole in a part.

'-----------------------------------------------
' Preconditions: 
' 1. Specified part document to open exists.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Opens the specified part document.
' 2. Creates a straight slot and a counterbore hole.
' 3. Prints the length of the slot to the Immediate
'    window.
' 4. To verify steps 2 and 3, examine the part in the
'    graphics area, the FeatureManager design tree, 
'    and the Immediate window.
'
NOTE: Because the part document is used elsewhere,
' do not save any changes when closing it.
'------------------------------------------------
 
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Public Sub main()
 
        Dim swModel As ModelDoc2
        Dim swFeatureMgr As FeatureManager
        Dim swFeature As Feature
        Dim swModelDocExt As ModelDocExtension
        Dim fileName As String
        Dim errors As Integer
        Dim warnings As Integer
        Dim status As Boolean
        Dim SlotType As Integer
        Dim HoleType As Integer
        Dim StandardIndex As Integer
        Dim FastenerTypeIndex As Integer
        Dim SSize As String
        Dim EndType As Integer
        Dim ConvFactorLength As Double
        Dim ConvFactorAngle As Double
        Dim Diameter As Double
        Dim Depth As Double
        Dim Length As Double
        Dim ScrewFit As Double
        Dim DrillAngle As Double
        Dim NearCsinkDiameter As Double
        Dim NearCsinkAngle As Double
        Dim FarCsinkDiameter As Double
        Dim FarCsinkAngle As Double
        Dim Offset As Double
        Dim ThreadClass As String
        Dim CounterBoreDiameter As Double
        Dim CounterBoreDepth As Double
        Dim HeadClearance As Double
        Dim BotCsinkDiameter As Double
        Dim BotCsinkAngle As Double
        Dim swWizardHoleFeatData As WizardHoleFeatureData2
 
        fileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\block20.sldprt"
        swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swFeatureMgr = swModel.FeatureManager
        swModelDocExt = swModel.Extension
 
        'Use IFeatureManager::HoleWizard5
        'to create a slot 
 
        'Select the face where to create the slot
        status = swModelDocExt.SelectByID2("""FACE", -0.000609805077203873, 0.0396239999998897, -0.00830387834611201, False, 0, Nothing, 0)
 
        SlotType = swWzdGeneralHoleTypes_e.swWzdHoleSlot
        StandardIndex = swWzdHoleStandards_e.swStandardAnsiInch
        FastenerTypeIndex = swWzdHoleStandardFastenerTypes_e.swStandardAnsiInchAllDrillSizes
        SSize = "#97"
        EndType = swEndConditions_e.swEndCondBlind
        ConvFactorLength = 25.4 / 1000     'Convert inches to meters
        ConvFactorAngle = (22 / 7) / 180   'Convert degrees to radians
        Diameter = 0.5 * ConvFactorLength
        Depth = 2 * ConvFactorLength
        Length = 3 * ConvFactorLength
 
        'Value1 to Value7 arguments; SolidWorks
        'ignores parameters set to -1
        ScrewFit = -1                       'Value1
        DrillAngle = 100 * ConvFactorAngle  'Value2
        NearCsinkDiameter = -1              'Value3
        NearCsinkAngle = -1                 'Value4
        FarCsinkDiameter = -1               'Value5
        FarCsinkAngle = -1                  'Value6
        Offset = -1                         'Value7
 
        ThreadClass = ""
 
        swFeature = swFeatureMgr.HoleWizard5(SlotType, StandardIndex, FastenerTypeIndex, SSize, EndType, _
           Diameter, Depth, Length, ScrewFit, DrillAngle, NearCsinkDiameter, NearCsinkAngle, _
           FarCsinkDiameter, FarCsinkAngle, Offset, -1, -1, -1, -1, -1, ThreadClass, _
           FalseFalseFalseFalseFalseFalse)

        'Print length of slot to Immediate window
        swWizardHoleFeatData = swFeature.GetDefinition
        Debug.Print("Length of slot: " & swWizardHoleFeatData.Length & " inches")
 
        'Use IFeatureManager::HoleWizard5
        'to create a counterbore hole   
 
        'Select the face where to create the hole
        status = swModelDocExt.SelectByID2("""FACE", -0.0060197480091233, 0.0396239999998329, 0.0270812377555103, False, 0, Nothing, 0)
 
        HoleType = swWzdGeneralHoleTypes_e.swWzdCounterBore
        StandardIndex = swWzdHoleStandards_e.swStandardAnsiInch
        FastenerTypeIndex = swWzdHoleStandardFastenerTypes_e.swStandardAnsiInchBinding
        SSize = "#12"
        EndType = swEndConditions_e.swEndCondThroughAll
        ConvFactorLength = 25.4 / 1000      'Convert inches to meters
        ConvFactorAngle = (22 / 7) / 180    'Convert degrees to radians
        Diameter = 0.5 * ConvFactorLength
        Depth = -1
        Length = -1
 
        'Value1 to Value12 arguments; SolidWorks
        'ignores parameters set to -1      
        CounterBoreDiameter = 0.6 * ConvFactorLength    'Value1
        CounterBoreDepth = 0.2 * ConvFactorLength       'Value2
        HeadClearance = -1                              'Value3
        ScrewFit = -1                                   'Value4
        DrillAngle = -1                                 'Value5
        NearCsinkDiameter = -1                          'Value6
        NearCsinkAngle = -1                             'Value7
        BotCsinkDiameter = -1                           'Value8
        BotCsinkAngle = -1                              'Value9
        FarCsinkDiameter = -1                           'Value10
        FarCsinkAngle = -1                              'Value11
        Offset = -1                                     'Value12
 
        ThreadClass = ""
 
        swFeature = swFeatureMgr.HoleWizard5(HoleType, StandardIndex, FastenerTypeIndex, SSize, EndType, _
            Diameter, Depth, Length, CounterBoreDiameter, CounterBoreDepth, HeadClearance, ScrewFit, DrillAngle, _
            NearCsinkDiameter, NearCsinkAngle, BotCsinkDiameter, BotCsinkAngle, FarCsinkDiameter, FarCsinkAngle, Offset, _
            ThreadClass, FalseFalseFalseFalseFalseFalse)
 
    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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Insert Hole Wizard Slot and Hole Example (VB.NET)
*Comment:  
*   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:

x

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
x

Web Help Content Version: API Help (English only) 2014 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.