Get Entities Attached to Cosmetic Thread Example (VBA)
This example shows how to locate all cosmetic
thread annotations in the drawing view, obtain the associated entities,
and query those entities for their radius values. It is assumed that you
have a drawing view selected.
'---------------------------------------------
Private Sub Command3_Click()
Dim swApp As Object
Dim activeDocument As Object
Dim pAnnotation As Object
Dim selType As Long
Dim entityCount As Long
Dim SelMgr As Object
Dim entitiesArray As Variant
Dim attachedEntity As Object
Dim selView As Object
Const swDocDRAWING = 3
Const swSelEDGES = 1
Const swSelFACES = 2
Const swSelCTHREADS = 39
Const swSelDRAWINGVIEWS = 12
Const swCThread = 1
Set swApp = CreateObject("SldWorks.Application")
Set activeDocument = swApp.ActiveDoc
If (activeDocument.GetType
<> swDocDRAWING) Then
Exit Sub
End If
Set SelMgr = activeDocument.SelectionManager
selType = SelMgr.GetSelectedObjectType2(1)
If (selType = swSelDRAWINGVIEWS)
Then
Set selView
= SelMgr.GetSelectedObject5(1)
If (selView
Is Nothing) Then
Exit Sub
End If
Set pAnnotation
= selView.GetFirstAnnotation3
While (Not pAnnotation
Is Nothing)
annotType =
pAnnotation.GetType
If (annotType
= swCThread) Then
entitiesArray
= pAnnotation.GetAttachedEntities
attachedEntityTypes
= pAnnotation.GetAttachedEntityTypes
entityCount
= UBound(entitiesArray) + 1
For i = 0 To
(entityCount - 1)
Set attachedEntity
= entitiesArray(i)
If (attachedEntityTypes(i)
= swSelEDGES) Then
edgeParams =
attachedEntity.GetCurve.CircleParams
edgeRadius =
edgeParams(6)
swApp.SendMsgToUser
"Cosmetic Thread Edge Radius = " + Str(edgeRadius)
ElseIf (attachedEntityTypes(i)
= swSelFACES) Then
faceParams =
attachedEntity.GetSurface.CylinderParams
faceRadius =
faceParams(6)
swApp.SendMsgToUser "Cosmetic Thread
Face Radius = " + Str(faceRadius)
End If
Next i
End If
Set pAnnotation
= pAnnotation.GetNext3
' End while annotations exist in the selected
drawing view
Wend
Else
swApp.SendMsgToUser "Please select a
drawing view containing cosmetic thread annotations"
End If
End Sub