3 Replies Latest reply on Jun 23, 2014 12:38 PM by Patrick O'Hern

    problem in mate command

    Vishaldeep Singh

      there is a flat face on to.sldprt i select that face and coincide with point during recording a macro but when i run the macro it is not selecting the right face.


      in image 1 the face is selected that i need but in image 2 the face is selected that is not my requirement

        • Re: problem in mate command
          Deepak Gupta

          From your image 1 it is not clear as which face you want to select via macro.

          • Re: problem in mate command
            Ivana Kolin

            If it is possible change to.SLDPRT so, that flat face is on origin.


            Here is your macro - cleaned up from unnecessary code.


            Option Explicit

            Dim swApp As SldWorks.SldWorks


            Dim Part As SldWorks.PartDoc

            Dim boolstatus As Boolean

            Dim longstatus As Long, longwarnings As Long


            Sub main()


            Set swApp = Application.SldWorks


            Set Part = swApp.ActiveDoc

            Dim myFeature As SldWorks.Feature

            Set myFeature = Part.InsertPart2("...<yourpath>.....\wo.SLDPRT", 1109)

            Part.ClearSelection2 True

            Part.SketchManager.Insert3DSketch True

            Dim skPoint As SldWorks.SketchPoint

            Set skPoint = Part.SketchManager.CreatePoint(-0.019544, 0.024943, -0#)

            Dim skSegment As SldWorks.SketchSegment

            Set skSegment = Part.SketchManager.CreateLine(0.0005, 0.0005, -0.0055, -0.045682, -0.052104, -0.0055)


            Part.ClearSelection2 True

            Part.SketchManager.InsertSketch True

            Set myFeature = Part.InsertPart2("...<yourpath>.....\to.SLDPRT", 1109)

            Part.ClearSelection2 True


            Dim Component As SldWorks.Component2

            Dim FeatureData  As SldWorks.MoveCopyBodyFeatureData

            Dim swFeat As SldWorks.Feature

            Part.ClearSelection2 True

            boolstatus = myFeature.Select2(False, 0)

            Set swFeat = Part.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, False, 1)

            Set FeatureData = swFeat.GetDefinition()

            boolstatus = Part.Extension.SelectByID2("Axis1-to", "AXIS", 0, 0, 0, False, 1, Nothing, 0)

            boolstatus = Part.Extension.SelectByID2("Line1@3DSketch1", "EXTSKETCHSEGMENT", 0, 0, 0, True, 1, Nothing, 0)

            FeatureData.AddMate Nothing, 0, 1, 0, 0, longstatus

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0, 0, 0, False, 1, Nothing, 0)

            boolstatus = Part.Extension.SelectByID2("Point1@3DSketch1", "EXTSKETCHPOINT", 0.0005, 0.0005, -0.0055, True, 1, Nothing, 0)

            FeatureData.AddMate Nothing, 0, 2, 0, 0, longstatus

            swFeat.ModifyDefinition FeatureData, Part, Component

            End Sub


            • Re: problem in mate command
              Patrick O'Hern

              Selection using coordinates is very unstable in the API.  Selections will vary depending on zoom level and model rotation.  I'm not really sure what your process is for building the parts, but if you can give your face a name, it will make selection much more reliable.


              To name your face, you can right click on it and select "Face Properties" (may require expanding the menu).  Then you can enter a name in the window.