SolidWorks API(VBA)将字符串存储在数组中
我想以数组的形式存储尺寸名称(字符串),以便我可以将另一个数组(尺寸名)与当前进行比较。
Public Sub WhateverName
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swPart As PartDoc
Dim swFeat As Feature
Dim swDispDim As DisplayDimension
Dim swDim As Dimension
Dim vDimVals As Variant
Dim swDimInfoNameArr As Variant
Dim SKETCH_NAME As String
Dim i As Variant
Dim swDimName As Variant
Dim swDispDimname As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
SKETCH_NAME = "ISO Standard"
Set swFeat = swPart.FeatureByName(SKETCH_NAME)
Set swDispDim = swFeat.GetFirstDisplayDimension
Do While Not swDispDim Is Nothing
i = 0
'For i = 0 To 4
Set swDim = swDispDim.GetDimension2(Empty)
vDimVals = swDim.GetValue3(swThisConfiguration, Empty)
Debug.Print swDim.Name & "@" & SKETCH_NAME & ": " & Round(vDimVals(0), 6)
Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
swDimName = swDim.Name
swDimInfoNameArr(i) = swDimName 'swModel.GetCustomInfoNames2 --> ERROR
i = i + 1
'Next
Loop
End Sub
第27行正在抛出错误“类型不匹配”
I want to store the dimension name (string) in the form of the array so that I can compare another array (dimension name) to the current.
Public Sub WhateverName
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swPart As PartDoc
Dim swFeat As Feature
Dim swDispDim As DisplayDimension
Dim swDim As Dimension
Dim vDimVals As Variant
Dim swDimInfoNameArr As Variant
Dim SKETCH_NAME As String
Dim i As Variant
Dim swDimName As Variant
Dim swDispDimname As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
SKETCH_NAME = "ISO Standard"
Set swFeat = swPart.FeatureByName(SKETCH_NAME)
Set swDispDim = swFeat.GetFirstDisplayDimension
Do While Not swDispDim Is Nothing
i = 0
'For i = 0 To 4
Set swDim = swDispDim.GetDimension2(Empty)
vDimVals = swDim.GetValue3(swThisConfiguration, Empty)
Debug.Print swDim.Name & "@" & SKETCH_NAME & ": " & Round(vDimVals(0), 6)
Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
swDimName = swDim.Name
swDimInfoNameArr(i) = swDimName 'swModel.GetCustomInfoNames2 --> ERROR
i = i + 1
'Next
Loop
End Sub
27th line is throwing the error "Type Mismatch"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要声明数组的大小,或使用其他对象存储。像词典一样:
You need to declare the size of the array, or use an other object to store. Like a dictionnary: