MACRO LIBRARY

Get mate information

Free public access. No account or subscription required.

Files

Get mate info

Code

'Gets the faces used by mates, since IMate2::GetSupplementalFaces is _
    not working as of 2012. Also displays the information related to _
    the mate entities such as owning feature and component.
    
'Preconditions: assembly is open
'Results: see immediate window for mate information
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'Special thanks for Abhay Kharade for assistance.
    
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swFeat As SldWorks.Feature
    Dim swMateFeat As SldWorks.Feature
    Dim swSubFeat As SldWorks.Feature
    Dim swMate As SldWorks.Mate2
    Dim swComp As SldWorks.Component2
    Dim swMateEnt As SldWorks.MateEntity2
    Dim swEnt As SldWorks.Entity
    Dim swFace As SldWorks.Face2
    Dim swOwningFeat As SldWorks.Feature
    Dim i As Integer
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swFeat = swModel.FirstFeature
    
    Do While Not swFeat Is Nothing
        If "MateGroup" = swFeat.GetTypeName Then
            Set swMateFeat = swFeat
            Exit Do
        End If
        Set swFeat = swFeat.GetNextFeature
    Loop
    
    Set swSubFeat = swMateFeat.GetFirstSubFeature
    Do While Not swSubFeat Is Nothing
        Set swMate = swSubFeat.GetSpecificFeature2
        
        If Not swMate Is Nothing Then
            Debug.Print swSubFeat.Name
            Debug.Print vbTab & "Type: " & GetMateTypeName(swMate)
            
            For i = 0 To swMate.GetMateEntityCount
                                         
                Set swMateEnt = swMate.MateEntity(i)
                If Not swMateEnt Is Nothing Then
                
                    Set swEnt = swMateEnt.Reference
                    
                    If TypeOf swEnt Is Face2 Then
                        Set swFace = swEnt
                        Set swOwningFeat = swFace.GetFeature
                        Debug.Print vbTab & "Entity type: face"
                        Debug.Print vbTab & vbTab & "Feature: " & swOwningFeat.Name
                    Else
                        Debug.Print vbTab & "Entity type: non-face"
                    End If
                    
                    Set swComp = swMateEnt.ReferenceComponent
                    Debug.Print vbTab & vbTab & "Component: " & swComp.Name2
                
                End If
                
            Next i
        End If
        
        Set swSubFeat = swSubFeat.GetNextSubFeature
    Loop
End Sub
    
Private Function GetMateTypeName(swMate As SldWorks.Mate2) As String
    Select Case swMate.Type
        Case 0
            GetMateTypeName = "COINCIDENT"
        Case 1
            GetMateTypeName = "CONCENTRIC"
        Case 2
            GetMateTypeName = "PERPENDICULAR"
        Case 3
            GetMateTypeName = "PARALLEL"
        Case 4
            GetMateTypeName = "TANGENT"
        Case 5
            GetMateTypeName = "DISTANCE"
        Case 6
            GetMateTypeName = "ANGLE"
        Case 7
            GetMateTypeName = "UNKNOWN"
        Case 8
            GetMateTypeName = "SYMMETRIC"
        Case 9
            GetMateTypeName = "CAMFOLLOWER"
        Case 10
            GetMateTypeName = "GEAR"
        Case 11
            GetMateTypeName = "WIDTH"
        Case 12
            GetMateTypeName = "LOCKTOSKETCH"
        Case 13
            GetMateTypeName = "RACKPINION"
        Case 14
            GetMateTypeName = "MAXMATES"
        Case 15
            GetMateTypeName = "PATH"
        Case 16
            GetMateTypeName = "LOCK"
        Case 17
            GetMateTypeName = "SCREW"
        Case 18
            GetMateTypeName = "LINEARCOUPLER"
        Case 19
            GetMateTypeName = "UNIVERSALJOINT"
        Case 20
            GetMateTypeName = "COORDINATE"
        Case 21
            GetMateTypeName = "SLOT"
        Case 22
            GetMateTypeName = "HINGE"
        Case 23
            GetMateTypeName = "SLIDER"
        Case 24
            GetMateTypeName = "PROFILECENTER"
        Case Else
            GetMateTypeName = "Unrecognized"
    End Select
End Function