Hide Table of Contents

Create Extruded Thin Feature Example (VBA)

This example shows how to create an extruded thin feature.

 

'---------------------------------------

'

' Preconditions: Model document with a sketch named Sketch2 is open.

'

' Postconditions: None

'

'---------------------------------------

Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()

    Dim swModel           As SldWorks.ModelDoc2

    Dim bValue            As Boolean

    Dim swFeature         As SldWorks.Feature

    Dim nStartCondition   As SwConst.swStartConditions_e

    Dim nEndcondition1    As SwConst.swEndConditions_e

    Dim nEndcondition2    As SwConst.swEndConditions_e

    Dim lCase             As Long

    Dim dStartOffset      As Double

    Dim bFlipOffset       As Boolean

    Dim dThickness        As Double

    Dim swExtrusionData   As SldWorks.ExtrudeFeatureData2

    Dim lThinFeatureType  As Long

    Dim lCapEnds          As Long

    

    

    

    ' Connect to SolidWorks

    Set swApp = Application.SldWorks

    ' Get active document

    Set swModel = swApp.ActiveDoc

    ' Set some parameters used for all cases

    nEndcondition1 = swEndCondBlind

    nEndcondition2 = swEndCondBlind

    dThickness = 0.01

    lThinFeatureType = 2 ' Mid-plane

    lCapEnds = 0

    

    For lCase = 1 To 7

    

        swModel.ClearSelection2 True

        

        bValue = swModel.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

            

        Select Case lCase

            Case 1

                nStartCondition = swStartSketchPlane

                dStartOffset = 0#

                bFlipOffset = False

                        

            Case 2    

                nStartCondition = swStartOffset

                dStartOffset = 0#

                bFlipOffset = False

       

            Case 3

                nStartCondition = swStartOffset

                dStartOffset = 0#

                bFlipOffset = True

        

            Case 4

                nStartCondition = swStartOffset

                dStartOffset = 0.01

                bFlipOffset = False

        

            Case 5

                nStartCondition = swStartOffset

                dStartOffset = 0.01

                bFlipOffset = True

        

            Case 6            

                nStartCondition = swStartSurface

                dStartOffset = 0#

                bFlipOffset = True

                dThickness = 0.005

                

                bValue = swModel.Extension.SelectByID2("", "FACE", -0.0227247722911, 0.01533611968841, 0, True, 0, Nothing, 0)

        

            Case 7            

                nStartCondition = swStartVertex

                dStartOffset = 0#

                bFlipOffset = True

                dThickness = 0.005

                

                bValue = swModel.Extension.SelectByID2("", "VERTEX", -0.05999251028807, 0.05489880658436, 0, True, 0, Nothing, 0)

                

        End Select

        

        Set swFeature = swModel.FeatureManager.FeatureExtrusionThin2(True, False, False, nEndcondition1, nEndcondition2, 0.03, 0.03, False, False, False, False, 0#, 0#, False, False, False, False, False, dThickness, 0#, 0#, lThinFeatureType, lCapEnds, False, 0.005, True, True, nStartCondition, dStartOffset, bFlipOffset)

        

        

        Debug.Print swFeature.Name & " [" & swFeature.GetTypeName & "]"

        

        Set swExtrusionData = swFeature.GetDefinition

        

        bValue = swExtrusionData.AccessSelections(swModel, Nothing)

        

        If (swExtrusionData.IsThinFeature = False) Then

            Debug.Print "ERROR: Must be a thin feature."

        End If

        

        Select Case swExtrusionData.FromType

        

            Case SwConst.swExtrudeFrom_e.swExtrudeFrom_SketchPlane

            

                Debug.Print "  from: sketchplane"

                

            Case SwConst.swExtrudeFrom_e.swExtrudeFrom_Offset

            

                Debug.Print "  from: offset"

                

                Debug.Print "    distance = " & swExtrusionData.FromOffsetDistance

                Debug.Print "    reverse  = " & swExtrusionData.FromOffsetReverse

                

            Case SwConst.swExtrudeFrom_e.swExtrudeFrom_SurfaceFacePlane

            

                Debug.Print "  from: surface"

                

            Case SwConst.swExtrudeFrom_e.swExtrudeFrom_Vertex

            

                Debug.Print "  from: vertex"

        End Select

        

        swExtrusionData.ReleaseSelectionAccess

        

        ' Examine the feature

        Stop

        

        ' Now delete the feature:

        ' The sketch remains, so that you can select it again.

        bValue = swFeature.Select2(True, 0)

        

        bValue = swModel.Extension.DeleteSelection2(swDelete_Children)

               

    Next lCase

        

End Sub



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:   Create Extruded Thin Feature Example (VBA)
*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) 2012 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.