Undefined variable in SW macro tutorial 2013.

huangapple go评论62阅读模式
英文:

Undefined variable in SW macro tutorial 2013

问题

你好,我试图按照这个SW插件教程进行操作,但在运行宏时出现了以下消息:“未定义的参数,swSelFaces”。我尝试定义该参数,但没有成功。我愿意接受建议和推荐(书籍、培训...)以提高我的编程能力。

以下是代码部分,不需要翻译:

VARIABLES TO ADD

CODE TO KEEP

STATEMENT TO KEEP

Declare all variables

as early bound variables

Sub main()

Connect to currently active SolidWorks document

Get coordinates of the point selected

If face is selected, then create the cut-extrude

else, stop execution

CODE TO KEEP

Insert new sketch

Get MathPoint to use when transforming point from

model space to sketch space

Get reference to the sketch

Translate sketch point into sketch space

Retrieve coordinates of the sketch point

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

Create the cut-extrude

End Sub

英文:

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

答案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

英文:

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

huangapple
  • 本文由 发表于 2023年3月7日 02:49:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75654701.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定