MACRO LIBRARY

Modify feature data of an extrusion

Free public access. No account or subscription required.

Files

Modify feature data of an extrusion

Code

'Doubles the depth of selected extrude feature.
'Preconditions: part is open and extrude feature is selected.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swExtrudeFeatureData As SldWorks.ExtrudeFeatureData2
    
Dim depth As Single
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    If Not swModel Is Nothing Then
        Set swSelMgr = swModel.SelectionManager
        Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
        If Not swFeat Is Nothing Then
            If swFeat.GetTypeName2 = "Extrusion" Then
                Set swExtrudeFeatureData = swFeat.GetDefinition
                depth = swExtrudeFeatureData.GetDepth(True)
                Debug.Print "Current depth = " & depth
                swExtrudeFeatureData.SetDepth True, depth * 2
                swFeat.ModifyDefinition swExtrudeFeatureData, swModel, Nothing
            Else
                swApp.SendMsgToUser "Please select an extrude feature."
            End If
        Else
            swApp.SendMsgToUser "Please select an extrude feature."
        End If
    Else
        swApp.SendMsgToUser "Open a part document."
    End If
End Sub