Hello I am trying to follow this SW adds-in tutorial but when running the macro I have this message "undefined parameter, swSelFaces". I tried to define that paremeters but without any success. I am open to suggestions and recommendations (books, formations...) to get better at coding.
Here is the code :
`STATEMENT TO KEEP`
Option Explicit
`Declare all variables`
`as early bound variables`
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
`VARIABLES TO ADD`
Dim SelectedObject As Object
Dim SelectCoords As Variant
Dim CircleSketch As SldWorks.Sketch
Dim MathUtil As SldWorks.MathUtility
Dim SketchPoint As SldWorks.MathPoint
Dim Transform As SldWorks.MathTransform
Dim dx As Double
Dim dy As Double
Dim dz As Double
`CODE TO KEEP`
Sub main()
`Connect to currently active SolidWorks document`
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
`Get coordinates of the point selected`
SelectCoords = Part.SelectionManager.GetSelectionPoint2(1, -1)
`If face is selected, then create the cut-extrude`;
`else, stop execution`
Set SelectedObject = _
Part.SelectionManager.GetSelectedObject6(1, 0)
If Part.SelectionManager.GetSelectedObjectType3(1, -1) = _
swSelFACES Then
`CODE TO KEEP`
`Insert new sketch`
Part.SketchManager.InsertSketch True
`Get MathPoint to use when transforming point from`
`model space to sketch space`
Set MathUtil = swApp.GetMathUtility
Set SketchPoint = MathUtil.CreatePoint(SelectCoords)
`Get reference to the sketch`
Set CircleSketch = Part.SketchManager.ActiveSketch
`Translate sketch point into sketch space`
Set Transform = CircleSketch.ModelToSketchTransform
Set SketchPoint = SketchPoint.MultiplyTransform(Transform)
`Retrieve coordinates of the sketch point`
dx = SketchPoint.ArrayData(0)
dy = SketchPoint.ArrayData(1)
dz = SketchPoint.ArrayData(2)
`Use Part.SketchManager.CreateCircleByRadius instead of`
`Part.SketchManager.CreateCircle because`
`Part.SketchManager.CreateCircleByRadius sketches a`
`circle centered on a sketch point and lets you specify`
`a radius`
Part.SketchManager.CreateCircleByRadius dx, dy, dz, 0.015
`Create the cut-extrude `
Part.FeatureManager.FeatureCut3 True, False, False, 0, _
0, 0.025, 0.01, True, False, False, False, 0, 0, False, _
False, False, False, False, True, True, False, False, _
False, swStartSketchPlane, 0, False
End If
End Sub
swSelectType_e.swSelFACES is an integer constant of value '2'
So you should either import the SolidWorks.Interop.swconst library
or replace it with this value.
See this link for reference: https://help.solidworks.com/2021/English/api/swconst/SOLIDWORKS.Interop.swconst~SOLIDWORKS.Interop.swconst.swSelectType_e.html