Create Base-Flange Feature Using Gauge Table Example (VBA)
This examples shows how to create a base-flange feature using a gauge
table.
'------------------------------------------------
'
' Preconditions: Part document containing a
' Sketch1
feature is open.
'
' Postconditions: Base-Flange feature created.
'
'-------------------------------------------------
Option Explicit
Sub main()
Dim
swApp As SldWorks.SldWorks
Dim
swModel As SldWorks.ModelDoc2
Dim
swFeatMgr As SldWorks.FeatureManager
Dim
swModelDocExt As SldWorks.ModelDocExtension
Dim
SelMgr As SldWorks.SelectionMgr
Dim
pFeatDef As SldWorks.BaseFlangeFeatureData
Dim
boolstatus As Boolean
Dim
pFeat As Object
Dim
i As Long
Dim
j As Long
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swFeatMgr = swModel.FeatureManager
Set
swModelDocExt = swModel.Extension
Set
SelMgr = swModel.SelectionManager
swModel.ClearSelection2 True
Set
pFeatDef = swFeatMgr.CreateDefinition(swFmBaseFlange)
pFeatDef.BendRadius = 0.02
pFeatDef.D1OffsetDistance = 0.04
pFeatDef.D1OffsetType = 1
pFeatDef.D1ReverseOffset = True
pFeatDef.D2OffsetDistance = 0.001
pFeatDef.D2OffsetType = 1
pFeatDef.D2ReverseOffset = True
pFeatDef.OffsetDirections = 1
pFeatDef.ReverseDirection = False
pFeatDef.ReverseThickness = False
'
All of the following values depend on the previous values;
'
you must set these values in sequence
pFeatDef.UseGaugeTable = True
'
Set the path to where the sheet metal gauge tables are stored on disk
pFeatDef.GaugeTablePath = "c:\Program Files\SolidWorks\SolidWorks\lang\english\Sheet
Metal Gauge Tables\sample table - steel - english units.xls"
Dim
ThicknessNames As Variant
Dim
Radii As Variant
ThicknessNames
= pFeatDef.GetTableThicknesses()
If
(IsEmpty(ThicknessNames)) Then
MsgBox
"Invalid gauge table path."
End
End
If
Debug.Print
" Table Thickness Names"
For
i = 0 To UBound(ThicknessNames)
Debug.Print
ThicknessNames(i)
Radii
= pFeatDef.GetTableRadii(ThicknessNames(i))
For
j = 0 To UBound(Radii)
Debug.Print
Radii(j)
Next
Next
i
'
Use the values from the previous API to set the following values
pFeatDef.ThicknessTableName = ThicknessNames(3)
Debug.Print
" Thickness Value" & ThicknessNames(0) & " = "
& pFeatDef.TableThickness
'
Get updated radii for new table, which was set previously
Radii
= pFeatDef.GetTableRadii(ThicknessNames(3))
pFeatDef.TableRadius = Radii(3)
Dim
Override As Boolean
Stop
'
Set value to what user wants
Override
= False
If
(Override = True) Then
pFeatDef.OverrideRadius = True
pFeatDef.OverrideThickness = True
pFeatDef.OverrideKFactor = True
Else
pFeatDef.OverrideRadius = False
pFeatDef.OverrideThickness = False
pFeatDef.OverrideKFactor = False
End
If
'
If above Override value is true, then use following API to set Override
value
If
(Override = True) Then
pFeatDef.Thickness = "0.06"
pFeatDef.BendRadius = 0.012
pFeatDef.KFactor = 0.75
End
If
swModel.ShowNamedView2 "*Trimetric",
8
boolstatus
= swModelDocExt.SelectByID2("Sketch1",
"SKETCH", 0, 0, 0, False, 0, Nothing, 0)
'
Create the feature
Set
pFeat = swFeatMgr.CreateFeature(pFeatDef)
End Sub