6 Replies Latest reply on May 11, 2018 3:38 PM by Sam Pike

    Sketch Entity in Assembly on another Part

    Sam Pike

      This one is giving me fits also.

      I have 2 parts in an assembly. The 2 parts are always named differently along with the assembly name. One of the parts we make a sketch on, for accuracy of cutting, and call it "Locating Sketch".

      Once in the assembly, the other part is selected (the one that doesn't have the "Locating Sketch"), start a sketch on one of its faces, select the "Locating Sketch" on the other part, convert entity, and Cut-Extrude to a depth of .25"

       

      I have this so far, but I am getting confused. Please help!

       

      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2
      Dim swAssy As SldWorks.AssemblyDoc
      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("swComp.Name2 + swModel.GetTitle", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
      swModel.EditPart
      swModel.ClearSelection2 True

      swModel.SketchManager.InsertSketch True
      boolstatus = swModel.Extension.SelectByRay(-0.110609985134488, 6.34999999994079E-03, 4.25014103411172E-02, -0.236548419051214, -0.683632167062601, -0.690428783873951, 1.38817010148556E-03, 2, False, 0, 0)
      swModel.ClearSelection2 True

      boolstatus = swModel.Extension.SelectByID2("Locating Sketch@" + swComp.Name2 + "@" + swModel.GetTitle, "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
      boolstatus = swModel.SketchManager.SketchUseEdge3(False, False)
      swModel.ClearSelection2 True

      Dim myFeature As Object
      Set myFeature = swModel.FeatureManager.FeatureCut4(True, True, False, 0, 0, 0.00635, 0.00635, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, False, True, True, True, True, False, 0, 0, False, False)
      swModel.SelectionManager.EnableContourSelection = False
      swModel.EditAssembly
      swModel.ClearSelection2 True

      End Sub

        • Re: Sketch Entity in Assembly on another Part
          Deepak Gupta

          I do not see any line in the codes about selecting a face/plane/surface on the component in which you trying to add the sketch and then cut extrude.

            • Re: Sketch Entity in Assembly on another Part
              Sam Pike

              When I commented out the code, going line by line, I came to this, and this line does select it. Not saying that is the correct way to do it.

              boolstatus = swModel.Extension.SelectByRay(-0.110609985134488, 6.34999999994079E-03, 4.25014103411172E-02, -0.236548419051214, -0.683632167062601, -0.690428783873951, 1.38817010148556E-03, 2, False, 0, 0)

                • Re: Sketch Entity in Assembly on another Part
                  Deepak Gupta

                  I do not think that this is correct line. Sorry away from machine and can not check/confirm.

                    • Re: Sketch Entity in Assembly on another Part
                      Sam Pike

                      I started out with doing new code. I got it almost working now. The only thing I need to do now is get the Cut-Extrude too set the flip side to cut. I am confused as to which setting it is in the code. Would anyone know?

                       

                      Dim swApp As Object
                      Dim swComp As SldWorks.Component2
                      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
                      Set swApp = Application.SldWorks
                      Set swModel = swApp.ActiveDoc
                      Set swSelMgr = swModel.SelectionManager
                      Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, 0)

                      boolstatus = Part.Extension.SelectByRay(-0.115676192932654, 6.34999999999764E-03, 1.29860726030984E-03, -0.108448573022486, -0.54545076872453, -0.831097085728981, 1.58123104284041E-03, 2, False, 0, 0)
                      Part.EditPart
                      Part.ClearSelection2 True
                      boolstatus = Part.Extension.SelectByRay(-0.106978428172582, 6.34999999999764E-03, 1.76640949543412E-02, -0.108448573022486, -0.54545076872453, -0.831097085728981, 1.58123104284041E-03, 2, False, 0, 0)
                      Part.SketchManager.InsertSketch True
                      boolstatus = Part.Extension.SelectByID2("Locating Sketch@" + swComp.Name2 + "@" + swModel.GetTitle, "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
                      boolstatus = Part.SketchManager.SketchUseEdge3(False, False)
                      Part.SketchManager.InsertSketch True
                      Dim myFeature As Object
                      Set myFeature = swModel.FeatureManager.FeatureCut4(True, True, False, 0, 0, 0.00635, 0.00635, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, False, True, True, True, True, False, 0, 0, False, False)
                      swModel.SelectionManager.EnableContourSelection = False
                      Part.EditAssembly
                      Part.ClearSelection2 True
                      End Sub