Hide Table of Contents

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

'-----------------------------------------------



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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Traverse All Cosmetic Threads Example (VBA)
*Comment:  
*   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:



x

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
x

Web Help Content Version: API Help (English only) 2014 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.