SW宏教程2013中未定义的变量

问题描述 投票:0回答:1

您好,我正在尝试遵循此 SW 插件教程,但是在运行宏时,我收到此消息“未定义的参数,swSelFaces”。我试图定义该参数但没有成功。 我乐于接受建议和推荐(书籍、编队……)以提高编码水平。

这是代码:

`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
vba visual-studio-debugging solidworks solidworksapi solidworkspdmapi
1个回答
0
投票

swSelectType_e.swSelFACES 是值为“2”的整数常量

所以你要么导入 SolidWorks.Interop.swconst 库

或者用这个值替换它。

参考此链接: https://help.solidworks.com/2021/English/api/swconst/SOLIDWORKS.Interop.swconst~SOLIDWORKS.Interop.swconst.swSelectType_e.html

© www.soinside.com 2019 - 2024. All rights reserved.