Files
Accessing and releasing feature data
Code
Module: mMain
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
'Preconditions: part is open, should have fillets if you want anything to happen
'Results: For fillets that have radii < 10 mm then make them 10 mm and select
' that fillet.
'Notes:
'-For single-radius fillets, the feature definition need only be modified.
'-For multi-radius fillets, access to the selections is required to determine which
' selections are actually
'-For ISimpleFilletFeatureData2::FilletItemsCount, -1 is returned is the simple fillet
' is not multi-radius
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.PartDoc
Dim swFeat As SldWorks.Feature
Dim swFilletData As SldWorks.SimpleFilletFeatureData2
Dim objFilletItem As Object 'GetFilletItemAtIndex can return edge, face, or loop
Dim i As Integer
Dim radius As Double
Dim blnSelFeat As Boolean
Const MinRadius As Single = 0.01
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
While Not swFeat Is Nothing
If swFeat.GetTypeName2 = "Fillet" Then
Set swFilletData = swFeat.GetDefinition
radius = swFilletData.DefaultRadius
'single-radius fillet
If radius < MinRadius Then
swFilletData.DefaultRadius = MinRadius
swFeat.ModifyDefinition swFilletData, swModel, Nothing
swFeat.Select2 True, 0
End If
'multi-radius fillets
If swFilletData.FilletItemsCount > 0 Then
swFilletData.AccessSelections swModel, Nothing
For i = 0 To swFilletData.FilletItemsCount - 1
Set objFilletItem = swFilletData.GetFilletItemAtIndex(i)
radius = swFilletData.GetRadius(objFilletItem)
If radius < MinRadius Then
blnSelFeat = True
swFilletData.SetRadius objFilletItem, MinRadius
End If
Next i
swFeat.ModifyDefinition swFilletData, swModel, Nothing
swFilletData.ReleaseSelectionAccess
'the selection must occur after the modifications are made, because _
previously the part was in the rollback state
If blnSelFeat = True Then
blnSelFeat = False
swFeat.Select2 True, 0
End If
End If
End If
Set swFeat = swFeat.GetNextFeature
Wend
End Sub