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