Hide Table of Contents

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.

' Preconditions:
' 1. Open a drawing of a model with a cosmetic thread.
' 2. Select a drawing view of the model with the cosmetic
'    thread.
' Postconditions: Displays a message box with the
' radius of the cosmetic thread.
Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim activeDocument As SldWorks.DrawingDoc
    Dim pAnnotation As SldWorks.Annotation
    Dim selType As Long
    Dim entityCount As Long
    Dim SelMgr As Object
    Dim entitiesArray As Variant
    Dim attachedEntity As SldWorks.Entity
    Dim selView As SldWorks.View
    Dim annotType As Long
    Dim attachedEntityTypes As Variant
    Dim i As Long
    Dim edgeParams As Variant
    Dim edgeRadius As Double
    Dim faceParams As Variant
    Dim faceRadius As Double    
    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
        ' Get the selected drawing view
        Set selView = SelMgr.GetSelectedObject6(1, -1)
            If (selView Is Nothing) Then
             Exit Sub
            End If
            ' Get first annotation in the view
            Set pAnnotation = selView.GetFirstAnnotation3
            ' Loop through every annotation in view
            While (Not pAnnotation Is Nothing)
                ' Get the type of annotation
                annotType = pAnnotation.GetType
                ' For each CThread, get radius of attached entity
                If (annotType = swCThread) Then
                    ' Get attached entities
                    entitiesArray = pAnnotation.GetAttachedEntities
                    attachedEntityTypes = pAnnotation.GetAttachedEntityTypes
                    ' Get number of attached entities
                    entityCount = UBound(entitiesArray) + 1
                        ' For each entity attached to this CThread
                        For i = 0 To (entityCount - 1)
                        ' Get the individual Edge or Face2 object
                        Set attachedEntity = entitiesArray(i)
                        ' If attached entity is an edge
                            If (attachedEntityTypes(i) = swSelEDGES) Then
                                edgeParams = attachedEntity.GetCurve.CircleParams
                                edgeRadius = edgeParams(6)
                                swApp.SendMsgToUser "Cosmetic Thread Edge Radius = " + Str(edgeRadius)
                            ' If attached entity is a face
                            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
        swApp.SendMsgToUser "Please select a drawing view containing cosmetic thread annotations"
    End If
End Sub

Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Get Entities Attached to Cosmetic Thread Example (VBA)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2018 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.