Insert Sweep Cut Feature Example (VBA)
This example shows how to create a sweep cut feature and get its properties.
'-----------------------------------------------------------------------------
' Preconditions:
' 1. Ensure that the specified document
exists.
' 2. Open an Immediate Window.
'
' Postconditions:
' 1. Cut-Sweep1 is in the FeatureManager design tree.
' 2. Inspect the Immediate Window for sweep feature data.
'
' NOTE: Because this part document is used by other macros,
' do not save any changes when closing the
document.
'------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swSweep
As SldWorks.SweepFeatureData
Dim swProfFeat
As SldWorks.Feature
Dim swProfSketch
As SldWorks.Sketch
Dim swPathFeat
As SldWorks.Feature
Dim swPathSketch
As SldWorks.Sketch
Dim bRet
As Boolean
Public Enum swTangencyType_e
swTangencyNone = 0
swTangencyNormalToProfile = 1
swTangencyDirectionVector = 2
swTangencyAllFaces = 3
End Enum
Public Enum swThinWallType_e
swThinWallOneDirection = 0
swThinWallOppDirection = 1
swThinWallMidPlane = 2
swThinWallTwoDirection = 3
End Enum
Public Enum swTwistControlType_e
swTwistControlFollowPath = 0
swTwistControlKeepNormalConstant = 1
swTwistControlFollowPathFirstGuideCurve = 2
swTwistControlFollowFirstSecondGuideCurves = 3
End Enum
Public Enum swCutSweepOption_e
swProfileSweep = 1
swSolidSweep = 2
End Enum
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.OpenDoc6("C:\program files\SOLIDWORKS
Corp\SOLIDWORKS\samples\tutorial\api\sweepcutextrude.SLDPRT", 1, 0, "",
longstatus, longwarnings)
swApp.ActivateDoc2 "sweepcutextrude.SLDPRT", False, longstatus
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
myModelView.FrameState = swWindowState_e.swWindowMaximized
Part.ShowNamedView2 "*Isometric", 7
boolstatus = Part.Extension.SelectByID2("Sketch2", "SKETCH",
0.01948983274156, -0.02564816935317, 0, False, 1, Nothing, 0) ' profile has Mark
= 1
boolstatus = Part.Extension.SelectByID2("Sketch3", "SKETCH", -0.03797488317814,
-0.02133214444164, 0, True, 4, Nothing, 0) ' path sweep has Mark = 4
Dim myFeature As SldWorks.Feature
Set myFeature = Part.FeatureManager.InsertCutSwept4(False, True, 0,
False, False, 0, 0, False, 0, 0, 0, 0, True, True, 0, True, True, True, False)
Set swSweep = myFeature.GetDefinition
Set swProfFeat = swSweep.Profile: Debug.Assert Not Nothing Is swProfFeat
Set swProfSketch = swProfFeat.GetSpecificFeature: Debug.Assert Not Nothing Is
swProfSketch
' Rollback to access selections
bRet = swSweep.AccessSelections(Part, Nothing): Debug.Assert bRet
Set swPathFeat = swSweep.Path: Debug.Assert Not
Nothing Is swPathFeat
Set swPathSketch = swPathFeat.GetSpecificFeature: Debug.Assert Not Nothing Is
swPathSketch
Debug.Print "File = " & Part.GetPathName
Debug.Print " " & myFeature.Name
Debug.Print " Path
= " & swPathFeat.Name
Debug.Print " Path alignment type
= " & swSweep.PathAlignmentType 'swTangencyType_e
Debug.Print " Profile
= " & swProfFeat.Name
Debug.Print " AdvancedSmoothing
= " & swSweep.AdvancedSmoothing
Debug.Print " AlignWithEndFaces
= " & swSweep.AlignWithEndFaces
Debug.Print " AutoSelect
= " & swSweep.AutoSelect
Debug.Print " AutoSelectComponents
= " & swSweep.AutoSelectComponents
Debug.Print " EndTangencyType
= " & swSweep.EndTangencyType 'swTangencyType_e
Debug.Print " AssemblyFeatureScope
= " & swSweep.AssemblyFeatureScope
Debug.Print " FeatureScope
= " & swSweep.FeatureScope
Debug.Print " FeatureScopeBodiesCnt =
" & swSweep.GetFeatureScopeBodiesCount
Debug.Print " GetPathType
= " & swSweep.GetPathType 'swSelectType_e
Debug.Print " Wall thickness foward =
" & swSweep.GetWallThickness(True) * 1000# & " mm"
Debug.Print " Wall thickness reverse = " &
swSweep.GetWallThickness(False) * 1000# & " mm"
Debug.Print " IsBossFeature
= " & swSweep.IsBossFeature
Debug.Print " IsThinFeature
= " & swSweep.IsThinFeature
Debug.Print " MaintainTangency
= " & swSweep.MaintainTangency
Debug.Print " Merge
= " & swSweep.Merge
Debug.Print " MergeSmoothFaces
= " & swSweep.MergeSmoothFaces
Debug.Print " PropagateFeatureToParts = " &
swSweep.PropagateFeatureToParts
Debug.Print " StartTangencyType
= " & swSweep.StartTangencyType 'swTangencyType_e
Debug.Print " TangentPropagation
= " & swSweep.TangentPropagation
Debug.Print " ThinWallType
= " & swSweep.ThinWallType
Debug.Print " TwistControlType
= " & swSweep.TwistControlType 'swTwistControlType_e
Debug.Print " CutSweepOption
= " & swSweep.GetCutSweepOption 'swCutSweepOption_e
' Roll forward
swSweep.ReleaseSelectionAccess
End Sub