In Solidworks API help file
Feature Types -- Specify values for feature types.
Miscellaneous Features→swTnProfileFeature _T "ProfileFeature"
Body Features→swTnExtrusion _T "Extrusion"
e.g.
D1@草图1@零件1.Part | 40 | ProfileFeature |
D1@拉伸1@零件1.Part | 10 | Extrusion |
D1@草图1@零件1.Part | 40 | Extrusion |
D1@草图1@零件1.Part | 40 | ProfileFeature |
API Code
'Iterate Through Dimensions in Model Example (VB)
'This example shows how to iterate through the dimensions in a model. It assumed that you have an active model document.
'--------------------------------------------------
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim SwDispDim As SldWorks.DisplayDimension
Dim SwDim As SldWorks.Dimension
Dim swAnn As SldWorks.Annotation
Dim bRet As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
Debug.Print "File = " & swModel.GetPathName
Do While Not swFeat Is Nothing
Debug.Print " " + swFeat.Name, swFeat.GetTypeName
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing
Debug.Print " " + swSubFeat.Name, swFeat.GetTypeName
Set SwDispDim = swSubFeat.GetFirstDisplayDimension
Do While Not SwDispDim Is Nothing
Set swAnn = SwDispDim.GetAnnotation
Set SwDim = SwDispDim.GetDimension
Debug.Print " [" & SwDim.FullName & "] = " & SwDim.GetSystemValue2("")
Set SwDispDim = swSubFeat.GetNextDisplayDimension(SwDispDim)
Loop
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
Set SwDispDim = swFeat.GetFirstDisplayDimension
Do While Not SwDispDim Is Nothing
Set swAnn = SwDispDim.GetAnnotation
Set SwDim = SwDispDim.GetDimension
Debug.Print " [" & SwDim.FullName & "] = " & SwDim.GetSystemValue2("")
Set SwDispDim = swFeat.GetNextDisplayDimension(SwDispDim)
Loop
Set swFeat = swFeat.GetNextFeature
Loop
End Sub
'--------------------------------------------------
''
'Traverse Subfeatures Example (VB)
'This example shows how to traverse the subfeatures of each feature in a part (assumed to be set elsewhere).
'------------------------------------------------------------------
Sub oFeat()
Dim swApp As SldWorks.SldWorks, SwPart As ModelDoc2
Set swApp = Application.SldWorks
Set SwPart = swApp.ActiveDoc
' Get the first feature in part
Dim Feature As Feature, SubFeat As Feature
Dim FeatureName, Message, SubFeatureName
Set Feature = SwPart.FirstFeature
' While we have a valid feature
While Not Feature Is Nothing
' Get the name of the feature
FeatureName = Feature.Name
Message = "Feature: " & FeatureName & Chr(10) & _
" SubFeatures:"
Set SubFeat = Feature.GetFirstSubFeature
' While we have a valid sub-feature
While Not SubFeat Is Nothing
' Get the name of the sub-feature
SubFeatureName = SubFeat.Name
Message = Message & Chr(10) & " " & SubFeatureName
Set SubFeat = SubFeat.GetNextSubFeature
' Continue until the last sub-feature is done
Wend
' Display the sub-features
swApp.SendMsgToUser Message
' Get the next feature
Set Feature = Feature.GetNextFeature()
' Continue until the last feature is done
Wend
End Sub
Code run result
Sketch1 ProfileFeature
[D1@Sketch1@Part1.Part] = .04
[D2@Sketch1@Part1.Part] = .05
Extrude1 Extrusion
Sketch1 Extrusion
[D1@Sketch1@Part1.Part] = .04
[D2@Sketch1@Part1.Part] = .05
[D1@Extrude1@Part1.Part] = .01
[D1@Sketch1@Part1.Part] = .04
[D2@Sketch1@Part1.Part] = .05
********************************
'------------------------------------------------------------------
Option Explicit
Sub TraverseComponent(swComp, nLevel As Long)
Dim vChildComp As Variant
Dim swChildComp
Dim swCompConfig
Dim sPadStr As String
Dim i As Long
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
Cells(i + 2, 1) = sPadStr & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">"
Next i
End Sub
Sub main()
Dim swModel As Object, swAssy As Object
Dim swConf As Object, swRootComp As Object
Dim bRet As Boolean
Set swModel = SetSwPart
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
Debug.Print "File = " & swModel.GetPathName
TraverseComponent swRootComp, 1
End Sub
'---------------------------------------
SolidworksApi macros