Insert Sheet Metal Gusset Feature Example (VBA)
This example shows how to insert a sheet metal gusset feature and modify its data.
'----------------------------------------------------------------------------
' Preconditions: Open:
' install_dir\samples\tutorial\api\SMGussetAPI.sldprt
'
' Postconditions:
' 1. Five gussets are inserted in the sheet metal.
' 2. Press F5 repeatedly and observe the gusset modifications.
'
' NOTE: Because the model is used elsewhere, do not save changes.
' ---------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim myFeature As SldWorks.Feature
Dim myFeature1 As SldWorks.Feature
Dim myFeature2 As SldWorks.Feature
Dim myFeature3 As SldWorks.Feature
Dim myFeature4 As SldWorks.Feature
Dim swFeat As SldWorks.Feature
Dim swFeatData As SldWorks.SMGussetFeatureData
Dim boolstatus As Boolean
Option Explicit
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("",
"FACE", -5.38403893476698E-02, 3.6701308754914E-03, 0.05530817474488, False, 0,
Nothing, 0)
boolstatus = Part.Extension.SelectByID2("",
"FACE", -1.77780871801474E-02, -3.07393226379986E-02, 3.41128529187245E-02,
True, 0, Nothing, 0)
' Gusset #1 insertion parameters
'1. bOffset
= True
'2. dOffset
= 50 mm
'3. bFlipOffsetSide
= False
'4. profDimType
= 0 (indent depth dimensioning scheme)
'5. dIndentDepth,
= 10 mm
'6. dLength
= 0
'7. bUseAngle,
= False
'8. dHeight
= 0
'9 dAngle
= 0
'10. bFlipSides
= False
'11. dWidth
= 10 mm
'12. dThickness
= 3 mm
'13. bDraft
= True
'14. dDraftAngle
= 3 degrees
'15. bInnerCornerFillet,
= True
'16. dInnerCornerFilletRadius = 2 mm
'17. bOuterCornerFillet
= True
'18. dOuterCornerFilletRadius = 1 mm
'19. gussetType
= 0 (rounded back)
'20 bEdgeFillet
= False
'21. dEdgeFilletRadius
= 0 mm
Set myFeature = Part.FeatureManager.InsertSheetMetalGussetFeature(True,
0.05, False, swSheetMetalGussetProfileDimType_IndentDepth, 0.01, 0, False, 0, 0, True, 0.01, 0.003, True, 3 * 0.0175, True,
0.002, True, 0.001, swSheetMetalRibGussetType_Rounded, False, 0)
Part.ClearSelection2 True
' Gusset #2 insertion parameters
'2. dOffset
= 30 mm
'19. gussetType
= 1 (flat back)
'20 bEdgeFillet
= True
'21. dEdgeFilletRadius = 1 mm
'Select faces
boolstatus = Part.Extension.SelectByID2("",
"FACE", -5.38403893476698E-02, 3.6701308754914E-03, 0.05530817474488, False, 0,
Nothing, 0)
boolstatus = Part.Extension.SelectByID2("",
"FACE", -1.77780871801474E-02, -3.07393226379986E-02, 3.41128529187245E-02,
True, 0, Nothing, 0)
Set myFeature1 = Part.FeatureManager.InsertSheetMetalGussetFeature(True,
0.03, False, swSheetMetalGussetProfileDimType_IndentDepth, 0.01, 0, False, 0, 0, False, 0.01, 0.003, True, 3 * 0.0175,
True, 0.002, True, 0.001, swSheetMetalRibGussetType_Flat, True, 0.001)
Part.ClearSelection2 True
' Gusset #3 insertion parameters
'2. dOffset
= 30 mm
'4. profDimType
= 1 (length + height dimensioning scheme)
'5. dIndentDepth,
= 0 mm
'6. dLength
= 25 mm
'7. bUseAngle,
= False
'8. dHeight
= 15 mm
'9 dAngle
= 0
'10. bFlipSides
= False
'19. gussetType
= 1 (flat back)
'20 bEdgeFillet
= True
'21. dEdgeFilletRadius = 1 mm
boolstatus = Part.Extension.SelectByID2("",
"FACE", -5.38403893476698E-02, 3.6701308754914E-03, 0.05530817474488, False, 0,
Nothing, 0)
boolstatus = Part.Extension.SelectByID2("",
"FACE", -1.77780871801474E-02, -3.07393226379986E-02, 3.41128529187245E-02,
True, 0, Nothing, 0)
Set myFeature2 = Part.FeatureManager.InsertSheetMetalGussetFeature(True,
0.03, False, swSheetMetalGussetProfileDimType_ProfileDimensions, 0, 0.025, False, 0.015, 0, False, 0.02, 0.003, True, 3 * 0.0175,
True, 0.002, True, 0.001, swSheetMetalRibGussetType_Flat, True, 0.001)
Part.ClearSelection2 True
' Gusset #4
'Select orientation and position references
boolstatus = Part.Extension.SelectByID2("",
"FACE", -5.38403893476129E-02, -2.24553153327633E-03, 0.087801420904043, True,
0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("",
"FACE", -2.35965800548001E-02, -3.07393226379986E-02, 8.97844682415894E-02,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line1@Sketch6",
"EXTSKETCHSEGMENT", -6.09049483400968E-03, -8.95139047397037E-02, 0, True, 0,
Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Point1@Sketch7",
"EXTSKETCHPOINT", 1.80407947995604E-02, -7.62728416981986E-02, 0, True, 0,
Nothing, 0)
Set myFeature3 = Part.FeatureManager.InsertSheetMetalGussetFeature(True,
0.03, False, swSheetMetalGussetProfileDimType_IndentDepth, 0.01, 0, False, 0, 0, False, 0.01, 0.003, True, 3 * 0.0175,
True, 0.002, True, 0.001, swSheetMetalRibGussetType_Rounded, True, 0.001)
Part.ClearSelection2 True
' Gusset #5
'Pass support, orientation, and position references in the
insertion method
Dim arrayOfFaces(0 To 1) As Object
boolstatus = Part.Extension.SelectByID2("",
"FACE", -5.38403893476129E-02, 2.15261807674665E-02, 0.127524627462805, True, 0,
Nothing, 0)
Set arrayOfFaces(0) = Part.SelectionManager.GetSelectedObject6(1,
-1)
boolstatus = Part.Extension.SelectByID2("",
"FACE", 1.29199133115776E-02, -3.07393226378281E-02, 6.73442494212964E-02, True,
0, Nothing, 0)
Set arrayOfFaces(1) = Part.SelectionManager.GetSelectedObject6(1,
-1)
Dim arrayOfRefLines(0) As Object
boolstatus = Part.Extension.SelectByID2("",
"EDGE", -5.38278103537095E-02, -1.23578076746185E-02, 0.214291961345026, True,
0, Nothing, 0)
Set arrayOfRefLines(0) = Part.SelectionManager.GetSelectedObject6(1,
-1)
Dim arrayRefPoints(0) As Object
boolstatus = Part.Extension.SelectByID2("",
"VERTEX", -5.38403893475499E-02, 1.16094138400761E-02, 0.200245910723487, True,
0, Nothing, 0)
Set arrayRefPoints(0) = Part.SelectionManager.GetSelectedObject6(1,
-1)
Set myFeature4 = Part.FeatureManager.InsertSheetMetalGussetFeature2(True,
0.15, False, swSheetMetalGussetProfileDimType_ProfileDimensions, 0, 0.025, True, 0, 60 * 0.0175, True, 0.02, 0.003, True, 3 *
0.0175, True, 0.002, True, 0.001, swSheetMetalRibGussetType_Flat, True, 0.001, arrayOfFaces, arrayOfRefLines,
arrayRefPoints)
Part.ClearSelection2 True
Stop
'Six examples of modifying gusset feature
data:
'a. Modify type,
draft, and outer corner fillet options for gusset #4
boolstatus = Part.Extension.SelectByID2("Sheet
Metal Gusset4", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = Part.SelectionManager.GetSelectedObject6(1,
-1)
Set swFeatData =
swFeat.GetDefinition
swFeatData.AccessSelections
Part, Nothing
swFeatData.GussetType
= 1 'flat back
swFeatData.DraftSideFaces =
False
swFeatData.FilletOuterCorners
= False 'no outer corner fillet
swFeat.ModifyDefinition
swFeatData, Part, Nothing
swFeatData.ReleaseSelectionAccess
Stop
'b. Modify type
and inner corner fillet options for gusset #5
boolstatus = Part.Extension.SelectByID2("Sheet
Metal Gusset5", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = Part.SelectionManager.GetSelectedObject6(1,
-1)
Set swFeatData =
swFeat.GetDefinition
swFeatData.AccessSelections
Part, Nothing
swFeatData.GussetType
= 0 'rounded back
swFeatData.FilletInnerCorners
= False 'no inner corner fillet
swFeat.ModifyDefinition
swFeatData, Part, Nothing
swFeatData.ReleaseSelectionAccess
Stop
'c. Modify legs of
gusset #5: select one bend face instead of two flat faces
boolstatus = Part.Extension.SelectByID2("Sheet
Metal Gusset5", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = Part.SelectionManager.GetSelectedObject6(1,
-1)
Set swFeatData =
swFeat.GetDefinition
swFeatData.AccessSelections
Part, Nothing
boolstatus = Part.Extension.SelectByID2("",
"FACE", -5.32822252084202E-02, -2.87774016125013E-02, 3.00897654936705E-02,
False, 0, Nothing, 0)
Dim faces(0 To 1) As Object
Dim ii As Integer
For ii = 0 To 1
Set faces(ii) =
Part.SelectionManager.GetSelectedObject6(ii + 1, -1)
Next ii
Dim facesVar As Variant
facesVar = faces
swFeatData.SupportingFaces =
facesVar
swFeat.ModifyDefinition
swFeatData, Part, Nothing
Stop
'd. Modify
orientation reference of gusset #3
boolstatus = Part.Extension.SelectByID2("Sheet
Metal Gusset3", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = Part.SelectionManager.GetSelectedObject6(1,
-1)
Set swFeatData =
swFeat.GetDefinition
swFeatData.AccessSelections
Part, Nothing
boolstatus = Part.Extension.SelectByID2("Line1@Sketch6",
"EXTSKETCHSEGMENT", -6.09049483400968E-03, -8.95139047397037E-02, 0, True, 0,
Nothing, 0)
Dim refLine As
Variant
Set refLine = Part.SelectionManager.GetSelectedObject6(1,
-1)
swFeatData.referenceline =
refLine
swFeat.ModifyDefinition
swFeatData, Part, Nothing
Stop
'e. Modify legs of
gusset #2: gusset moved to bend of edge flange
boolstatus = Part.Extension.SelectByID2("Sheet
Metal Gusset2", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = Part.SelectionManager.GetSelectedObject6(1,
-1)
Set swFeatData =
swFeat.GetDefinition
swFeatData.AccessSelections
Part, Nothing
boolstatus = Part.Extension.SelectByID2("",
"FACE", 0.03831148650454, -3.27672470662037E-02, 0.147978181958194, False, 0,
Nothing, 0)
Dim newBendFace As
Variant
Dim bendfaces(0 To 1) As Object
Dim jj As Integer
For jj = 0 To 1
Set bendfaces(jj) =
Part.SelectionManager.GetSelectedObject6(jj + 1, -1)
Next jj
newBendFace = bendfaces
swFeatData.SupportingFaces =
newBendFace
swFeat.ModifyDefinition
swFeatData, Part, Nothing
Stop
'f. Modify
reference position of gusset #3 - 3 mm away from vertex of hexagonal cut
boolstatus = Part.Extension.SelectByID2("Sheet
Metal Gusset3", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = Part.SelectionManager.GetSelectedObject6(1,
-1)
Set swFeatData =
swFeat.GetDefinition
swFeatData.AccessSelections
Part, Nothing
boolstatus = Part.Extension.SelectByID2("",
"VERTEX", -5.38403893475499E-02, -1.00654290631334E-02, 0.205954465964501,
False, 0, Nothing, 0)
Dim refPoint As
Variant
Set refPoint = Part.SelectionManager.GetSelectedObject6(1,
-1)
swFeatData.ReferencePoint =
refPoint
swFeat.ModifyDefinition
swFeatData, Part, Nothing
End Sub