ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
BRBen Richardson26/02/2020

I am trying to create a macro that will generate a part from a simple sketch. Nothing too complex, I have gotten it to work with the sketch that I recorded the macro with but when I try it on another part its not working as intended (particularly editing the sketch and adding the offset sketch)

Here is my code:


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
'Offset sketch
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Part.EditSketch
boolstatus = Part.Extension.SketchBoxSelect("-0.063401", "0.022647", "0.000000", "-0.063349", "0.022596", "0.000000")
boolstatus = Part.SketchManager.SketchOffset2(0.0022, False, False, 0, 0, True)
Part.SketchManager.InsertSketch True
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

' Create Extrude
Dim myFeature As Object
Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, True, 0, 0, 0.016, 0.01, True, False, False, False, 4.36332312998583E-02, 4.36332312998583E-02, False, False, False, False, True, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
End Sub

I used "select all" but it seems to have created a box selection and I think this may be the issue.

What im trying to achieve:

  • From an already created sketch on the front plane, add 2.2mm offset outwards
  • Use this sketch to create extrude, 16mm long with 2.5 degrees draft

Once I get that working on ANY sketch, I then need to:

  • create sketch on the base face of the above extrude (can be front plane if the face is not suitable), offset 4mm outwards and 1mm inwards on that same face.
  • From this sketch create 1.2mm extrude
  • Create a set of configurations based off a list of sizes where "D1@Sketch1" is the dimension to be changed for each configuration

Im pretty new to macros so any help is appreciated, thanks.