Cut Extrude Form Issue
SOLIDWORKS Forums
9 days ago

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

'Show user Form
UserForm1.Show

End Sub
Public Sub CreateDepth(InputDepth As Double)

Dim DepthDistance As Double

DepthDistance = InputDepth

'CutExtrude
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.EditAssembly
Part.ClearSelection2 True
End Sub

 

CommandButton1

 

Private Sub CommandButton1_Click()

Dim Depth As Double

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


Categories: API∕Macros

Comments
Last comment By: Nilesh Patel   Wed, 16 May 2018 21:50:10 GMT
Re: Cut Extrude Form Issue

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.

 

Regards,

Nilesh

By: Nilesh Patel  Tue, 15 May 2018 21:56:30 GMT
Re: Cut Extrude Form Issue

Sorry, I am obviously new to this. I was thinking about the document unit. How would that be written?

By: Sam Pike  Wed, 16 May 2018 01:10:46 GMT
Re: Cut Extrude Form Issue

Change 'Call CreateDepth(InputDepth)' to 'Call CreateDepth(InputDepth/1000)' if your document unit is in MM or to 'Call CreateDepth(InputDepth/39.3700787402)' if your document unit is in INCH.

By: Nilesh Patel  Wed, 16 May 2018 01:41:05 GMT
Re: Cut Extrude Form Issue

On your number 5, I had to keep the 'End' in the code. Otherwords the dialog box would not close out, it would just stay open.

Everything else worked great. Great catches. Thank you for the help! Much appreciated!

By: Sam Pike  Wed, 16 May 2018 12:15:16 GMT
Re: Cut Extrude Form Issue

Instead of using 'End' use 'Unload UserForm1' which will remove all user form data from the memory.

By: Nilesh Patel  Wed, 16 May 2018 21:50:10 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.