MACRO LIBRARY

Get face that owns cosmetic thread

Free public access. No account or subscription required.

Files

Get face that owns cosmetic thread

Code

Module:

'Demonstrates how to get the face on which a cosmetic thread is applied.
    
'Preconditions: Cosmetic thread is selected in feature manager tree.
'Result: Circular face on which cosmetic thread is applied is selected.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swData As SldWorks.CosmeticThreadFeatureData
Dim swEdge As SldWorks.Edge
Dim swFace1 As SldWorks.Face2
Dim swFace2 As SldWorks.Face2
Dim swSurf As SldWorks.Surface
Dim swEnt As SldWorks.Entity
Dim vFaces As Variant
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
    Set swData = swFeat.GetDefinition
    swData.AccessSelections swModel, Nothing
    Set swEdge = swData.Edge
    vFaces = swEdge.GetTwoAdjacentFaces2
    Set swFace1 = vFaces(0)
    Set swFace2 = vFaces(1)
    Set swSurf = swFace1.GetSurface
    If swSurf.IsCylinder Then
        Set swEnt = swFace1
    Else
        Set swEnt = swFace2
    End If
    swEnt.Select False
    
    'Does not appear to be necessary since AccessSelections doesn't put _
        the cosmetic thread in a rollback state.
    'swData.ReleaseSelectionAccess
End Sub