5 Replies Latest reply on May 16, 2018 5:50 PM by Nilesh Patel

    Cut Extrude Form Issue

    Sam Pike

      I am having a problem with a portion of my program that uses a Form for the user to input a distance for the Cut-Extrude.

      The 1st part of the program has a couple of parts in an assembly. One of the parts has a sketch. The sketch is then being used as a converted entity on the other part and cut. I would like the user to input a distance for the cut-extrude.

      Currently it is going through, selecting the sketch, starting a new sketch on the part, and brings up the dialog box. I can input a number but it does nothing from there.

      In the UserForm1, I have the text box called DepthTextBox and the command button as CommandButton1


      Please help


      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.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

      'Show user Form

      End Sub
      Public Sub CreateDepth(InputDepth As Double)

      Dim DepthDistance As Double

      DepthDistance = InputDepth

      Set myFeature = swModel.FeatureManager.FeatureCut4(True, False, False, 0, 0, InputDepth, InputDepth, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, False, True, True, True, True, False, 0, 0, False, False)
      Part.SelectionManager.EnableContourSelection = False
      Part.ClearSelection2 True
      End Sub




      Private Sub CommandButton1_Click()

      Dim Depth As Double

      InputDepth = DepthTextBox.Text
      Call CreateDepth(InputDepth)
      End Sub

        • Re: Cut Extrude Form Issue
          Nilesh Patel

          Hi Sam,


          There are few issues with your code:


          1. Change 'Dim Depth As Double' line with 'Dim InputDepth As Double' and your code should work. You also need to keep in mind that the value entered by the user will be considered in meters so you will have to convert it to document unit. I cannot see this conversion anywhere.


          2. You have typed 'Set swApp = Application.SldWorks' line twice. Remove one of them.


          3. Remove 'Set swModel = swApp.ActiveDoc' line and replace 'swModel' with 'Part'.


          4. Remove 'Dim DepthDistance As Double' and 'DepthDistance = InputDepth' lines as you are nor using the variable 'DepthDistance' anywehre.


          5. Remove 'End' from 'Private Sub CommandButton1_Click()'.


          Hope this helps.