3 Replies Latest reply on Sep 29, 2016 6:38 AM by Yong Ning

    Have feature name→ how to get mate name?

    Yong Ning

      0.jpg

       

      follow code result is

         *********  Coincident1   MateCoincident

         *********  Coincident2   MateCoincident

         *********  Coincident4   MateCoincident

      ****************************************************

      Help me

       

      Feature name is Coincident1 →

          hope get mate name → Coincident → (b<1>,a<1>)

       

      ************************************************

       

      Private Sub MateFeat()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

            Set SwApp = Application.SldWorks

            Set SwModel = SwApp.ActiveDoc

         Dim SwFeat As Feature, SwSubFeat As Feature

            Set SwFeat = SwModel.FirstFeature

            Do While Not SwFeat Is Nothing

               'Debug.Print SwFeat.Name, SwFeat.GetTypeName

               Set SwSubFeat = SwFeat.GetFirstSubFeature

               Do While Not SwSubFeat Is Nothing

                  With SwSubFeat

                     If .GetTypeName Like "*Mate*" Then

                        Debug.Print "   ********* ", .Name, .GetTypeName

                     End If

                     Set SwSubFeat = .GetNextSubFeature

                  End With

               Loop

               Set SwFeat = SwFeat.GetNextFeature

            Loop

       

      End Sub

        • Re: Have feature name→ how to get mate name?
          Deepak Gupta

          Try these codes:

           

          Option Explicit

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

              Dim i                           As Integer

          On Error Resume Next

              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

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

                          Debug.Print "      Mate Name         = " & swSubFeat.Name

                      End If

                  Set swSubFeat = swSubFeat.GetNextSubFeature

              Loop

           

          End Sub

            • Re: Have feature name→ how to get mate name?
              Yong Ning

              Thanks your code.,

              ***********************

                             With swMateEnt(i)

                                Debug.Print .ReferenceComponent.Name  → result is →  b-1

                             End With

              Hope get  result  b-1 and a-1, See follow picture

               

              0.jpg

               

                     

              **************************************************

               

               

              Option Explicit

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

                  Dim i                           As Integer

                  Dim Ss

              On Error Resume Next

                  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

              Debug.Print swMateFeat.Name

               

               

                  Set swSubFeat = swMateFeat.GetFirstSubFeature

                  Do While Not swSubFeat Is Nothing

                     Set swMate = swSubFeat.GetSpecificFeature2

                          If Not swMate Is Nothing Then

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

                           

                             With swMateEnt(i)

                                Debug.Print .ReferenceType, .Reference,

                                Debug.Print .ReferenceComponent.Name, .ReferenceComponent.ReferencedConfiguration

                             End With

                             'Debug.Print

                              Debug.Print "      Mate Name         = " & swSubFeat.Name

                          End If

                      Set swSubFeat = swSubFeat.GetNextSubFeature

                  Loop

               

              End Sub

                • Re: Have feature name→ how to get mate name?
                  Yong Ning

                  Sub deldel()

                      Dim swApp As SldWorks.SldWorks, swModel As ModelDoc2

                          Set swApp = Application.SldWorks

                          Set swModel = swApp.ActiveDoc

                      Dim CompArr, CompArr1

                      Dim SwComp As Component2

                          CompArr = ComponentArr(swModel)

                          MateGroupFeature swModel

                          For ii = 0 To UBound(CompArr)

                              Set SwComp = CompArr(ii)

                              Set swModel = SwComp.GetModelDoc

                              MateGroupFeature swModel

                          Next ii

                         

                         

                  End Sub

                   

                   

                  ''

                  Function ComponentArr(swModel As ModelDoc2)

                    'Debug.Print SwModel.GetTitle

                    Dim oDic As New Dictionary

                   

                    Dim SwRootComp As Component2, SwComp As Component2

                    Dim SwRootConf As Configuration, vChildComp, vModel As ModelDoc2

                    Set SwRootConf = swModel.GetActiveConfiguration

                    Set SwRootComp = SwRootConf.GetRootComponent

                    vChildComp = SwRootComp.GetChildren

                    For ii = 0 To UBound(vChildComp)

                       Set SwComp = vChildComp(ii)

                       Set oDic(SwComp.GetPathName) = SwComp

                    Next ii

                    ''

                    ComponentArr = oDic.Items

                  End Function

                  ''

                  Function MateGroupFeature(swModel As ModelDoc2)

                      Dim ConfArr

                          ConfArr = swModel.GetConfigurationNames

                      Dim swFeat As Feature, SwSubFeat As Feature

                          Set swFeat = swModel.FirstFeature

                          Do While Not swFeat Is Nothing

                              If swFeat.GetTypeName = "MateGroup" Then

                                  Debug.Print swModel.GetTitle, swFeat.Name, swFeat.GetTypeName, swFeat.IsSuppressed

                                  Set SwSubFeat = swFeat.GetFirstSubFeature

                                  Do While Not SwSubFeat Is Nothing

                                      Debug.Print , "****", SwSubFeat.Name, SwSubFeat.GetTypeName, SwSubFeat.IsSuppressed

                                      If SwSubFeat.IsSuppressed Then

                                          SwSubFeat.Select True

                                      End If

                                      Set SwSubFeat = SwSubFeat.GetNextSubFeature

                                     

                                  Loop

                              End If

                              Set swFeat = swFeat.GetNextFeature

                          Loop

                          swModel.EditUnsuppress

                  End Function

                   

                  *******************************************************

                  Option Explicit

                  Public Enum swInConfigurationOpts_e

                      swConfigPropertySuppressFeatures = 0

                      swThisConfiguration = 1

                      swAllConfiguration = 2

                      swSpecifyConfiguration = 3

                  End Enum

                  Sub main()

                      Dim swApp                   As SldWorks.SldWorks

                      Dim swModel                 As SldWorks.ModelDoc2

                      Dim swSelMgr                As SldWorks.SelectionMgr

                      Dim swFeat                  As SldWorks.Feature

                      Dim vConfNameArr            As Variant

                      Dim vSuppStateArr           As Variant

                      Dim i                       As Long

                      Dim bRet                    As Boolean

                    

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                      Set swSelMgr = swModel.SelectionManager

                      Set swFeat = swSelMgr.GetSelectedObject5(1)

                      vConfNameArr = swModel.GetConfigurationNames

                     

                      vSuppStateArr = swFeat.IsSuppressed2(swConfigPropertySuppressFeatures, vConfNameArr)

                      Debug.Assert True = IsEmpty(vSuppStateArr)

                     

                      vSuppStateArr = swFeat.IsSuppressed2(swThisConfiguration, vConfNameArr)

                      Debug.Assert 0 = UBound(vSuppStateArr)

                     

                      vSuppStateArr = swFeat.IsSuppressed2(swAllConfiguration, vConfNameArr)

                      Debug.Assert UBound(vSuppStateArr) = UBound(vConfNameArr)

                     

                      vSuppStateArr = swFeat.IsSuppressed2(swSpecifyConfiguration, vConfNameArr)

                      Debug.Assert UBound(vSuppStateArr) = UBound(vConfNameArr)

                     

                      Debug.Print "File = " & swModel.GetPathName

                      Debug.Print "  " & swFeat.Name

                      For i = 0 To UBound(vConfNameArr)

                          Debug.Print "    " & vConfNameArr(i) & " ---> " & vSuppStateArr(i)

                      Next i

                  End Sub

                  '--------