Traverse All Cosmetic Threads Example (VBA)
This example shows how to traverse all cosmetic threads in part or assembly.
'------------------------------------------------------------------
'
' Problem:
' In
a part or assembly, a cosmetic thread is a sub-feature,
' typically
a sub-feature of a hole or extrusion. Thus,
' you
can traverse over all cosmetic threads in a
' model
by using the usual IFeature traversal methods.
'
' This
code shows how to traverse a part or assembly
' and
extract information about all cosmetic threads.
'
' Preconditions:
' (1)
Part or assembly is open
' (2)
Assembly is fully resolved
'
' Postconditions:
' None
'
'------------------------------------------------------------------
Option Explicit
Public Enum swCosmeticThreadType_e
swApplyCosmeticThread_Blind
= 0
swApplyCosmeticThread_UpToNext
= 1
swApplyCosmeticThread_ThroughFeature
= 2
End Enum
Public Enum swCosmeticThreadDiameterType_e
swCosmeticThread_ConicalOffset
= 1
swCosmeticThread_MajorDiameter
= 2
swCosmeticThread_MinorDiameter
= 3
End Enum
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swFeat As
SldWorks.feature
Dim
swSubFeat As
SldWorks.feature
Dim
sFeatType As
String
Dim
swCosThread As
SldWorks.CosmeticThreadFeatureData
Dim
i As
Long
Dim
j As
Long
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Debug.Print
"File = " & swModel.GetPathName
Set
swFeat = swModel.FirstFeature
Do
While Not swFeat Is Nothing
Set
swSubFeat = swFeat.GetFirstSubFeature
Do
While Not swSubFeat Is Nothing
sFeatType
= swSubFeat.GetTypeName
Select
Case sFeatType
Case
"CosmeticThread"
Debug.Print
" "
& swSubFeat.Name & "
[" & sFeatType & "]"
Set
swCosThread = swSubFeat.GetDefinition
Debug.Print
" ApplyThread
=
" & swCosThread.ApplyThread
Debug.Print
" BlindDepth
=
" & swCosThread.BlindDepth
* 1000# & " mm"
Debug.Print
" Diameter
=
" & swCosThread.diameter
* 1000# & " mm"
Debug.Print
" DiameterType
=
" & swCosThread.DiameterType
Debug.Print
" ThreadCallout
=
" & swCosThread.ThreadCallout
Debug.Print
""
End
Select
Set
swSubFeat = swSubFeat.GetNextSubFeature
Loop
Set
swFeat = swFeat.GetNextFeature
Loop
End Sub
'-----------------------------------------------