2 Replies Latest reply on Feb 2, 2017 5:23 PM by Matt Camacho-Cook

    How to identify missing mate references

    Matt Camacho-Cook

      Hello,

      I have large assemblies with several mates that have been broken due to part geometry/faces changing.  Unfortunately, these mates do not show up as errors in the feature tree and only show up as greyed out (but not suppressed) in the feature tree.  I'm struggling to find a way to identify these via the API.  I've tried the following example from the help, but it does not provide any useful info to show these problematic mates: 2013 SOLIDWORKS API Help - Get Mates and Mate Entities Example (VBA) .

       

      I have also tried IFeature.GetErrorCode2(), but this returns 0 for no errors and False for the IsWarning (since they aren't showing up in the feature tree as errors).

       

      Example mate that has lost its references:

       

      Editing the "Tangent23" mate:

       

      Is there a way to retrieve the mate selection names above so I could search "**External**Face" and see that I have an error?  I'm on SolidWorks 2013.

       

      Paul Ryan seemed to have a somewhat similar question with API and Missing Mates .

       

      Thanks in advance,

      Matt

        • Re: How to identify missing mate references
          Raghvendra Bhargava

          Hi Matt,

          There is no direct API to get the Mate Selection names. As far as i understand You want to get the Mate name which is having Missing Selection reference.

          Below code will give you Mate name which is using Two selection (Like Face and face), and one of the Selection is missing.

           

          Try this:

          Option Explicit

          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(2) As SldWorks.MateEntity2

          Dim fileName As String

          Dim errors As Long

          Dim warnings As Long

          Dim i As Long

           

          Sub main()

             

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

           

              'Get the first feature in the assembly

              Set swFeat = swModel.FirstFeature

              'Iterate over features in FeatureManager design tree

              Do While Not swFeat Is Nothing

                  If "MateGroup" = swFeat.GetTypeName Then

                      Set swMateFeat = swFeat

                      Exit Do

                  End If

                  Set swFeat = swFeat.GetNextFeature

              Loop

             

              'Get first mate, which is a subfeature

              Set swSubFeat = swMateFeat.GetFirstSubFeature

              Do While Not swSubFeat Is Nothing

                 Set swMate = swSubFeat.GetSpecificFeature2

                

                  Dim MateEntCnt As Integer

                  MateEntCnt = swMate.GetMateEntityCount 'Getting Mate Selection Count

                 

                  Dim MateRefCnt As Integer

                  MateRefCnt = 0

                 

                  If Not swMate Is Nothing Then

                      For i = 0 To 1

                          Set swMateEnt(i) = swMate.MateEntity(i)

           

                          Dim ref As Entity

                          Set ref = swMateEnt(i).Reference 'It will return the Entity object like face, Edge etc.

                         

                          If Not ref Is Nothing Then

                              MateRefCnt = MateRefCnt + 1

                          End If

                      Next i

                      If MateEntCnt <> MateRefCnt Then Debug.Print swSubFeat.Name & " < is having Missing Mate Selection>" ' Mate name which is having Missing Selection Reference

                  End If

                  ' Get the next mate in MateGroup

                  Set swSubFeat = swSubFeat.GetNextSubFeature

              Loop

          End Sub

            • Re: How to identify missing mate references
              Matt Camacho-Cook

              Hi Raghvendra,

               

              Your solution above worked great!  I made a couple of minor changes to make sure the Set swMate = swSubFeat.GetSpecificFeature2 was only acting on mates, as the GetNextSubFeature seemed to be grabbing the derived hole patterns that show up below my mates in my feature tree.

               

              Here's my final code:

               

              Option Explicit
              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 sFeatType As String
              Dim i As Long
              
              Sub main()
                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc
              
                  'Get the first feature in the assembly
                  Set swFeat = swModel.FirstFeature
              
                  'Iterate over features in FeatureManager design tree
                  Do While Not swFeat Is Nothing
                      If "MateGroup" = swFeat.GetTypeName Then
                          Set swMateFeat = swFeat
                          Exit Do
                      End If
                      Set swFeat = swFeat.GetNextFeature
                  Loop
              
                  'Get first mate, which is a subfeature
                  Set swSubFeat = swMateFeat.GetFirstSubFeature
                  Do While Not swSubFeat Is Nothing
                      sFeatType = swSubFeat.GetTypeName2
                      
                      ' GetNextSubFeature starts grabbing derived hole patterns and we only want mates.
                      Select Case sFeatType
                          Case "MateCoincident", "MateParallel", "MatePlanarAngleDim", "MateWidth", "MateConcentric", "MateTangent", "MateCoordinate", "MateSymmetric", "MateDistanceDim"
                              Set swMate = swSubFeat.GetSpecificFeature2
                              Call CheckMateSelections(swMate)
                      End Select
                      
                      ' Get the next mate in MateGroup
                      Set swSubFeat = swSubFeat.GetNextSubFeature
                  Loop
              End Sub
              
              Sub CheckMateSelections(swMate As SldWorks.Mate2)
                  Dim MateEntCnt As Integer
                  MateEntCnt = swMate.GetMateEntityCount 'Getting Mate Selection Count
                  Dim MateRefCnt As Integer
                  MateRefCnt = 0
              
                  If Not swMate Is Nothing Then
                      MateEntCnt = swMate.GetMateEntityCount
                      ReDim swMateEnt(MateEntCnt)
                      For i = 0 To MateEntCnt - 1
                          Set swMateEnt(i) = swMate.MateEntity(i)
                          Dim ref As Object
                          Set ref = swMateEnt(i).Reference 'It will return the Entity object like face, Edge etc.
              
                          If Not ref Is Nothing Then
                              MateRefCnt = MateRefCnt + 1
                          End If
                      Next i
                      
                      If MateEntCnt <> MateRefCnt Then
                          Debug.Print "  Missing mate selection: " & swSubFeat.Name ' Mate name which is having Missing Selection Reference
                      End If
                  End If
              End Sub
              

               

              Thanks,
              Matt