2 Replies Latest reply on Feb 15, 2016 12:26 PM by Nicholas Wilde

    Rotation Locking an Existing Concentric Mate

    Nicholas Wilde

      I'm trying to loop through existing concentric mates and rotation locking only certain ones. For some reason EditMate3 doesn't want to enable the Lock rotation. I can get the same macro to uncheck the Lock Rotation by setting LockRotation to false, but when I set it to true it does nothing. Any help is appreciated.


      I'm using the Edit Mate Example as a base.


      I find it ironic that the SolidWorks Jive forum doesn't support VBA .


      Option Explicit
      Sub main()
          Dim swApp               As SldWorks.SldWorks
          Dim swModel             As SldWorks.ModelDoc2
          Dim swFeat              As SldWorks.Feature
          Dim swBomFeat           As SldWorks.BomFeature
          Dim swSubFeat           As SldWorks.Feature
          Dim swBOMAnnotation     As SldWorks.BomTableAnnotation
          Dim swBOMFeature        As SldWorks.BomFeature
          Dim swTableAnn          As SldWorks.TableAnnotation
          Dim blnRtn As Boolean
          Dim swMateEnt()             As SldWorks.MateEntity2
          Dim i As Integer
          Dim swMate                  As SldWorks.Mate2
          Dim nRetVal As Long
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swFeat = swModel.FirstFeature
          Do While Not swFeat Is Nothing
              If swFeat.GetTypeName2 = "MateGroup" Then
                  Set swSubFeat = swFeat.GetFirstSubFeature                           ' Get the features of the drawing
                  Do While Not swSubFeat Is Nothing
                      ' If swSubFeat.GetTypeName2 = "MateConcentric" Then
                      If swSubFeat.Name = "Concentric165" Then
                          Debug.Print "  Feature Name : " & swSubFeat.Name
                          Debug.Print "  Feature Type Name : " & swSubFeat.GetTypeName
                          Set swMate = swSubFeat.GetSpecificFeature2
                          For i = 0 To swMate.GetMateEntityCount - 1
                              blnRtn = SelectMateEntity(swApp, swModel, swMate.MateEntity(i), 1)
                          Next i
                          blnRtn = swSubFeat.Select2(True, 0)
                          swModel.EditMate3 _
                              swMate.Type, _
                              swMate.Alignment, _
                              swMate.Flipped, _
                              0#, _
                              swMate.MaximumVariation, _
                              swMate.MinimumVariation, _
                              0#, _
                              0#, _
                              0#, _
                              swMate.MaximumVariation, _
                              swMate.MinimumVariation, _
                              False, _
                              True, _
                              0, _
                          Debug.Print "nRetVal: " & nRetVal
                          blnRtn = swModel.EditRebuild3
                          Exit Sub
                      End If
                      Set swSubFeat = swSubFeat.GetNextSubFeature
              End If
              Set swFeat = swFeat.GetNextFeature
      End Sub
      Function SelectMateEntity(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swMateEnt As SldWorks.MateEntity2, nMark As Long) As Boolean
          Dim swEnt                   As SldWorks.Entity
          Dim swSelMgr                As SldWorks.SelectionMgr
          Dim swSelData               As SldWorks.SelectData
          Dim bRet                    As Boolean
          Select Case swMateEnt.ReferenceType
              Case swMateEntity2ReferenceType_Point, _
                      swMateEntity2ReferenceType_Line, _
                      swMateEntity2ReferenceType_Circle, _
                      swMateEntity2ReferenceType_Plane, _
                      swMateEntity2ReferenceType_Cylinder, _
                      swMateEntity2ReferenceType_Sphere, _
                      swMateEntity2ReferenceType_Cone, _
                  Set swSelMgr = swModel.SelectionManager
                  Set swSelData = swSelMgr.CreateSelectData
                  Set swEnt = swMateEnt.Reference
                  swSelData.Mark = nMark
                  bRet = swEnt.Select4(True, swSelData)
                  SelectMateEntity = bRet
                  Exit Function
              Case swMateEntity2ReferenceType_Set, _
                      swMateEntity2ReferenceType_MultipleSurface, _
                      swMateEntity2ReferenceType_GenSurface, _
                      swMateEntity2ReferenceType_Ellipse, _
                      swMateEntity2ReferenceType_GeneralCurve, _
              Case Else
          End Select
          SelectMateEntity = False
      End Function