循环文件以检索solidworks的数据

时间:2016-03-23 13:16:20

标签: vba loops solidworks

我编写了以下代码,当我打开一个文件时它可以正常工作。但是,我对vba编码的了解很少。我使用for循环来打开一系列文件名output_1到output_61,但我得到的错误是"运行时错误' 53'文件未找到"。任何人都可以帮我这个吗?

这是我写的代码: 问候, 耶

Dim swApp As Object

Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    swApp.ActiveDoc.ActiveView.FrameState = 1
    Dim skPoint As Object

    For i = 1 To 61
        Open "C:\Users\jerry.obrien\Desktop\2MW Blade\Solidworks\output_i.txt" For Input As #1
        Part.SketchManager.Insert3DSketch True
        Do While Not EOF(1)
            Input #1, X, Y, Z
            Set skPoint = Part.SketchManager.CreatePoint(X / 1, Y / 1, Z / 1)
        Loop
    Next i
    Close #1

    Part.ShowNamedView2 "*Isometric", 7
    Part.ViewZoomtofit2
End Sub

2 个答案:

答案 0 :(得分:0)

更改为" C:\ Users \ jerry.obrien \ Desktop \ 2MW Blade \ Solidworks \ output _" &安培;我和我" .TXT"

答案 1 :(得分:0)

一些通用的循环内容

 path = "C:\Users\jerry.obrien\Desktop\2MW Blade\Solidworks" & "\" 
 Filename = Dir(path & "*.txt??")

 Do While Len(Filename) > 0
     DoEvents
     debug.? "found "; path & Filename
     Filename = Dir()
         For Each..... 
         Next .....
   Filename = Dir
 Loop