Get Cosmetic Threads Annotations and Any Patterns (VBA)
This example shows how to get the cosmetic thread annotations and patterns
in a drawing.
' --------------------------------------------------------------------------
'
' Preconditions: Drawing is open and contains patterned
' cosmetic
thread annotations.
'
' Postconditions: None
'
' --------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swMathUtility As SldWorks.MathUtility
Sub main()
Dim
myModel As SldWorks.ModelDoc2
Dim
myDrawing As SldWorks.DrawingDoc
Dim
thisView As SldWorks.View
Dim
thisCThread As SldWorks.CThread
Set
swApp = Application.SldWorks
Set
swMathUtility = swApp.GetMathUtility()
Set
myModel = swApp.ActiveDoc
Set
myDrawing = myModel
myModel.ClearSelection2 True
'
Traverse annotations of the drawing views or this drawing and look for
cosmetic threads
Set
thisView = myDrawing.GetFirstView()
While
Not thisView Is Nothing
Set
thisCThread = thisView.GetFirstCThread()
While
Not thisCThread Is Nothing
Call
processCosmeticThread(myModel, thisCThread)
Set
thisCThread = thisCThread.GetNext()
Wend
Set
thisView = thisView.GetNextView()
Wend
End Sub
Private Sub processCosmeticThread(myModel As SldWorks.ModelDoc2,
aCThread As SldWorks.CThread)
Dim
cthreadAnno As SldWorks.Annotation
Dim
annoName As String, annoVis As String
Dim
patternedCount As Long
Dim
vPatternedXform As Variant
Dim
i As Integer
Dim
transform As SldWorks.MathTransform
Dim
vTransform As Variant
Set
cthreadAnno = aCThread.GetAnnotation()
annoName
= cthreadAnno.GetName()
If
(cthreadAnno.Visible = SwConst.swAnnotationHidden)
Then
annoVis
= "Hidden"
Else
annoVis
= "Visible"
End
If
Debug.Print
"Processing CThread " & annoName & "(" &
annoVis & ")"
'
Retrieve information about any patterns made from this cosmetic thread
patternedCount
= aCThread.GetPatternedTransformsCount()
Debug.Print
" Pattern
count = " & patternedCount
vPatternedXform
= aCThread.PatternedTransforms()
If
Not IsEmpty(vPatternedXform) Then
For
i = LBound(vPatternedXform) To UBound(vPatternedXform)
Set
transform = vPatternedXform(i)
vTransform
= transform.ArrayData()
If
Not IsEmpty(vTransform) Then
Debug.Print
"Rotate (" & Format(vTransform(0), "###0.0#####")
& " " & Format(vTransform(1), "###0.0#####")
& " " & Format(vTransform(2), "###0.0#####")
Debug.Print
" "
& Format(vTransform(3), "###0.0#####") & " "
& Format(vTransform(4), "###0.0#####") & " "
& Format(vTransform(5), "###0.0#####")
Debug.Print
" "
& Format(vTransform(6), "###0.0#####") & " "
& Format(vTransform(7), "###0.0#####") & " "
& Format(vTransform(8), "###0.0#####") & ")"
Debug.Print
"Translate " & Format(vTransform(9), "###0.0#####")
& " " & Format(vTransform(10), "###0.0#####")
& " " & Format(vTransform(11), "###0.0#####")
Debug.Print
End
If
Next
i
End
If
End Sub