3 Replies Latest reply on May 10, 2018 10:26 AM by Sam Pike

    Mating Planes API

    Sam Pike

      Hello, I for the life of me cannot figure this out. Hoping someone can help me out.

      What I am trying to do is write an API to coincident mate the Front Plane (Of the Assembly) to a part plane Called "Array Vert."

      Then I will do the same with the Right Plane (Of the Assembly) to the part called "Array Horz".

      The part name always changes but always has these two planes, specially created for this part.

      The part/assembly are part of a template, that is why the part name always changes.

      I am not sure how to make the API look inside of the tree for the part plane (Array Vert. or the Array Horz.) and select the plane before making the coincident mate.

       

      Here is what I have so far. Any help would be appreciated. The trial name is something I quick made up for this.

       

      Dim swApp As Object

      Dim Part As Object
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long

       

      Sub main()

      Set swApp = Application.SldWorks

      Set Part = swApp.ActiveDoc
      boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Array Vert@Trial-1@Assem3", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

      ' Mate
      Dim swMate As Mate2
      Set swMate = Part.AddMate5(0, 0, False, 0.329922578613554, 0.0254, 0.0254, 0.0254, 0.0254, 0, 0.5235987755983, 0.5235987755983, False, False, 0, longstatus)
      Part.ClearSelection2 True
      Part.EditRebuild3

      boolstatus = Part.Extension.SelectByID2("Array Horz@Trial-1@Assem3", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Right Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

      ' Mate
      Set swMate = Part.AddMate5(0, 0, False, 0.110371086679135, 0.0254, 0.0254, 0.0254, 0.0254, 0, 0.5235987755983, 0.5235987755983, False, False, 0, longstatus)
      Part.ClearSelection2 True
      Part.EditRebuild3

      End Sub

        • Re: Mating Planes API
          Jacob Corder

          try setting the mark to 1

           

          boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 1, Nothing, 0)

          boolstatus = Part.Extension.SelectByID2("Array Vert@Trial-1@Assem3", "PLANE", 0, 0, 0, True, 1, Nothing, 0)

          • Re: Mating Planes API
            Deepak Gupta

            You need to get the component name of the inserted part. For e.g., select a component in assembly and then run these codes:

             

            Option Explicit

                Dim swApp As SldWorks.SldWorks

                Dim swModel As SldWorks.ModelDoc2

                Dim swSelMgr As SldWorks.SelectionMgr

                Dim swComp As SldWorks.Component2

                Dim boolstatus As Boolean

                Dim swMate As Mate2

                Dim longstatus As Long

               

            Sub main()

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

                Set swSelMgr = swModel.SelectionManager

                Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, 0)

               

                boolstatus = swModel.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

                boolstatus = swModel.Extension.SelectByID2("Array Vert@" + swComp.Name2 + "@" + swModel.GetTitle, "PLANE", 0, 0, 0, True, 0, Nothing, 0)

             

                'Mate

                Set swMate = swModel.AddMate5(0, 0, False, 0.329922578613554, 0.0254, 0.0254, 0.0254, 0.0254, 0, 0.5235987755983, 0.5235987755983, False, False, 0, longstatus)

                swModel.EditRebuild3 

             

            End Sub

            Modify as needed.