Hi,
How can modify this code to run on solid part not for drawing?
i try to modify it and it's not working
2016 SOLIDWORKS API Help - Get Entities Attached to Cosmetic Thread Example (VBA)
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks<br> Dim activeDocument As SldWorks.DrawingDoc<br> Dim pAnnotation As SldWorks.Annotation<br> Dim selType As Long<br> Dim entityCount As Long<br> Dim SelMgr As Object<br> Dim entitiesArray As Variant<br> Dim attachedEntity As SldWorks.Entity<br> Dim selView As SldWorks.View<br> Dim annotType As Long<br> Dim attachedEntityTypes As Variant<br> Dim i As Long<br> Dim edgeParams As Variant<br> Dim edgeRadius As Double<br> Dim faceParams As Variant<br> Dim faceRadius As Double
Set swApp = CreateObject("SldWorks.Application")<br> Set activeDocument = swApp.<span style="font-weight: 900;">ActiveDoc</span> If (activeDocument.<span style="font-weight: 900;">GetType</span> <> swDocDRAWING) Then<br> Exit Sub<br> End If
Set SelMgr = activeDocument.<span style="font-weight: 900;">SelectionManager</span><br> selType = SelMgr.<span style="font-weight: 900;">GetSelectedObjectType2</span>(1)
If (selType = swSelDRAWINGVIEWS) Then<br> ' Get the selected drawing view<br> Set selView = SelMgr.<span style="font-weight: 900;">GetSelectedObject6</span>(1, -1)<br> If (selView Is Nothing) Then<br> Exit Sub<br> End If<br> ' Get first annotation in the view<br> Set pAnnotation = selView.<span style="font-weight: 900;">GetFirstAnnotation3</span><br> ' Loop through every annotation in view<br> While (Not pAnnotation Is Nothing)<br> ' Get the type of annotation<br> annotType = pAnnotation.<span style="font-weight: 900;">GetType</span><br> ' For each CThread, get radius of attached entity<br> If (annotType = swCThread) Then<br> ' Get attached entities<br> entitiesArray = pAnnotation.<span style="font-weight: 900;">GetAttachedEntities</span><br> attachedEntityTypes = pAnnotation.<span style="font-weight: 900;">GetAttachedEntityTypes</span><br> ' Get number of attached entities<br> entityCount = UBound(entitiesArray) + 1<br> ' For each entity attached to this CThread<br> For i = 0 To (entityCount - 1)<br> ' Get the individual Edge or Face2 object<br> Set attachedEntity = entitiesArray(i)<br> ' If attached entity is an edge<br> If (attachedEntityTypes(i) = swSelEDGES) Then<br> edgeParams = attachedEntity.<span style="font-weight: 900;">GetCurve</span>.<span style="font-weight: 900;">CircleParams</span><br> edgeRadius = edgeParams(6)<br> swApp.SendMsgToUser "Cosmetic Thread Edge Radius = " + Str(edgeRadius)<br> ' If attached entity is a face<br> ElseIf (attachedEntityTypes(i) = swSelFACES) Then<br> faceParams = attachedEntity.<span style="font-weight: 900;">GetSurface</span>.<span style="font-weight: 900;">CylinderParams</span><br> faceRadius = faceParams(6)<br> swApp.SendMsgToUser "Cosmetic Thread Face Radius = " + Str(faceRadius)<br> End If<br> Next i<br> End If<br> Set pAnnotation = pAnnotation.<span style="font-weight: 900;">GetNext3</span><br> Wend<br> Else<br> swApp.SendMsgToUser "Please select a drawing view containing cosmetic thread annotations"<br> End If
End SubSolidworksApi macros
