I think that since I can't deal with macro files, I have a ready-made code via artificial intelligence, but I couldn't run it. I need help on how to enter a ready-made code into SolidWorks 2023
' Declare variables
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swSketch As SldWorks.Sketch
Dim swFeature As SldWorks.Feature
' Create SolidWorks object
Set swApp = Application.SldWorks
Set swModel = swApp.NewDocument(swDocTypePart)
Set swPart = swModel
' Create sketch for the screwdriver head
Set swSketch = swPart.CreateSketch
swSketch.AddPolygon 6, 2, 0, 0, 0.004 ' Create hexagon (6 sides, center at 0,0, radius 4mm)
' Define the points for the angled cuts to create the hex head shape
Dim pt1 As Variant, pt2 As Variant, pt3 As Variant, pt4 As Variant
pt1 = Array(0, 0.004) ' Top point
pt2 = Array(0.002, 0.00693) ' Top right point
pt3 = Array(0.004, 0.004) ' Middle right point
pt4 = Array(0.002, 0.00107) ' Bottom right point
' Add the angled lines to the sketch
swSketch.AddLine pt1(0), pt1(1), pt2(0), pt2(1)
swSketch.AddLine pt2(0), pt2(1), pt3(0), pt3(1)
swSketch.AddLine pt3(0), pt3(1), pt4(0), pt4(1)
swSketch.AddLine pt4(0), pt4(1), 0, 0 ' Close the profile
' Create the extruded feature for the head
Set swFeature = swPart.CreateExtrusionFeature(swSketch, 0.004) ' Extrude 4mm
' Create sketch for the screwdriver body (shaft)
Set swSketch = swPart.CreateSketch
swSketch.AddCircle 0, 0, 0.002 ' Create circle (center at 0,0, radius 2mm)
' Create the extruded feature for the body
Set swFeature = swPart.CreateExtrusionFeature(swSketch, 0.12) ' Extrude 120mm
' Add more details (optional)
' You can add details such as a grip pattern on the handle or a company logo
' Save the file
swModel.SaveAs2 "C:\Users\Public\Documents\Screwdriver.sldprt" ' Change path as needed
' Clean up objects
Set swFeature = Nothing
Set swSketch = Nothing
Set swPart = Nothing
Set swModel = Nothing
Set swApp = Nothing